Skip to content

Market Channel (WebSocket)

Clients subscribe by specifying one or more asset IDs (token IDs). The server can send an initial order book snapshot on subscribe, then pushes incremental price-level changes, trade notifications, top-of-book updates, and lifecycle events to the connection.

Server: wss://api.openfish.me/ws/market


Direction: Client -> Server

FieldTypeRequiredDescription
typestringYes"subscribe" or "unsubscribe"
assets_idsarray of stringsYesAsset IDs to subscribe/unsubscribe
levelintegerNoSubscription level: 1=trades only, 2=+best bid/ask and price changes (default), 3=allows book initial dump
initial_dumpbooleanNoSend one initial order book snapshot after subscribing when level >= 3 (default: false)
{
"type": "subscribe",
"assets_ids": ["52114319501245..."],
"level": 2,
"initial_dump": true
}
const ws = new WebSocket("wss://api.openfish.me/ws/market");
ws.addEventListener("open", () => {
ws.send(JSON.stringify({
type: "subscribe",
assets_ids: [
"52114319501245915516055106046884209969926127482827954674443846427813813222426"
],
level: 2,
initial_dump: true
}));
});
ws.addEventListener("message", (event) => {
if (event.data === "PING") {
ws.send("PONG");
return;
}
console.log(JSON.parse(event.data));
});

Example server event:

{
"type": "best_bid_ask",
"asset_id": "52114319501245915516055106046884209969926127482827954674443846427813813222426",
"market": "0xbd31dc8a00000000000000000000000000000000000000000000000000000000",
"best_bid": "0.54",
"best_ask": "0.56",
"timestamp": 1770000000000
}
LevelEvents
1last_trade_price
2Level 1 + best_bid_ask, price_change
3Level 2 + book when initial_dump=true

Lifecycle events (new_market, market_resolved, tick_size_change) are always delivered.

You can add or remove assets from your subscription without dropping the connection:

{
"type": "subscribe",
"assets_ids": ["71321045679252..."]
}
{
"type": "unsubscribe",
"assets_ids": ["71321045679252..."]
}

For backward compatibility, ?market= and ?asset_id= query parameters are still accepted at connection time.

The server emits a text "PING" frame every 10 seconds. The client must reply with text "PONG".


Sent as a one-time initial snapshot when subscribing with level >= 3 and initial_dump=true. Ongoing order book mutations are sent as price_change and best_bid_ask events.

FieldTypeDescription
typestring"book"
asset_idstringAsset ID
marketstringCondition ID
bidsarray[{ "price": "0.50", "size": "15" }]
asksarray[{ "price": "0.52", "size": "25" }]
hashstringOrderbook content hash
timestampstringUnix ms

Requires level >= 2.

FieldTypeDescription
typestring"price_change"
marketstringCondition ID
asset_idstringAsset ID
pricestringAffected price level
sizestringNew size at this level ("0" = removed)
sidestring"BUY" or "SELL"
hashstringBook content hash
best_bidstring?Current best bid (if changed)
best_askstring?Current best ask (if changed)
timestampintegerUnix timestamp
FieldTypeDescription
typestring"last_trade_price"
asset_idstringAsset ID
marketstringCondition ID
pricestringExecution price
sizestringTrade size
sidestring"BUY" or "SELL" (taker perspective)
timestampintegerUnix ms

Requires level >= 2.

FieldTypeDescription
typestring"best_bid_ask"
asset_idstringAsset ID
marketstringCondition ID
best_bidstring?Best bid price, or null when no bid is available
best_askstring?Best ask price, or null when no ask is available
timestampintegerUnix ms
FieldTypeDescription
typestring"tick_size_change"
asset_idstringAsset ID
old_tick_sizestringPrevious tick size
new_tick_sizestringNew tick size
timestampintegerUnix ms

Broadcast to all connected clients regardless of subscription level.

FieldTypeDescription
typestring"new_market"
marketstringCondition ID
questionstringMarket question
slugstringURL-friendly market slug
outcomesarrayOutcome labels (e.g. ["Yes", "No"])
clob_token_idsarrayToken IDs for each outcome
tagsarrayMarket tags
timestampintegerUnix timestamp

Broadcast to all connected clients regardless of subscription level.

FieldTypeDescription
typestring"market_resolved"
marketstringCondition ID
winning_token_idstringWinning asset ID
winning_outcomestringWinning outcome label
assets_idsarrayAll asset IDs in the market
tagsarrayMarket tags
timestampintegerUnix timestamp