protected OrderBook DownloadOrderBook(TickerInputInfo ti)
        {
            int orderBookDepth = ti.OrderBookDepth == 0 ? OrderBook.Depth : ti.OrderBookDepth;

            if (!ti.Ticker.UpdateOrderBook(orderBookDepth))
            {
                return(null);
            }
            OrderBook ob = new OrderBook(null);

            ob.Assign(ti.Ticker.OrderBook);
            return(ob);
        }
        private async void OnOrderBook3(Binance.WsDepth depth)
        {
            try
            {
                await _lock.WaitAsync();

                if ((orderBook.Asks.IsEmpty && orderBook.Bids.IsEmpty) ||
                    (orderBook.MergeDecimals != (int)cmbMergeDecimals.SelectedValue))
                {
                    var result = await client.GetDepthAsync(depth.symbol, (int)cmbBookSize.SelectedValue);

                    if (result.Success)
                    {
                        var tmp = Convert(result.Data, si);
                        orderBook.MergeDecimals = (int)cmbMergeDecimals.SelectedValue;
                        orderBook.Assign(tmp);
                        lastUpdateId = result.Data.lastUpdateId;
                        //Debug.Print($"{lastUpdateId}");
                    }
                }
                if (depth.finalUpdateId <= lastUpdateId)
                {
                    Debug.Print($"{depth.firstUpdateId} : {depth.finalUpdateId}  dropped");
                    return;
                }
                if (depth.firstUpdateId <= lastUpdateId + 1 && depth.finalUpdateId >= lastUpdateId + 1)
                {
                    var sw          = Stopwatch.StartNew();
                    var bookUpdates = Convert(depth, si);
                    foreach (var e in bookUpdates)
                    {
                        //Debug.Print($"Got {e.Price} : {e.Quantity}.");
                        orderBook.Update(e);
                    }

                    lastUpdateId = depth.finalUpdateId;
                    Debug.Print($"Update {lastUpdateId} took {sw.ElapsedMilliseconds}ms.");

                    //if (true)
                    //{
                    //    // remove items which are out of size
                    //    var item = orderBook.FirstOrDefault(x => x.Side == TradeSide.Buy);
                    //    var idx = orderBook.IndexOf(item);
                    //    var count = (int)cmbBookSize.SelectedValue;
                    //    var askCount = idx > count ? count : idx;
                    //    var bidCount = count;

                    //    orderBookCopy.Clear();
                    //    orderBookCopy.AddRange(orderBook.Skip(idx - askCount).Take(askCount + bidCount));
                    //}
                }
                else
                {
                    Debug.Print($"{depth.firstUpdateId} : {depth.finalUpdateId}  dropped");
                }
            }
            finally
            {
                _lock.Release();
            }
        }