private void InitiateBuy(string pair, IRule rule, IEnumerable <ISignal> ruleSignals) { StopTrailing(pair); IPairConfig pairConfig = tradingService.GetPairConfig(pair); SignalRuleModifiers ruleModifiers = rule.GetModifiers <SignalRuleModifiers>(); if (LoggingEnabled) { loggingService.Info($"Initiate buy request for {pair}. Rule: {rule.Name}"); } var buyOptions = new BuyOptions(pair) { MaxCost = pairConfig.BuyMaxCost * pairConfig.BuyMultiplier * (ruleModifiers?.CostMultiplier ?? 1), Metadata = new OrderMetadata { SignalRule = rule.Name, Signals = ruleSignals.Select(s => s.Name).ToList(), BoughtRating = ruleSignals.Any(s => s.Rating != null) ? ruleSignals.Where(s => s.Rating != null).Average(s => s.Rating) : null, BoughtGlobalRating = signalsService.GetGlobalRating() } }; tradingService.Buy(buyOptions); }
public IActionResult Buy(BuyRequest buyRequest) { if (Application.Resolve <ICoreService>().Config.ReadOnlyMode) { return(new BadRequestResult()); } if (!string.IsNullOrWhiteSpace(buyRequest.Pair) && buyRequest.Amount > 0) { ITradingService tradingService = Application.Resolve <ITradingService>(); tradingService.Buy(new BuyOptions(buyRequest.Pair) { Amount = buyRequest.Amount, IgnoreExisting = true, ManualOrder = true }); return(new OkResult()); } return(new BadRequestResult()); }