Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Market Feeds

The mercury-market crate manages all inbound market data.

FeedManager

FeedManager owns one or more WebSocket connections and routes parsed messages onto the EventBus. It handles reconnection automatically on disconnect.

Implementing a new feed

Implement the FeedParser trait:

#![allow(unused)]
fn main() {
pub trait FeedParser: Send + Sync {
    /// Return the WebSocket URL for this exchange/symbol.
    fn ws_url(&self, symbol: &Symbol) -> String;

    /// Return the JSON subscription message to send after connecting.
    fn subscribe_message(&self, symbol: &Symbol) -> String;

    /// Parse a raw WebSocket message into zero or more events.
    fn parse(&self, msg: &str) -> Vec<EventPayload>;
}
}

Once implemented, register your parser with FeedManager::add_feed.

Supported feeds

ParserExchangeData
BinanceParserBinanceOrder book depth (L2), trades
CoinbaseParserCoinbaseOrder book depth (L2), trades
BybitParserBybitOrder book depth (L2), trades
KrakenParserKrakenOrder book depth (L2), trades
OkxParserOKXOrder book depth (L2), trades
PolymarketParserPolymarket CLOBOrder book snapshots and deltas
KalshiParserKalshiOrder book snapshots and deltas
YahooFeedYahoo FinanceOHLCV bars (HTTP polling)

BookBuilder

BookBuilder maintains a full L2 order book from incremental BookUpdate events. It applies sequence-numbered deltas and publishes a fresh Arc<BookUpdate> snapshot after each delta is applied.