private void AddToTradeResult(BuySellOperation buyOperation, BuySellOperation sellOperation, ICollection <BuySellOperation> buysToBeRemoved, ICollection <BuySellOperation> sellsToBeRemoved) { if (sellOperation.Quantity == buyOperation.Quantity) { PrintTrade(buyOperation, sellOperation, sellOperation.Quantity); sellsToBeRemoved.Add(sellOperation); buysToBeRemoved.Add(buyOperation); } else if (sellOperation.Quantity < buyOperation.Quantity) { PrintTrade(buyOperation, sellOperation, sellOperation.Quantity); if (BuyPriceToQuantityMap.TryGetValue(buyOperation.Price, out _)) { BuyPriceToQuantityMap[buyOperation.Price] -= sellOperation.Quantity; } buyOperation.Quantity -= sellOperation.Quantity; sellsToBeRemoved.Add(sellOperation); } else if (sellOperation.Quantity > buyOperation.Quantity) { PrintTrade(buyOperation, sellOperation, buyOperation.Quantity); if (SellPriceToQuantityMap.TryGetValue(sellOperation.Price, out _)) { SellPriceToQuantityMap[sellOperation.Price] -= buyOperation.Quantity; } sellOperation.Quantity -= buyOperation.Quantity; buysToBeRemoved.Add(buyOperation); } }
private void BalancePriceToQuantityMap(BuySellOperation operation) { if (operation.OperationType == OperationType.Buy && BuyPriceToQuantityMap.TryGetValue(operation.Price, out _)) { BuyPriceToQuantityMap[operation.Price] -= operation.Quantity; } else if (operation.OperationType == OperationType.Sell && SellPriceToQuantityMap.TryGetValue(operation.Price, out _)) { SellPriceToQuantityMap[operation.Price] -= operation.Quantity; } }
public void Process(BuySellOperation buySellOperation) { if (buySellOperation.Price <= 0 || buySellOperation.Quantity < 0) { return; } if (buySellOperation.OperationType == OperationType.Buy) { // Put the current buy / sell operation on the queue. BuyOperations.Add(buySellOperation); // Add buyOperation to historical price to quantity map. if (buySellOperation.OrderType != OrderType.Ioc && BuyPriceToQuantityMap.TryGetValue(buySellOperation.Price, out var quantity)) { BuyPriceToQuantityMap[buySellOperation.Price] = quantity + buySellOperation.Quantity; } else if (buySellOperation.OrderType != OrderType.Ioc) { BuyPriceToQuantityMap.Add(buySellOperation.Price, buySellOperation.Quantity); } } else { // Put the current buy / sell operation on the queue. SellOperations.Add(buySellOperation); // Add buyOperation to historical price to quantity map. if (buySellOperation.OrderType != OrderType.Ioc && SellPriceToQuantityMap.TryGetValue(buySellOperation.Price, out var quantity)) { SellPriceToQuantityMap[buySellOperation.Price] = quantity + buySellOperation.Quantity; } else if (buySellOperation.OrderType != OrderType.Ioc) { SellPriceToQuantityMap.Add(buySellOperation.Price, buySellOperation.Quantity); } } }