Skip to main content

Module sync

Module sync 

Source
Expand description

Adapter-local order book synchronization state for CoinAPI.

BookSyncTracker applies the CoinAPI sequence rule to the shared per-book [BookSync] lifecycle and converts accepted messages into deltas. A snapshot lists the whole book, so it is accepted at any sequence; an update is accepted only at the sequence after the last accepted message. A book’s position is that last sequence.

The reader captures each book frame’s subscription-write identity before queuing it. The consumer waits for that write to commit, and the tracker rejects identities replaced or removed since the frame arrived. BookWrites opens snapshot gates at commit and aborts pending writes on drop, so cancellation wakes waiting consumers without admitting their frames.

CoinAPI restarts a pair’s sequence at one whenever it restarts the pair or the connection, and a managed OrderBook keeps its sequence as a high-water mark across snapshots. Emitted deltas therefore carry the venue sequence plus a per-book offset, set at each accepted snapshot so the emitted sequence keeps rising across restarts, unsubscribes, and reconnects. Gap detection uses the venue sequence.

Conversion happens under the tracker’s lock, so an L3 book’s OrderIndex changes only with its accepted position. A message that fails conversion leaves the book out of sync, as a gap does. This module performs state transitions; super::recovery runs the asynchronous scope changes and retries.

Structs§

BookSyncTracker
Sequence, snapshot, and recovery state of each subscribed book.

Enums§

BookFrame
A book or book_l3 message routed to its book.