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

Prerequisites

Add the required dependencies.

Generate Rust Types

Install the Protocol Buffer compiler, then clone the Anthid definitions.
Example build.rs:
Example Cargo.toml build dependency:

Authentication

Anthid authenticates streaming requests 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.
environment is required: set it to trading::BrokerEnvironment::Paper as i32 or trading::BrokerEnvironment::Live as i32 to match the account, because Default::default() leaves it unspecified and the server refuses that. Set order_delivery: trading::OrderDelivery::Primed as i32 on Subscribe to receive retained order snapshots first. Default::default() leaves instrument filters empty and order delivery live-only. Positions always prime retained state. Wait for the corresponding Primed event before treating 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.

Handling Events

Each TradingEvent contains a single event variant.

Bidirectional Streaming

Backend and native applications may use StreamEvents when subscriptions need to be modified over an existing connection.

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.
  • Streaming Overview
  • Python Guide
  • Trading Accounts
  • Orders
  • Positions
  • Ledger
  • Intents