/// <summary>Parse a market data update message</summary> private void ApplyUpdate(CandleUpdate update) // Worker thread context { lock (CandleData) { // Push the update to the buffer m_pending.Add(update); // If the data hasn't had the initial snapshot applied yet, we're done if (CandleData.Count == 0) { return; } // Apply updates foreach (var upd in m_pending) { var idx = CandleData.BinarySearch(x => x.Time.CompareTo(upd.Kline.StartTime)); if (idx >= 0) { CandleData[idx] = upd.Kline; } else { CandleData.Insert(~idx, upd.Kline); } } // Cap the length of the candle data if (CandleData.Count > 1500) { CandleData.RemoveRange(0, 500); } // All pending updates have been applied m_pending.Clear(); } }