public RunnerChangeStub WithTraded(double?price, double?size) { Traded ??= new List <List <double?> >(); var priceSize = new List <double?> { price, size }; Traded.Add(priceSize); return(this); }
private void Match() { if (Status != SecurityTradingStatus.Open) { return; } var fills = new List <Fill>(); var time = DateTime.UtcNow; int maxTradePrice = int.MinValue; int minTradePrice = int.MaxValue; var buy = WorkingOrders(Side.Buy).FirstOrDefault(); var sell = WorkingOrders(Side.Sell).FirstOrDefault(); while (buy != null && sell != null && buy.Price >= sell.Price) { Order resting = buy.Id < sell.Id ? buy : sell; Order aggressor = buy == resting ? sell : buy; fills.AddRange(Match(resting, aggressor)); maxTradePrice = Math.Max(maxTradePrice, resting.Price.Value); minTradePrice = Math.Min(minTradePrice, resting.Price.Value); buy = WorkingOrders(Side.Buy).FirstOrDefault(); sell = WorkingOrders(Side.Sell).FirstOrDefault(); } // remove FAK orders (should only ever be one) foreach (var order in WorkingOrders()) { if (order.TimeInForce == TimeInForce.FillAndKill) { ExpireOrder(order); Console.WriteLine($"FAK expired: {order.Id}"); } } CheckStops(maxTradePrice, minTradePrice); if (fills.Count > 0) { Traded?.Invoke(this, new TradedEventArgs(time, Security, fills)); } }