User Fill Stream
Receive private order events over /ws. Authenticate with an API key; use REST to place, cancel, and list
orders.
wss://api.unhedged.gg/wsorder:readFee signs: Top-level fee is negative when
paid; cashflow = payment + fee,
as in GET /api/v1/trades. Nested order.cum_fees stays engine-positive.
{
"type": "auth",
"token": "Bearer ak_your_key_here"
} // success
{ "type": "authenticated", "userId": "clx...", "role": "USER" }
// missing order:read
{
"type": "error",
"error": "forbidden",
"code": "MISSING_SCOPE",
"scope": "order:read"
} trading_resync The trading feed reconnected. Reload orders, positions, and recent fills through REST. Missed WebSocket notifications are not replayed.
trade Each match emits one event per leg: 2 for regular trades, N for cross trades. All share trade_id, unique within the market; key on market_id + trade_id + order_id. Top-level fee is signed (negative when paid); cashflow = payment + fee, as in GET /api/v1/trades.
share_update Authoritative post-change snapshot for one market/outcome after ask lock/unlock, trade settlement, or auto-redeem. available, locked_me, and total = available + locked_me are contract quantities as 2-decimal strings.
burned Complete-set redemption. quantity is a 2-decimal contract string; payment = cashflow = $1 per 1.00 set ("0.25" redeemed = $0.25).
conditional_order Final order snapshot for a triggered stop-loss or take-profit step.
cancelled_order Final order snapshot for a cancelled resting order.
amended_order Order snapshot after a same-price size decrease or an accepted higher revision with unchanged price and size. The order keeps its id and queue priority; refresh open orders and balances.
{
"type": "trade",
"room": "me:clx...",
"timestamp": 1770000000000,
"data": {
"exec_id": "42",
"trade_id": "184221",
"qty": "25.00",
"transact_ts": 1770000000000000,
"market_id": "clx...",
"trade_type": "direct",
"role": "taker",
"is_maker": false,
"price": "0.62",
"fee": "-0.25",
"payment": "-15.5",
"cashflow": "-15.75",
"order": {
"id": "123",
"market_id": "clx...",
"outcome": "out_0",
"outcome_label": "YES",
"side": "bid",
"type": "Limit",
"user": "clx_balance...",
"price": "0.62",
"quantity": "100.00",
"cum_quantity": "25.00",
"cum_quote_quantity": "15.5",
"cum_fees": "0.25",
"last_trade_fee": "0.25",
"last_exec_price": "0.62",
"status": "Placed"
}
}
} {
"type": "burned",
"room": "me:clx...",
"timestamp": 1770000000000,
"data": {
"msg": "burned",
"burn_id": "1",
"market_id": "clx...",
"balance_id": "clx_balance...",
"quantity": "1.00",
"cause_type": "trade",
"reference_id": "clx...:184221",
"payment": "1.00",
"cashflow": "1.00",
"transact_ts": 1770000000000000
}
} {
"type": "share_update",
"room": "me:clx...",
"timestamp": 1770000000000,
"data": {
"msg": "share_update",
"user": "clx_balance...",
"market_id": "clx...",
"outcome": "out_0",
"outcome_label": "YES",
"available": "12.00",
"locked_me": "3.00",
"total": "15.00",
"cause_type": "trade",
"reference_id": "clx...:184221",
"transact_ts": 1770000000000000
}
} const apiKey = process.env.UNHEDGED_API_KEY;
const marketId = "clx...";
const ws = new WebSocket("wss://api.unhedged.gg/ws");
ws.onopen = () => {
ws.send(JSON.stringify({
type: "auth",
token: `Bearer ${apiKey}`
}));
};
ws.onmessage = async (event) => {
const message = JSON.parse(event.data);
if (message.type === "authenticated") {
await backfillFills(marketId);
return;
}
if (message.type === "trade") {
handleFill(message.data);
}
if (message.type === "share_update") {
applyShareSnapshot(message.data);
}
if (message.type === "burned") {
handleBurn(message.data);
}
}; Reconnect recovery
No replay cursor. After connecting or reconnecting:
- Backfill from your last processed fill.
GET /api/v1/trades?limit=500&startTime=<last fill time>Use ISO 8601 or epoch milliseconds; dividetransact_tsmicroseconds by 1000. This avoids paging the full history. - Deduplicate fills. Key on
market_id+trade_id+order_id. - Refresh positions. Apply live
share_updatesnapshots to your positions map. After reconnecting, recover missed snapshots with:GET /api/v1/portfolio/me/shares?marketId=clx...