Expand description
One WebSocket per API key, shared by every stream a subscriber and its clones open.
§Why the connection is shared
The provider allows a key a single WebSocket — a second is refused with TOO_MANY_CONNECTIONS
on the free registered tier — and that one socket serves every dataset, subscription kind and
option underlying against one subscription cap. A socket per stream could therefore never run
two streams on one key.
§Shape
An actor task owns the socket. Each stream a LseSubscriber opens
attaches to it and is
handed an LseAttachment: the raw frames for its own symbols, which it parses exactly as it
would parse a socket of its own. The actor reads only what routing needs — a frame’s type,
symbol and replay stamp — and forwards the frame itself, a reference-counted clone, so each
stream’s decoder stays the only full parse.
- Connect lazily, close when idle. The socket opens on the first attach and closes once no stream remains attached.
- Subscribe once per symbol. A symbol or option underlying the socket already holds is not sent again: the attach is confirmed at once, and its frames fan out to every stream holding it. One symbol served by two datasets or two kinds costs one slot.
- Unsubscribe on the last detach. Dropping an attachment frees every symbol and underlying no other stream holds.
- One subscribe handshake at a time. Attaches are serialised, so a rejection naming no
symbol (
LIMIT_REACHED,INVALID_START) belongs to the attach in flight and fails it. One arriving outside a handshake is logged once, by the connection. A detach waits for the handshake in flight too, so a dropped stream’s symbols stay subscribed until that handshake ends; frames keep flowing to every attached stream meanwhile. - Every guard is per attach, and the cap is per connection. The offered-symbol check runs against each attach’s own batch, before anything is sent; the subscription cap is checked against everything the connection would then hold, because every stream sharing it draws on the same slots.
§Reconnect
Every stream on the connection ends together when the socket is lost, and each is re-initialised by the usual reconnect wrapper. The first to re-attach reconnects and re-subscribes everything the lost socket held; the rest re-attach to that one reconnect.
- A symbol has one replay window per connection. The provider answers a repeated subscribe
carrying
startwith “Already subscribed” and replays nothing, so each resumed symbol’s window opens from the earliest watermark among the streams holding it. Each stream then drops, silently, the ticks before its own watermark — ones it had already delivered — and skips the delivered prefix at its watermark exactly as a stream of its own would. SeeLseSubscriber::with_resume. - Replayed frames reach only the streams that asked for them. A stream that holds a resumed
symbol without a watermark of its own — it does not resume, or has delivered nothing for that
symbol yet — receives the live frames and none of the replay. This relies on the provider
stamping replayed ticks
replay: true, as it does today. - A stream keeps its place for
REATTACH_GRACEafter the socket is lost. Frames for a stream that has not re-attached yet are held until then, and discarded with a warning if it has not; its symbols are then released. A stream dropped while the socket was down is forgotten the same way, so no later reconnect re-subscribes its symbols. The grace runs from the loss, and a reconnect that fails does not extend it.
A stream attaching to a symbol the socket already holds cannot be given a replay at all, for the same reason; if it has a watermark to resume from, that is reported rather than passed over.
§Sharing is by clone, and only by clone
Clones of one subscriber share one connection. Two subscribers built separately for one key open
two sockets, and the provider refuses the second — visibly, with TOO_MANY_CONNECTIONS, which is
left to surface rather than papered over by a process-wide registry.
Structs§
- LseAttachment
- One stream’s view of the shared London Strategic Edge connection.
Constants§
- REATTACH_
GRACE - How long a shared connection keeps a stream’s place after the socket it was reading is lost.