A WebSocket can reconnect while a dashboard still shows the last EUR/USD quote from the old connection. Treat those as two separate states. The socket is ready to send subscriptions when it opens. A currency pair is ready to display as live only after its first usable quote from that connection.
Recover each currency pair separately
On disconnect, mark the affected quotes stale. If keeping the last value on screen helps the user, label it as stale and show its timestamp. After reconnect, register listeners and resubscribe to the wanted symbols. Do not mark every pair live on a socket-open event or a subscription acknowledgment. A message for EUR/USD tells you nothing about whether USD/JPY has resumed.
For example, the TickDB public client documentation shows a ticker subscription that can include EURUSD. Send the documented subscription on each new connection. If the provider reports an authorization or subscription error, surface it rather than retrying indefinitely. For transient failures, use capped exponential backoff with jitter and allow only one active reconnect loop.
Reject messages from the old connection
Give each socket a locally assigned generation number. Capture it in the callbacks and check it before processing either quotes or disconnects. This also covers work that was queued by the old handler and finishes after the new socket opens.
An interval with no live quote separates connection n from n+1; the diagram is illustrative.
The Python example below takes normalized, synthetic quotes, not raw provider frames. In one generation it rejects an earlier timestamp for the same symbol and invalid bid/ask values. It permits equal timestamps: millisecond timestamps alone do not establish a total order. Use a documented sequence number if your feed supplies one and its scope is known.
from dataclasses import dataclass @dataclass(frozen=True) class Quote: symbol: str time_ms: int bid: float ask: float class QuoteGate: def __init__(self): self.epoch = 0 self.live = False self.latest = {} def opened(self): self.epoch += 1 self.live = True self.latest.clear() return self.epoch def disconnected(self, epoch): if epoch == self.epoch: self.live = False self.latest.clear() def accept(self, epoch, quote): if not self.live or epoch != self.epoch: return False if not (0 < quote.bid <= quote.ask < float("inf")): return False previous = self.latest.get(quote.symbol) if previous and quote.time_ms < previous.time_ms: return False self.latest[quote.symbol] = quote return True if __name__ == "__main__": g = QuoteGate() a = g.opened() assert g.accept(a, Quote("EURUSD", 2000, 1.10, 1.11)) g.disconnected(a) assert not g.latest assert not g.accept(a, Quote("EURUSD", 2200, 1.10, 1.11)) b = g.opened() assert not g.accept(a, Quote("EURUSD", 2300, 1.10, 1.11)) assert g.accept(b, Quote("EURUSD", 2100, 1.10, 1.11)) assert not g.accept(b, Quote("EURUSD", 2090, 1.09, 1.11)) assert not g.accept(b, Quote("USDJPY", 2100, 150, 149)) g.disconnected(a) assert g.live and "USDJPY" not in g.latest print("8 synthetic assertions passed; no live WebSocket request") The eight offline assertions include a late quote with a newer timestamp from the old socket and a late disconnect notification. Neither should change the new socket's state. The script does not connect to a live feed.
Do not turn a reconnect into a completeness claim
A fresh quote restores a display, not every update that arrived while the link was down. If you use a REST snapshot to fill the display, label its source and keep it from replacing a newer streaming update. For a trade recorder or replay pipeline, preserve the outage interval and only backfill from a documented, suitable source. A ticker snapshot or a candle is not a replay of all missed events.
A quiet symbol is not necessarily disconnected. Combine the provider's documented heartbeat behavior with a freshness policy for the market and the specific pair. You want to be able to say which connection supplied the quote, when you received it, and whether the UI is labeling it correctly.


