A stream sends only what happens after you connect. It has no snapshot and does not replay events you missed, so a correct client always pairs it with a REST read. The reconciliation pattern below shows how.
Check the host first
Read the account’s host from List hosts and check its capabilities before you connect. A stream the host does not support is refused with422 NotSupported.
See Host capabilities for how to read these entries.
Connect
Send the sameX-API-KEY and X-API-SECRET headers you use for HTTP on the upgrade request. There is nothing to send after connecting: the account is in the path, and the server ignores any frames you send.
With websocat:
websockets library, version 14 or later:
Messages
Every message is one JSON text frame with the same envelope:timestamp is when Plurex sent the event, and data is the payload.
Order events
Each order event carries thechange that happened and the complete order, exactly as Get an order returns it:
change to decide what to react to. New change types can be added, so handle an unrecognised type the same way as Unknown.
Transaction events
Each transaction event is one balance posting, with the sameid that List account transactions returns for it:
amount is signed from your side: positive increases the balance, negative decreases it. Transaction events are ordered among themselves but not relative to order events, so a fee can arrive before or after the fill it belongs to. See Balances, positions and settings for posting types and links.
Keep a correct local copy
The streams promise no snapshot, no replay, no sequence numbers and no resume point. The pattern that stays correct anyway:1
Connect first
Open the stream before reading anything. Events that arrive from now on are buffered by your client.
2
Read the current state
Page through List open orders (or recent transactions) until
nextCursor is null. This is your starting copy.3
Apply events on top
Apply buffered events, then live ones, in the order they arrive. For orders the newest event for an order ID replaces what you hold; drop an order from your open set once its state is
Filled, Cancelled or Rejected. For transactions, add any posting whose id you do not have.4
After any disconnect, do both again
Events sent while you were disconnected are gone. Reconnect, then read the REST state again and replace your copy.
websockets 14 or later and httpx:
websockets client holds messages that arrive while you read the REST state, so they are applied after it, in order. The loop backs off on network failures and on 429 and 5xx responses, and stops on errors that need a fix.
For transactions, the same loop works with ListTransactions in place of ListOpenOrders. Keep posting IDs you have seen, and after reconnecting re-read history a little further back than the newest posting you hold, so a posting that reached the host’s history late is not missed. The listTransactions capability’s defaultOrdering says whether history comes newest or oldest first.
Close codes
Any other disconnect, such as a network failure, is handled the same way: reconnect, then reconcile.
What a stream does not promise
- No snapshot on connect, and no replay of missed events.
- No sequence numbers or resume tokens. A gap is detected only by a disconnect.
- No ordering between the order stream and the transaction stream.
- No individual executions when
includesFillDetailsisfalse. - No browser authentication.
Related
- Place and manage orders: order states and how to read an order.
- Balances, positions and settings: transactions and balances.
- Stream account orders and Stream account transactions: the message reference.