Prerequisites
Add the required dependencies.Generate Rust Types
Install the Protocol Buffer compiler, then clone the Anthid definitions.build.rs:
Cargo.toml build dependency:
Authentication
Anthid authenticates streaming requests with either a Bearer access token or thex-api-key metadata header. This guide uses an API key.
Subscribe to Events
TheSubscribeEvents 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
EachTradingEvent contains a single event variant.
Bidirectional Streaming
Backend and native applications may useStreamEvents when subscriptions need to be modified over an existing connection.
Handling Disconnects
Applications should automatically reconnect when a stream closes unexpectedly. After reconnecting:- Create a new stream.
- Authenticate using a Bearer access token or API key.
- Re-subscribe to required trading accounts.
- Resume event processing.
Related Resources
- Streaming Overview
- Python Guide
- Trading Accounts
- Orders
- Positions
- Ledger
- Intents