Market Gateway WebSocket
Stream public ORDER_BOOK market data and request execution quotes over
WebSocket. Place and cancel orders through authenticated REST /api/v1/orders.
WebSocket URL
wss://market-gateway.unhedged.gg/wsProtocol
JSON-RPC over WebSocket text frames.
- Request
id,method, optionalparams.- Response
- Same
id, plusresultorerror.
Reconnect after shutdown
Close code 1012: market gateway stopped; reconnect required.
- Reconnect.
- Request a fresh
snapshot. - Resume sequenced deltas.
const ws = new WebSocket("wss://market-gateway.unhedged.gg/ws");
ws.onopen = () => {
ws.send(JSON.stringify({
id: 1,
method: "subscribe",
params: {
market_id: "clx...",
best_bid_ask: true,
snapshot_update: true,
trade: true
}
}));
};
ws.onmessage = (event) => {
const message = JSON.parse(event.data);
if (message.id) {
// JSON-RPC response
console.log(message.result ?? message.error);
return;
}
// Unsolicited gateway event: best_bid_ask, snapshot_update, trade, etc.
console.log(message);
}; Gateway Methods
list_markets List active matching-engine markets from the gateway catalog, including maker_protection_ms: the minimum age for incoming taking-capable instructions. Zero disables the window.snapshot Return the gateway order-book mirror for one market.subscribe Subscribe to best bid/ask, book diff, and trade streams for a market.unsubscribe Remove one or more active subscriptions for a market.query_trade Historical public trade ticks for one market; at most 500 trade IDs.quote_execution Estimates immediate fill size, notional, fees, and worst_execution_price from the mirrored L2 book. For Market orders, derive a price bound from best ask (buy) or best bid (sell); use it for both quote and placement. Zero tolerance forbids worse prices. Reuse quoteQuantity with budgetIncludesFees to cap live cost, including automatically selected fees.Gateway Errors
-32601 Method not found.-32602 Invalid params.-32004 Market or outcome does not exist in the active gateway catalog.-32005 Gateway message rate limit exceeded.Gateway Events
new_market Market added to the gateway catalog.
finish_market Market removed from the gateway catalog.
best_bid_ask Top-of-book update for one outcome.
snapshot_update Incremental L2 book diff for one or more price levels.
trade Public trade tick; direct and cross-outcome fills share the same msg value.
Gateway trade_id is a JSON
number on the wire. REST and private /ws order/trade IDs are strings.
{
"id": 2,
"method": "snapshot",
"params": { "market_id": "clx..." }
} {
"id": 3,
"method": "quote_execution",
"params": {
"market_id": "clx...",
"outcome": "out_0",
"side": "bid",
"type": "Limit",
"price": 0.50,
"quantity": "10.00"
}
} Quantity format
- Requests
quantityis in contracts: decimal string, at most 2 decimals, minimum"0.01". JSON integers mean whole contracts:10 = "10.00".- Responses
- Book levels, trade ticks, and quotes return quantities as 2-decimal strings.
Quote limitations
- Estimate
quote_executionestimates immediate fills using aggregated L2 depth.- Excluded
- Your balance and self-trade prevention.
- Freshness
- The gateway mirror can lag while processing market-data messages.