Skip to main content
Market discovery is on OMS. Public market data is on MDS.
Use OMS GET /markets or GET /market/{asset_id} to discover markets and book decimals, then use MDS for depth, trades, klines, and tickers. Public trades, klines, and tickers include millisecond timestamps beside their nanosecond timestamps, on both REST and WebSocket responses. Each *_ms equals its *_ns divided by 1,000,000, rounded down. The nanosecond fields are unchanged; JavaScript clients can use milliseconds without losing integer precision. Ticker open interest has its own measurement timestamp. A truncated kline page includes both truncated_before_ns and truncated_before_ms; otherwise both are omitted.

Raw depth sync

Open the WebSocket, wait for its subscription confirmation, and start buffering depth frames:
Then fetch the snapshot while buffering continues:
Waiting for the subscription confirmation ensures the server has installed the depth receiver before the snapshot request. On reconnect or when switching MDS hosts, start this synchronization again. The stream does not replay a client’s missing history. Resync pseudocode (buffered_ws waits for the server subscription confirmation and buffers depth frames immediately, filtering out the control message):
The snapshot’s sequence_number is the number of the last diff MDS sent for the market, so on an active market the diff carrying that number is usually in your buffer already: skip it with every older one rather than refetching. sequence_number is MDS’s own numbering, per market in one MDS process, independent of the orderbook’s counters. Its initial value comes from the wall clock; it is not a persisted cursor or an ordering guarantee across restarts or hosts. REST and WebSocket must reach the same MDS instance. The Tplus gateway pins both depth routes for a market to one MDS and returns an error if that instance is unavailable; it does not substitute another instance’s counter. Custom proxies must preserve this affinity too. Reconnect and take a new snapshot after an MDS restart or a shard-configuration change. The number is contiguous between two reset diffs, and a reset diff skips one number, so a client that only checks for gaps refetches then too. A diff with reset: true carries no levels: MDS replaced the book it holds (the first full book after it started, or a newer book after a failover), so drop every level and fetch the snapshot again. The orderbook’s periodic full books, and a book stopping, reach you as ordinary diffs: nothing when nothing changed, the differences otherwise, a diff to empty for a stop. A snapshot or diff carries stale: true when the depth MDS serves may not reflect the book, and omits stale otherwise: MDS holds no full book of the market yet (the snapshot is then empty), it lost diffs, the orderbook that publishes the book went away or is no longer the market’s primary, the council reset the market to a later stream epoch, or the orderbook has published nothing for three keyframe periods (30 s by default). Re-fetching the snapshot then returns the same depth, so a resync does not help. Keep applying diffs, treat the book as unreliable, and trust it again once a diff or snapshot comes without stale: true. Lost diffs and silence end with the orderbook’s next full book, within a keyframe period (silence also with its next diff). An orderbook that went away publishes nothing more: that ends when it comes back and publishes its book again, or with the full book of the orderbook that takes the market over, which reaches you as a reset diff. A newer book whose full book has not arrived ends with that full book; an orderbook that is no longer the market’s primary ends with the full book of the primary that replaced it (or of a later one); both reach you as a reset diff. After a council reset, the old epoch stays stale even while the new epoch has no confirmed primary: its old full books do not recover freshness. A full book from the new epoch is required. If a new CE leader retains an earlier history without that reset, MDS waits for a full book under the new authority before trusting depth again. MDS may also send a diff with no levels at the sequence number you already hold, when stale changed with nothing to apply. The loop above checks a conflicting notice against a fresh snapshot. The same fresh notice follows an unchanged full book when REST observed silence before the updater’s periodic silence check.

tpluspy parsing

The SDK also exports MarketDataClient from tplus.client.

Klines

Candlesticks are 1 second wide by default; pass interval for wider ones. A page holds at most 1500 candlesticks, the same at every interval, so a wide window has to be paged. How far back history reaches depends on the width requested: second-wide candlesticks reach back 7 days, minute-wide ones 90 days, 15-minute ones a year, and hour-wide ones 3 years; 4 hours and wider reach the whole history of the market. REST:
WS:
Kline updates are emitted when a bucket closes. The active open bucket is included in ticker 24h stats but is not in the REST kline history until flushed. Kline volume is quote/notional volume: the updater adds trade.price * trade.quantity.

v0 and v1 envelopes

MDS market-data streams send a welcome frame, then bare payloads:
OMS authenticated streams support the v1 envelope when tplus.ws.v1 is present in Sec-WebSocket-Protocol; v0 is the bare payload. See WebSocket streams.

Reconnect

On disconnect, re-fetch the matching REST snapshot before applying new WS messages. MDS streams close on broadcast lag without a resync envelope. OMS v1 streams can send RESYNC_REQUIRED before close code 1013.