private void ProcessOrders(Order o) { if (o.BidOffer == BidOffer.Bid) { if (_bids.Count == 0) { _bids.AddFirst(o); } else if (_bids.Last != null && _bids.Last.Value.Price >= o.Price) { _bids.AddLast(o); } else { var bid = _bids.First; while (bid != null && bid.Value.Price > o.Price) { bid = bid.Next; } if (bid != null) { _bids.AddBefore(bid, o); } } } else { if (_offers.Count == 0) { _offers.AddFirst(o); } else if (_offers.Last != null && _offers.Last.Value.Price <= o.Price) { _offers.AddLast(o); } else { var offer = _offers.First; while (offer != null && offer.Value.Price < o.Price) { offer = offer.Next; } if (offer != null) { _offers.AddBefore(offer, o); } } } OrdersOut.AddOrder(new OrderEventArgs(o, OrderOperation.Add)); if (_bids.Count > 0 && _offers.Count > 0) { MatchOrders(); } }
private void RemoveOrder(LinkedListNode <Order> o) { if (o.Value.BidOffer == BidOffer.Bid) { _bids.Remove(o); } else { _offers.Remove(o); } OrdersOut.AddOrder(new OrderEventArgs(o.Value, OrderOperation.Delete)); }
private void AmendOrder(LinkedListNode <Order> o1, LinkedListNode <Order> o2) { o1.Replace(o2); OrdersOut.AddOrder(new OrderEventArgs(o2.Value, OrderOperation.Amend)); }