Reconnect a Stock Quote WebSocket and Restore Missing Candles with Historical Data
TickDB Research ·
Reconnect a Stock Quote WebSocket and Restore Missing Candles with Historical Data
A quote dashboard can start moving again while its chart still has a gap. A local replay of real Cambricon candles shows how to resubscribe, backfill with REST and decide when the recovery alert can be cleared.
The Cambricon quote dashboard receives a fresh update at 10:10. Its chart still lacks the 10:07, 10:08 and 10:09 candles. Any metric or alert that needs preceding minutes still has an incomplete input. We reproduced this scenario from real historical bars on a local WebSocket, then reconciled the outage window. Running the full backfill twice left ten stored candles. [1]
Stream recovery and gap recovery use two different inputs
The WebSocket keeps a dashboard updated. A historical candle query supplies bars from an earlier window. Once the stream returns, record the first recovered source timestamp and compare it with the last one before the outage. Build the expected minutes from trading sessions so scheduled breaks do not become false gaps. [2, 3]
In our local replay the socket disconnected after 10:06 and the first recovered bar was 10:10. Seven of the ten bars from 10:03 to 10:12 were stored after replay. We backfilled 10:06 through 10:10, deliberately including the two bars already stored at the boundaries. Comparing known bars helps catch a window or convention mismatch. [1]

Figure 1. Cambricon one-minute prices from November 12, 2026, Shanghai time. [1]
Zero inserts can hide a permanent gap
The first backfill inserted three bars and found two matching overlaps. The second inserted zero and found five matching overlaps. Both CSV exports were byte-identical. OHLC, volume and turnover also matched the archive. We then changed the same input in two controlled tests. [1]
| Test | New | Still missing | Conflicts |
|---|---|---|---|
| Full batch, first pass | 3 | 0 | 0 |
| Full batch, second pass | 0 | 0 | 0 |
| Boundaries only, two passes | 0 / 0 | 3 / 3 | 0 / 0 |
| One deliberately changed close | 3 | 0 | 1 |
The boundary-only retry added nothing twice while leaving the same three gaps. The modified batch filled all three gaps and flagged one conflicting row. A release check needs the expected window, duplicate keys and matching values.
Put four steps in your recovery runbook
- Reconnect and subscribe again. The TickDB A-Shares API provides a live stream and historical candle queries. Record the last timestamp before the disconnect and the first recovered source timestamp. Keep incomplete historical windows marked as pending. [2]
- Use
GET /v1/market/klinefor closed bars. Pass the symbol,interval=1m, adjustment setting and millisecond window. Build the expected labels from market sessions. The live bar can remain provisional until it closes. [3] - Merge on symbol, interval and minute start. Include adjustment mode if the same store holds several conventions. Retain rows with identical values. Keep an evidence record when the same key carries different values.
- Compare the result against the full expected set, including duplicate and extra keys and differences in price fields. Repeat the same batch. Clear the data-recovery alert after the content and retry checks pass.
This short calculation uses the recovered minute labels and starts both cases from the same seven-bar store.
expected = set(range(3, 13))
stored = {3, 4, 5, 6, 10, 11, 12}
for batch in ({6, 10}, {6, 7, 8, 9, 10}):
new = batch - stored
print(len(new), len(expected - (stored | batch)))
The actual output is 0 3 and 3 0, for new and still missing bars. A full check also compares values. The terminal capture below is from the original local replay. [1]

Figure 2. November 21 localhost replay, cropped to remove the window title. Test recovery and latency in the target deployment separately. [1]
FAQ
How do I treat the current unfinished minute? You can update it in the display, then include it in the historical completeness check after it closes.
What if the same closed minute returns different values? Keep both records and timestamps while checking instrument, session, adjustment and data version. Accept a revision when its cause is clear.
References
- TickDB Cambricon 688256.SH unadjusted minute candles from November 12, 2026, 10:03–10:12 Shanghai, and local replay and negative-test records.
- TickDB Docs, WebSocket Best Practices, for heartbeat, reconnect and resubscription.
- TickDB Docs, Historical K-Line, for query windows, periods and unfinished bars.
7 markets · 42,688 symbols
- US stocks
- 14,386
- Hong Kong market
- 3,354
- China stocks, ETFs & bonds
- 7,576
- Forex & metals
- 1,228
- Indices
- 13,960
- Futures
- 1,172
- Crypto
- 1,012