The orderbook channel streams real-time orderbook updates for prediction markets. Use this channel to build orderbook visualizations, depth charts, and market depth analysis tools.
Subscribe
Subscribe to All Orderbooks
{
"type" : "subscribe" ,
"channel" : "orderbook" ,
"all" : true
}
Subscribe to Specific Tickers
{
"type" : "subscribe" ,
"channel" : "orderbook" ,
"tickers" : [ "BTCD-25DEC0313-T92749.99" , "SPX-25DEC0313-T5000" ]
}
Unsubscribe
Unsubscribe from All Orderbooks
{
"type" : "unsubscribe" ,
"channel" : "orderbook" ,
"all" : true
}
Unsubscribe from Specific Tickers
{
"type" : "unsubscribe" ,
"channel" : "orderbook" ,
"tickers" : [ "BTCD-25DEC0313-T92749.99" ]
}
When subscribed to the orderbook channel, you’ll receive messages with the following structure:
{
"channel" : "orderbook" ,
"type" : "orderbook" ,
"market_ticker" : "BTCD-25DEC0313-T92749.99" ,
"yes_bids" : {
"0.45" : 1000 ,
"0.44" : 500 ,
"0.43" : 200
},
"no_bids" : {
"0.55" : 1500 ,
"0.56" : 800 ,
"0.57" : 300
}
}
Response Fields
Field Type Description channelstring Always "orderbook" typestring Message type market_tickerstring Market identifier yes_bidsobject Map of price (string) to quantity (number) for YES outcome bids no_bidsobject Map of price (string) to quantity (number) for NO outcome bids
The yes_bids and no_bids fields are objects where keys are price strings
and values are quantities. The order of entries in these objects represents
the orderbook depth.
Code Examples
Subscribe to All Orderbooks
const WEBSOCKET_URL = "wss://prediction-markets-api.dflow.net/api/v1/ws" ;
const ws = new WebSocket ( WEBSOCKET_URL );
ws . onopen = () => {
console . log ( "Connected to WebSocket" );
// Subscribe to all orderbook updates
ws . send (
JSON . stringify ({
type: "subscribe" ,
channel: "orderbook" ,
all: true ,
})
);
};
ws . onmessage = ( event ) => {
const message = JSON . parse ( event . data );
if ( message . channel === "orderbook" ) {
console . log ( "Orderbook update:" , {
ticker: message . market_ticker ,
yesBids: message . yes_bids ,
noBids: message . no_bids ,
});
}
};
ws . onerror = ( error ) => {
console . error ( "WebSocket error:" , error );
};
ws . onclose = () => {
console . log ( "WebSocket connection closed" );
};
Subscribe to Specific Markets
const WEBSOCKET_URL = "wss://prediction-markets-api.dflow.net/api/v1/ws" ;
// Market tickers to subscribe to
const marketTickers = [ "BTCD-25DEC0313-T92749.99" , "SPX-25DEC0313-T5000" ];
const ws = new WebSocket ( WEBSOCKET_URL );
ws . onopen = () => {
console . log ( "Connected to WebSocket" );
// Subscribe to specific tickers for orderbooks
ws . send (
JSON . stringify ({
type: "subscribe" ,
channel: "orderbook" ,
tickers: marketTickers ,
})
);
};
ws . onmessage = ( event ) => {
const message = JSON . parse ( event . data );
console . log ( `Orderbook update for ${ message . market_ticker } :` , message );
};
interface OrderbookUpdate {
channel : "orderbook" ;
type : string ;
market_ticker : string ;
yes_bids : Record < string , number >;
no_bids : Record < string , number >;
}