Various Websocket Use Cases

Use ProphetX WebSocket patterns to confirm order activation and cancellation, build market order books, monitor fills, manage risk, and maintain reliable connectivity in real time.

Trading API — Various Websocket Use Cases

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 placing an order through the REST API, record the order_id for that order. You will then receive a confirmation message on the private channel 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 placement, the cause may be a WebSocket disconnection or a lost message. Reconnect the WebSocket and call the REST API mm/get_order/{order_id} to retrieve the current order status.

Order Cancellation Confirmation

After canceling a single order or a batch of orders, a successful cancellation returns a 200 response, indicating the orders are canceled and can no longer be filled. A confirmation message is also sent through the private WebSocket channel with details about which orders were canceled. Attempting to cancel an order that is already canceled returns a 400 error.

Order Book Real-Time Construction

To build the order book for a market and track fill activity, subscribe to the market_selection message on the broadcast channel. We recommend calling the REST APIs mm/get_markets or mm/get_multiple_markets once every 15 minutes and comparing the response with your WebSocket-built order book. This helps prevent inaccuracies caused by missed WebSocket messages. You can also subscribe to the trade_execution topic on the same broadcast channel to receive real-time fill details. When market liquidity changes, it may indicate that an order was canceled or filled. If the change was caused by matching, a trade_execution message with the price and filled amount will also be broadcast.

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 amount, and fill price. Your system can 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 public health_check message, which is broadcast 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.