Monitor orders and positions in real time
This Guide shows how to combine an initial REST snapshot with live events so your application can maintain a reliable view of orders, trades and positions.
Before you begin
Step-by-step workflow
Read the initial order and position state
Before opening the socket, read the current Order Book and Positions so the application starts from a known account state.
Connect to General WebSocket
Open an authenticated General WebSocket connection and register the event handlers required by the workflow.
Subscribe to required event streams
Subscribe to the supported order, trade, position or general events needed by the application.
Process order events
Use order events to update status, quantities and rejection information. Match each event to the correct order identifier.
Process trade and position events
Apply trade and position events to the local account view. Keep order state, executed trades and resulting positions as separate records.
Recover state after reconnect
After a disconnection, read the latest REST state again before resuming event processing. This prevents missed events from leaving the application out of sync.
Verify the result
Check the relevant API response and account or market-data state to confirm that the workflow completed successfully. If the result is partial or unsuccessful, review the returned status and message before deciding whether to retry or take another action.
Common issues
Authentication or permission failure401 Unauthorized
The access token is missing, expired, or the app does not have the required permission. Generate a fresh token and retry the request.
HTTP/1.1 401 Unauthorized
{"s":"error","code":-8,"message":"Could not authenticate the user"}View Authentication →Incorrect request inputs400 Bad Request
A required field is missing or invalid (symbol, quantity, side, or product type). Read the response message, correct the payload, then retry.
HTTP/1.1 400 Bad Request
{"s":"error","code":-50,"message":"Please provide valid order parameters"}View Error Code Reference →Plan or rate-limit restriction429 Too Many Requests
The request exceeded the plan’s rate limit or an entitlement. Back off before retrying and confirm the Standard vs Prime limits for the API you are calling.
HTTP/1.1 429 Too Many Requests
Retry-After: 1
{"s":"error","message":"Rate limit exceeded"}Learn exponential backoff →Temporary network or socket interruptionTimeout
The connection dropped before a response arrived. Check the latest order, position, or socket state before sending the same request again.
Error: socket hang up
ECONNRESETView WebSocket Overview →Related API reference
Read current orders
View API →Read executed trades
View API →Read open positions
View API →Connect to General WebSocket
View API →Subscribe to account events
View API →Unsubscribe from account events
View API →Keep the General WebSocket connection alive
View API →Process order events
View API →Process trade events
View API →Process position events
View API →