private bool TryOpenMoreDeals(double bottomAsk, double topBid, double spreadToOpen) { int zoneIndex = OrderGrid.GetZoneIndex(spreadToOpen); if (zoneIndex == -1) { return(false); } double baseAmount = GetRemainAmountForZoneInBaseCurrency(zoneIndex); if (baseAmount == 0) { return(false); } double buyAmount = CalculateLongBuyAmountByBaseAmount(baseAmount); double actualBuyAmount = GetActualBottomAskAmount(bottomAsk); double finalBuyAmount = Math.Min(buyAmount, actualBuyAmount); double requiredShortSellAmount = CalculateRequiredShortAmount(finalBuyAmount, spreadToOpen); double availableShortSellAmount = GetActualShortBidAmount(topBid); double finalSellAmount = Math.Min(requiredShortSellAmount, availableShortSellAmount); if (finalSellAmount < requiredShortSellAmount) { finalSellAmount = availableShortSellAmount; finalBuyAmount = CalculateRequiredLongAmount(finalSellAmount, spreadToOpen); } MarketBuy(Long, bottomAsk, finalBuyAmount); MarketSell(Short, topBid, finalSellAmount); var order = new StatisticalArbitrageOrderInfo() { LongAmount = finalBuyAmount, LongValue = bottomAsk, ShortAmount = finalSellAmount, ShortTotalAmount = finalSellAmount, ShortValue = topBid, ZoneIndex = zoneIndex, SpentDeposit = Long.HighestBidInBaseCurrency() * finalBuyAmount, Spread = spreadToOpen }; LastItem = new StatisticalArbitrageHistoryItem(); LastItem.Time = DateTime.UtcNow; LastItem.Earned = Earned; LastItem.LongPrice = bottomAsk; LastItem.ShortPrice = topBid; LastItem.LongAmount = finalBuyAmount; LastItem.ShortAmount = finalSellAmount; LastItem.Open = true; StrategyData.Add(LastItem); //OpenedOrders.Add(order); OnOrderOpened(LastItem); return(true); }