Skip to main content
Anthid provides generated Protocol Buffer definitions that can be used to build Python clients for the Streaming API. This guide demonstrates how to generate the Python gRPC client and subscribe to real-time trading events.

Prerequisites

Install the required Python packages.

Download the Protobuf Definitions

Clone the Anthid protobuf repository.

Generate Python Client Code

Generate Python classes from the protobuf definitions.
The generated trading namespace contains the message definitions and gRPC service stubs required to interact with Anthid services.

Authentication

Streaming requests authenticate with either a Bearer access token or an API key passed as gRPC metadata. This guide uses an API key.

Subscribe to Events

The example below demonstrates connecting to the server-streaming endpoint and subscribing to broker order and position events.
environment is required: set it to trading_types_pb2.BROKER_ENVIRONMENT_PAPER or trading_types_pb2.BROKER_ENVIRONMENT_LIVE to match the account. The enum is defined in trading_types.proto, so it is generated into trading_types_pb2 rather than trading_service_pb2. To receive retained order snapshots first, set order_delivery=trading_pb2.ORDER_DELIVERY_PRIMED in Subscribe. 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.

Bidirectional Streaming

Backend and native applications may prefer the bidirectional StreamEvents endpoint. This endpoint allows subscriptions and unsubscriptions to be sent over an existing stream without creating a new connection.

Handling Disconnects

Applications should automatically reconnect when a stream is interrupted. After reconnecting:
  1. Establish a new stream.
  2. Re-authenticate using a Bearer access token or API key.
  3. Re-subscribe to required trading accounts.
  4. Resume event processing.
  • Streaming Overview
  • Trading Accounts
  • Orders
  • Positions
  • Ledger
  • Intents