Default Pattern
- Fetch startup snapshots over REST.
- Start WebSocket subscriptions for exchange metadata, market stats, orderbooks, and trader state.
- Apply snapshots and deltas through SDK primitives.
- Build instructions from the exchange cache.
- Sign and send through the user’s wallet or signer service.
- Reconcile from trader-state streams; refetch REST snapshots after reconnects or sequence gaps.
Rate Limits
Most public market and trader reads do not require auth, but authenticated sessions receive higher API limits. Auth is required for referral-code onboarding and notifications. To avoid rate-limit pressure:- Prefer WebSocket streams for frequently changing state.
- Share one process-level Phoenix client where possible.
- Share one subscription per market or trader and fan out locally.
- Cache exchange params with
client.exchangeorPhoenixMetadata. - Cache trader state with
createTraderStateStore(client)orTrader::apply_update(...). - Use REST polling for slow reconciliation, not frame-by-frame UI updates.
- Back off on
429responses and retry after the server-provided delay when available.
Snapshots And Deltas
Do not hand-roll snapshot/delta application unless you are building SDK internals. In TypeScript:client.exchangebootstraps from API or RPC, applies exchange WebSocket snapshots and deltas, and emits cache events.createTraderStateStore(client)applies trader-state snapshots and deltas and exposes derived positions, orders, triggers, history, andmarginInputs().client.marketData()combines all-mids, market-stats, and mark-price streams into per-symbol rows.
PhoenixMetadata::new(exchange)creates the exchange cache from an HTTP snapshot.metadata.apply_market_stats(&stats)updates market mark-price inputs used by margin math.Trader::apply_update(&msg)applies trader-state WebSocket updates to a local trader container.L2Book::apply_update(&msg)maintains an orderbook container.
Reconnects
WebSocket clients can reconnect, but your application still needs a reconciliation policy. After a reconnect, sequence gap, or prolonged disconnect:- Refresh exchange metadata over REST or wait for a fresh exchange snapshot.
- Refetch or await a fresh trader-state snapshot before showing account health as final.
- Drop stale L2 book state unless the SDK resource confirms it has been resynced.
- Recompute margin only after both trader state and market prices are current.