public void Update(OrderbookResponse changes) { foreach (var ask in changes.asks) { if (ask.qty == 0) { if (_asks.ContainsKey(ask.price)) { _asks.Remove(ask.price); } } else { _asks.Add(ask.price, ask.qty); } } foreach (var bid in changes.bids) { if (bid.qty == 0) { if (_bids.ContainsKey(bid.price)) { _bids.Remove(bid.price); } } else { _bids.Add(bid.price, bid.qty); } } }
unsafe private void onOrderbookHandler(ulong bidActualValueLen, ulong askActualValueLen, IntPtr marketStr, ulong lastUpdateId, ulong updateId) { var market = CString.ToString(marketStr); FreeString(marketStr); var bidsList = new List <AskBid>(); var asksList = new List <AskBid>(); for (int i = 0; i < (int)bidActualValueLen; i++) { bidsList.Add(subBidsBuff[i].ToAskBid()); subBidsBuff[i].Dispose(); } for (int i = 0; i < (int)askActualValueLen; i++) { asksList.Add(subAsksBuff[i].ToAskBid()); subAsksBuff[i].Dispose(); } if (!onOrderbookCbs.ContainsKey(market)) { return; } var latestOrderbook = new OrderbookResponse( market, asksList, bidsList, lastUpdateId, updateId ); this.onOrderbookCbs.TryGetValue(market, out var callbacks); foreach (var callback in callbacks) { callback(latestOrderbook); } }