Пример #1
0
        public IRuleResult RuleExecuted(Solbot solbot)
        {
            if (solbot.Strategy.AvailableStrategy.StopLossDown == 0)
            {
                solbot.Communication.StopLoss = new ChangeMessage
                {
                    Change       = 0,
                    PriceReached = false
                };

                return(new MarketRuleResult()
                {
                    Success = false,
                    Message = LogGenerator.Off(MarketOrder)
                });
            }
            else
            {
                var boughtPrice = solbot.BoughtPrice();

                var result = new MarketResponse();

                if (boughtPrice > 0)
                {
                    result = _marketService.IsStopLossReached(
                        solbot.Strategy.AvailableStrategy.CommissionType,
                        solbot.Strategy.AvailableStrategy.StopLossDown,
                        boughtPrice,
                        solbot.Communication.Price.Current);
                }
                else
                {
                    result.IsReadyForMarket = false;
                    result.Changed          = 0;
                }

                solbot.Communication.StopLoss = new ChangeMessage
                {
                    Change       = result.Changed,
                    PriceReached = result.IsReadyForMarket
                };

                var change = solbot.StopLossChange();

                return(new MarketRuleResult()
                {
                    Success = result.IsReadyForMarket,
                    Message = result.Changed < 0
                        ? LogGenerator.StepMarketSuccess(MarketOrder, solbot.Communication.Price.Current, boughtPrice, change)
                        : LogGenerator.StepMarketError(MarketOrder, solbot.Communication.Price.Current, boughtPrice, change)
                });
            }
        }
Пример #2
0
        public IRuleResult RuleExecuted(Solbot solbot)
        {
            var response = solbot.Communication.Sell.PriceReached;

            var sellPriceChange = solbot.BoughtPrice() - solbot.Communication.Price.Current > 0
                ? "falling"
                : "rising";

            var result = solbot.BoughtPrice() > 0
                ? $"100 - {solbot.Communication.Price.Current}(current) / {solbot.BoughtPrice()} * 100 = " +
                         $"{Math.Round(100 - (solbot.Communication.Price.Current / solbot.BoughtPrice() * 100), GlobalConfig.RoundValue)}. (price {sellPriceChange})." +
                         $" => sellup => {solbot.Strategy.AvailableStrategy.SellUp}%"
                : "LAST BUY => NO";

            var sellPrice = solbot.Strategy.AvailableStrategy.CommissionType == CommissionType.VALUE
                ? $"{solbot.Communication.Price.Current}(current) - {solbot.BoughtPrice()} = " +
                            $"{Math.Round(solbot.Communication.Price.Current - solbot.BoughtPrice(), GlobalConfig.RoundValue)}. (price {sellPriceChange})." +
                            $" => sellup => {solbot.Strategy.AvailableStrategy.SellUp}"
                : result;

            return(new OrderRuleResult
            {
                Success = response,
                Message = response
                    ? $"REACHED => {sellPrice}"
                    : $"NOT REACHED => {sellPrice}"
            });
        }
Пример #3
0
        public IRuleResult RuleExecuted(Solbot solbot)
        {
            var boughtPrice = solbot.BoughtPrice();

            var result = new MarketResponse();

            if (boughtPrice > 0)
            {
                result = _marketService.IsGoodToSell(
                    solbot.Strategy.AvailableStrategy.CommissionType,
                    solbot.Strategy.AvailableStrategy.SellUp,
                    boughtPrice,
                    solbot.Communication.Price.Current);
            }
            else
            {
                result.IsReadyForMarket = false;
                result.Changed          = 0;
            }

            solbot.Communication.Sell = new ChangeMessage
            {
                Change       = result.Changed,
                PriceReached = result.IsReadyForMarket
            };

            var change = solbot.SellChange();
            var needed = solbot.NeededSellChange();

            var priceUp = (solbot.Strategy.AvailableStrategy.CommissionType == CommissionType.PERCENTAGE && result.Changed > 0) ||
                          solbot.Strategy.AvailableStrategy.CommissionType == CommissionType.VALUE && result.Changed < 0;

            return(new MarketRuleResult()
            {
                Success = result.IsReadyForMarket,
                Message = priceUp
                    ? LogGenerator.SellStepSuccess(
                    solbot.Strategy.AvailableStrategy.SellType,
                    solbot.Communication.Price.Current,
                    boughtPrice,
                    change)
                    : LogGenerator.SellStepError(
                    solbot.Strategy.AvailableStrategy.SellType,
                    solbot.Communication.Price.Current,
                    boughtPrice,
                    change,
                    needed)
            });
        }
Пример #4
0
        public IRuleResult RuleExecuted(Solbot solbot)
        {
            var boughtPrice = solbot.BoughtPrice();

            var result = new MarketResponse();

            if (boughtPrice > 0)
            {
                result = _marketService.IsGoodToSell(
                    solbot.Strategy.AvailableStrategy.CommissionType,
                    solbot.Strategy.AvailableStrategy.SellUp,
                    boughtPrice,
                    solbot.Communication.Price.Current);
            }
            else
            {
                result.IsReadyForMarket = false;
                result.Changed          = 0;
            }

            solbot.Communication.Sell = new ChangeMessage
            {
                Change       = result.Changed,
                PriceReached = result.IsReadyForMarket
            };

            var change = solbot.SellChange();

            return(new MarketRuleResult()
            {
                Success = result.IsReadyForMarket,
                Message = result.Changed > 0
                    ? LogGenerator.StepMarketSuccess(MarketOrder, solbot.Communication.Price.Current, boughtPrice, change)
                    : LogGenerator.StepMarketError(MarketOrder, solbot.Communication.Price.Current, boughtPrice, change)
            });
        }