Skip to main content
streamAccountUpdates() emits full account snapshots for one or more traders. It combines subgraph polling, Alchemy contract-log overlays, and live price repricing so market opens and full closes can appear before subgraph indexing catches up.
Read-only clients and OstiumSubgraphClient require a user address array.

Multiple addresses

Pass one or more addresses in user to subscribe to accounts on a single stream. The stream uses one WebSocket, one poll loop, and one price feed regardless of how many addresses you watch — far cheaper than opening one stream per trader.
The snapshot is keyed by normalized trader address. Each trader bucket contains positions, orders, and limits. Duplicate addresses are de-duplicated, and stream.users returns the subscribed addresses.

Optimistic opens

For market opens, add an optimistic overlay immediately after submission and reconcile it once you know the on-chain order id.
extractOrderIdFromReceipt() decodes the current Trading contract’s market-open and market-close initiation events, plus older PriceRequested receipts. The returned id matches the base-10 Order.oid and Fill.oid format used by SDK reads. addOptimisticOpen() only supports market open orders. When streaming multiple addresses, pass the owning address as the third argument (addOptimisticOpen(params, result, '0xTraderA')); it is optional and defaults to the sole subscribed address when streaming one trader.

Parameters

alchemyApiKey can be provided when creating the client or when starting the stream. The stream throws if no Alchemy API key is available. pollIntervalMs defaults to 3000. Sub-second open/close confirmations come from the Alchemy event watchers (which also trigger an immediate poll), so the timer poll only paces reconciliation of changes with no watcher — limit fills, partial closes, TP/SL edits, and liquidations. Pass a lower value to restore a faster cadence. All subscribed traders are fetched in a single batched subgraph query per poll. The contract-log WebSocket reconnects indefinitely with a 2-second delay. Fast-overlay positions seed rollover from the pair accumulator at the open block, so streamed PnL and liquidation estimates stay aligned with the eventual indexed position.

Response schema

positions, orders, and limits use the same SDK-formatted objects returned by getOpenPositions, getOrders, and getOpenOrders.