Skip to content

Handling Events

Every streaming update reaches your callback as one typed event. There are five data events and a set of control events covering session lifecycle; your callback narrows on the event type and reads typed fields — no JSON, no string parsing.

Narrowing

rust
use thetadatadx::streaming::{StreamControl, StreamData, StreamEvent};

client.stream().start_streaming(|event: &StreamEvent| {
    match event {
        StreamEvent::Data(StreamData::Quote { contract, bid, ask, .. }) => {
            println!("{} bid={bid} ask={ask}", contract.symbol);
        }
        StreamEvent::Data(StreamData::Trade { contract, price, size, .. }) => {
            println!("{} {price} x {size}", contract.symbol);
        }
        StreamEvent::Control(StreamControl::Disconnected { .. }) => {
            eprintln!("disconnected; automatic reconnect underway");
        }
        _ => {}
    }
})?;

Data events

KindFieldsDelivered for
quoteBest bid and offer (BBO for stocks, NBBO for options): bid / ask price, size, exchange, condition; ms_of_day, date, received_at_nsQuote streams
tradeprice, size, exchange, condition, sequence, ms_of_day, date, received_at_nsTrade, full-trade, and index price streams
open_interestopen_interest, ms_of_day, date, received_at_nsOpen-interest streams
ohlcvcopen, high, low, close, volume, count, ms_of_day, date, received_at_nsBars that arrive from upstream automatically — one per traded contract, ahead of that contract's trade
market_valuemarket_price (calculated value), market_bid / market_ask (stocks and options only), ms_of_day, date, received_at_nsIndex market value and per-contract market-value streams

Each stream-type page in the sidebar lists its event's complete field table.

The contract on every data event

Data events carry a resolved, typed contract — read identity straight off the event, no lookup table:

FieldTypeNotes
symbolstringUnderlying or ticker.
sec_typestringSTOCK / OPTION / INDEX / RATE.
expirationint?YYYYMMDD; options only.
rightstring?C / P; options only.
strikeint?Over the server's WebSocket, the terminal's 1/10-cent integer (a $570 strike is 570000), matching the terminal wire; options only. The native SDK bindings resolve it to dollars on event.contract (Rust strike_dollars(); the C ABI field is dollars).

Control events

Lifecycle and session events share the callback. The ones worth handling:

KindMeaning
connected / login_successSession is up and authenticated.
contract_assignedThe server bound a contract to the session (informational).
req_responseAcknowledgement for a subscribe/unsubscribe, with its request id.
market_open / market_closeSession boundary notices.
disconnected / reconnecting / reconnectedAutomatic-reconnect progress; see Reconnection & Monitoring.
reconnects_exhaustedThe retry budget is spent; the session is down for good until you intervene.
server_error / parse_errorServer-reported (ServerError) or protocol-level parse (ParseError) error with a message payload.
ping, restart, reconnected_server, unknown_frame, unknown_controlHeartbeats, server restarts, and forward-compatibility fallbacks.

Unrecognized future event types arrive as unknown_* rather than being dropped, so a callback written today keeps working against newer servers.

Released under the Apache-2.0 License.