Various Websocket Use Cases

Use Trading API WebSocket patterns to confirm order status, build market order books, monitor fills, and manage risk in real time.

Use these WebSocket patterns to confirm order status, monitor market updates, and manage risk in real time.

Order activation confirmation

Orders on ProphetX rely on FIFO queues for activation. After you submit an order through the REST API, record its order_id. You will receive a private-channel update indicating whether the order was activated successfully or failed. The most common failure reason is insufficient cash balance.

Safety protection

If you do not receive an order activation message within 10 seconds of submission, the cause may be a WebSocket disconnection or a lost message. Reconnect the WebSocket and call GET /v4/mm/get_order/{id} to retrieve the current order status.

Order cancellation confirmation

After you cancel an order through POST /v4/mm/cancel_order, or cancel multiple orders through POST /v4/mm/cancel_multiple_orders, a successful response returns 200. From that point the order can't match anything new: its resting quantity is removed immediately, and a private-channel update identifies the orders that were canceled. Attempting to cancel an order that is already canceled returns 400.

One timing case to handle: if the matching engine had already found a match for some of the order's quantity when your cancel arrived — but the wallet hadn't yet confirmed it — the cancel still returns 200, and that already-matched quantity still fills once the confirmation completes (normally well under a second later). The cancel is recorded against it and only takes effect if the confirmation fails. So a 200 tells you nothing further will match; it doesn't tell you the final filled amount. Read that from the orders event on your private channel (one message per fill, plus the cancel) or from GET /v4/mm/get_order/{id} once open_quantity is 0.

Build the order book in real time

To build the order book for a market and track fill activity, subscribe to market_selections on the broadcast channel. Call GET /v4/mm/get_markets or GET /v4/mm/get_multiple_markets every 15 minutes and compare the response with your WebSocket-built order book. This helps prevent inaccuracies caused by missed WebSocket messages.

To receive real-time fill details, bind trade_execution (or, on the legacy vocabulary, matched_bet) — not on the market_selections channel, but on the channel from a {"type": "tournament", ...} subscription, under whatever binding name your registration response lists for it (tournament_{id} and/or v2.tournament_{id}). See WebSocket Events for the exact binding names and payload shape.

Risk control in real time

Fill updates for your orders are pushed to you through a private channel. These messages include details such as order_id, filled_quantity, and fill_price. Use this information to rebalance your book and minimize exposure in real time.

Ensure WebSocket connectivity

A disconnect event is typically sent when the WebSocket connection is lost. To reduce false positives, you can also listen to the health_check message on your private user channel — it's not on a broadcast channel — sent every 5 seconds. If you rely on this message, disconnect and reconnect the WebSocket if no health_check message is received for more than 30 seconds.


Did this page help you?