Skip to main content
Anthid provides Protocol Buffer definitions that can be used to generate Node.js clients for the Streaming API. This guide demonstrates connecting to the Streaming API and receiving real-time broker order and position updates.

Prerequisites

Install the required dependencies.

Download the Protobuf Definitions

Load the Proto Definitions

Authentication

Streaming requests authenticate with either a Bearer access token or the x-api-key metadata header. This guide uses an API key.

Subscribe to Events

The SubscribeEvents endpoint provides a server-streaming interface suitable for most applications.

Bidirectional Streaming

Backend and long-running services can use StreamEvents to dynamically subscribe and unsubscribe from accounts over an existing connection.
With keepCase: false, request and response fields use camel case: tradingAccountId, environment, orderDelivery, and event.primed.eventType. environment is required on every subscribe and unsubscribe request: "BROKER_ENVIRONMENT_PAPER" or "BROKER_ENVIRONMENT_LIVE", matching the account’s environment. Set orderDelivery: "ORDER_DELIVERY_PRIMED" on the subscribe request to receive retained order snapshots first. Wait for the order primed event before treating that initial delivery as complete. Terminal orders and zero-quantity positions expire from retained stream state after one hour. Rebuild a fresh snapshot set on reconnect so an old cache does not retain entries that no longer replay. See Rebuilding a cached view.

Unsubscribe

To stop receiving events for an account, send an unsubscribe request on the same stream.

Handling Disconnects

Applications should automatically reconnect when a stream closes unexpectedly. After reconnecting:
  1. Create a new stream.
  2. Authenticate using a Bearer access token or API key.
  3. Re-subscribe to required trading accounts.
  4. Resume event processing.

TypeScript

The same approach works in TypeScript. Many teams choose to generate strongly typed TypeScript definitions from the Anthid protobuf files during their build process rather than loading protobuf definitions dynamically at runtime.
  • Streaming Overview
  • Python Guide
  • Rust Guide
  • Trading Accounts
  • Orders
  • Positions
  • Ledger
  • Intents