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) }); } }
public IRuleResult RuleExecuted(Solbot solbot) { 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(); var needed = solbot.NeededStopLossChange(); var priceDown = (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 = priceDown ? LogGenerator.StopLossStepSuccess( solbot.Strategy.AvailableStrategy.SellType, solbot.Communication.Price.Current, boughtPrice, change) : LogGenerator.StopLossStepError( solbot.Strategy.AvailableStrategy.SellType, solbot.Communication.Price.Current, boughtPrice, change, needed) }); }