Example #1
0
        public IRuleResult RuleExecuted(Solbot solbot)
        {
            var result = _marketService.IsGoodToBuy(
                solbot.Strategy.AvailableStrategy.CommissionType,
                solbot.Strategy.AvailableStrategy.BuyDown,
                solbot.Communication.Average.Current,
                solbot.Communication.Price.Current);

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

            if (_isInProductionMode)
            {
                var fundResponse = _marketService.AvailableQuote(
                    solbot.Strategy.AvailableStrategy.FundPercentage,
                    solbot.Communication.AvailableAsset.Quote,
                    solbot.Communication.Symbol.QuoteAssetPrecision);

                solbot.Communication.Buy.AvailableFund = fundResponse.QuoteAssetToTrade;
            }

            var change = solbot.BuyChange();
            var needed = solbot.NeededBuyChange();

            return(new MarketRuleResult()
            {
                Success = result.IsReadyForMarket,
                Message = result.Changed > 0
                    ? LogGenerator.BuyStepSuccess(
                    solbot.Communication.Price.Current,
                    solbot.Communication.Average.Current,
                    change)
                    : LogGenerator.BuyStepError(
                    solbot.Communication.Price.Current,
                    solbot.Communication.Average.Current,
                    change,
                    needed)
            });
        }