public async Task <OrderInfo> OpenOrderAsync(string accountId, string assetPairId, double volume, double definedPrice) { if (!double.IsNaN(definedPrice)) { var orderInfo = new PendingOrder { ClientId = accountId, AssetPairId = assetPairId, Volume = volume, Id = Guid.NewGuid().ToString(), CreatedAt = DateTime.UtcNow, DefinedPrice = definedPrice }; await _pendingOrderRepository.AddAsync(orderInfo); return(Mapper.Map <OrderInfo>(orderInfo)); } else { var currentQuote = await _assetPairQuoteRepository.GetByIdAsync(assetPairId); if (currentQuote == null) { throw new InvalidOperationException(); } var orderInfo = new MarketOrder { ClientId = accountId, AssetPairId = assetPairId, Volume = volume, Id = Guid.NewGuid().ToString(), CreatedAt = currentQuote.DateTime }; orderInfo.Price = orderInfo.OrderAction == OrderAction.Buy ? currentQuote.Ask : currentQuote.Bid; await _marketOrderRepository.AddAsync(orderInfo); return(Mapper.Map <OrderInfo>(orderInfo)); } }