public async Task <Result> PutOrder(TradeOrder order, string strategyId, OrderType orderType) { var strategy = _strategyRepository.GetById(strategyId); if (strategy.TradingMode == TradingMode.Real) { var soldAsset = GetSoldAsset(order, strategyId, orderType); if (soldAsset == null || soldAsset.Amount < order.Amount) { return(new Result(false, "Insufficient funds for " + soldAsset.Currency)); } var exchange = _exchangeFactory.GetExchange(order.Exchange); if (exchange == null) { return(new Result(false, "Exchange not found")); } var uuid = await exchange.PutOrder(order, orderType, strategy.UserId); if (uuid == null) { return(new Result(false, "Exchange unable to create order")); } return(new Result(true, ManageAssets(soldAsset, order, orderType, uuid))); } else if (strategy.TradingMode == TradingMode.BackTesting) { return(new Result(true, ManageAssets(null, order, orderType, ""))); } else { var soldAsset = GetSoldAsset(order, strategyId, orderType); if (soldAsset == null || soldAsset.Amount < order.Amount) { return(new Result(false, "Insufficient funds for" + soldAsset.Currency)); } return(new Result(true, ManageAssets(soldAsset, order, orderType, ""))); } }
public IActionResult GetTrades(string strategyId) { var strategy = _strategyRepository.GetById(strategyId); if (strategy == null) { return(BadRequest("Strategy not found")); } if (strategy.TradingMode == TradingMode.Real) { _tradeService.MirrorRealTrades(strategy); } return(Ok(_tradeRepository.GetByStrategyId(strategyId))); }