public void Add(OrderBookRecord record) { if (record.Price == 0 || record.Volume == 0) { return; } if (record.Price.Asset.Id != Pair.Asset2.Id) { throw new System.Exception($"You cant add this {nameof(OrderBookRecord)} as it has the wrong asset: {record.Price.Asset} -> should be: {Pair.Asset2}"); } if (record.Volume.Asset.Id != Pair.Asset2.Id) { throw new System.Exception($"You cant add this {nameof(OrderBookRecord)} as it has the wrong volume asset: {record.Volume.Asset} -> should be: {Pair.Asset2}"); } IsSorted = IsSorted && IsInOrder(record); if (record.Type == OrderType.Ask) { _asks.Add(record); } else { _bids.Add(record); } }
private bool IsInOrder(OrderBookRecord newRecord) { if (newRecord.Type == OrderType.Ask) { var la = _asks.LastOrDefault(); return(la == null || newRecord.Price > la.Price); } var lb = _bids.LastOrDefault(); return(lb == null || newRecord.Price < lb.Price); }
public void Add(OrderType type, decimal price, decimal volume, bool volumeIsNotQuote = false) { Add(OrderBookRecord.CreateInternal(type, new Money(price, Pair.Asset2), GetVolume(price, volume, volumeIsNotQuote))); }