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]

The local test store goes from seven candles to ten and remains at ten on retry

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]

TestNewStill missingConflicts
Full batch, first pass300
Full batch, second pass000
Boundaries only, two passes0 / 03 / 30 / 0
One deliberately changed close301

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

  1. 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]
  2. Use GET /v1/market/kline for 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]
  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.
  4. 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]

Real terminal output from the disconnect, resubscribe and two backfill passes

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

  1. TickDB Cambricon 688256.SH unadjusted minute candles from November 12, 2026, 10:03–10:12 Shanghai, and local replay and negative-test records.
  2. TickDB Docs, WebSocket Best Practices, for heartbeat, reconnect and resubscription.
  3. 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
11/24/2026

Related articles

Did Your Watchlist Follow the Index? A Midday Review with a Real-Time China A-Share Stock API

On November 23, the ChiNext Index opened lower and was up 1.22% by midday. Yet 209 stocks in our example watchlist were still below their previous close. Use opening prices, previous closes, and midday quotes from a real-time China A-share stock API to see which stocks rebounded, which turned positive, and whether your watchlist still warrants a risk flag.

TickDB Research ·

Moving a Hong Kong stock data API into Docker? Check the first quote after restart

Before moving a Hong Kong stock dashboard, alerting service, or risk monitor to Docker, what should count as recovery? In our local Tencent test, the first quote request returned HTTP 403. A later run returned a valid snapshot. The controlled restart command returned after 0.223 seconds, and the first quote passed validation after 1.580 seconds. It was still the previous session's quote. This article shows what to check on a weekend and what to verify again during trading.

TickDB Research ·