Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.anthid.com/llms.txt

Use this file to discover all available pages before exploring further.

Anthid uses gRPC streaming to deliver live broker context back to your application as soon as it is available. REST is still the right interface for submissions and queries, but the stream is where your application receives immediate execution updates, order changes, position changes, heartbeats, and subscription confirmations. The protobuf definitions for Anthid streaming are published in the anthid-labs/proto repository.

Language Support

Any programming language with Protocol Buffers and gRPC support can connect to the Anthid streaming platform. Python is used in this guide because it is popular and easy to follow, but it is only an example. Teams can generate clients from the same proto definitions for languages such as Go, TypeScript, Java, C#, Rust, and others.

Why gRPC

gRPC is a high-performance RPC framework built on HTTP/2 and Protocol Buffers. Instead of sending loosely shaped messages over a raw socket, gRPC gives you a typed service contract, generated clients, efficient binary payloads, and first-class streaming. Anthid chose gRPC over WebSockets for the streaming API because broker execution updates benefit from:
  • Strongly typed messages generated from shared .proto files
  • Efficient binary serialization with Protocol Buffers
  • Bidirectional streaming over HTTP/2
  • Built-in metadata for authentication, including x-api-key
  • Cleaner client generation across languages
  • A more structured contract for long-lived execution streams
For trading workflows, this means less custom socket plumbing and a clearer interface for live broker events.

Build the protobuf client

Clone the proto repository and generate Python client code from the .proto files.

macOS

If on a Mac, you can use Homebrew to install protobuf and Python dependencies then configure a local python virtual environment to support development such as the following.

Install Dependencies

brew install protobuf

Setup Python Virtual Environment

python3 -m venv .venv
source .venv/bin/activate

Install dependencies into the virtual env

python -m pip install grpcio grpcio-tools protobuf

Clone Proto Dependencies

git clone https://github.com/anthid-labs/proto.git anthid-proto

Change directory and Generate the Proto Client

cd anthid-proto
mkdir -p ../generated/python
python -m grpc_tools.protoc \
  -I . \
  --python_out=../generated/python \
  --grpc_python_out=../generated/python \
  $(find . -name "*.proto")

Linux

On Linux and debian based systems, you can install protobuf and Python dependencies with apt-get and configure a local python virtual environment to support development such as the following.

Install Dependencies

sudo apt-get update
sudo apt-get install -y protobuf-compiler python3-venv

Setup Python Virtual Environment

python3 -m venv .venv
source .venv/bin/activate

Install dependencies into the virtual env

python -m pip install grpcio grpcio-tools protobuf

Clone Proto Dependencies

git clone https://github.com/anthid-labs/proto.git anthid-proto

Change directory and Generate the Proto Client

cd anthid-proto
mkdir -p ../generated/python
python -m grpc_tools.protoc \
  -I . \
  --python_out=../generated/python \
  --grpc_python_out=../generated/python \
  $(find . -name "*.proto")
The exact generated module names depend on the package and file names in the proto repository. After generation, import the generated *_pb2.py and *_pb2_grpc.py files from your application.

Authentication

The initial gRPC connection must include your API key in the x-api-key metadata header.
metadata = (("x-api-key", "YOUR_API_KEY"),)
After the stream connects, Anthid sends regular heartbeats so your client can tell that the connection is still alive.

Subscriptions

Once connected, your client can subscribe to additional message types for a trading account. By default, each organization can open up to 100 streaming connections. The subscription messages are defined in protobuf:
message Subscribe {
  string trading_account_id = 1;
  repeated EventType subscriptions = 2;
}

message Unsubscribe {
  string trading_account_id = 1;
}

message Status {
  string message = 1;
}

enum EventType {
  EVENT_TYPE_UNSPECIFIED = 0;
  EVENT_TYPE_BROKER_ORDER = 1;
  EVENT_TYPE_BROKER_POSITION = 2;
}
To subscribe, send a Subscribe message with the trading account ID and the event types your client wants to receive. To unsubscribe, send an Unsubscribe message with the trading account ID.

Python example flow

The example below shows the expected flow. Update the generated import paths, request wrapper names, and stub method names to match the generated code from the proto repository.
import asyncio
import grpc

from generated import streaming_pb2
from generated import streaming_pb2_grpc


API_KEY = "YOUR_API_KEY"
TRADING_ACCOUNT_ID = "YOUR_TRADING_ACCOUNT_ID"
STREAM_TARGET = "api.anthid.com:443"


async def stream_requests():
    yield streaming_pb2.StreamRequest(
        subscribe=streaming_pb2.Subscribe(
            trading_account_id=TRADING_ACCOUNT_ID,
            subscriptions=[
                streaming_pb2.EVENT_TYPE_BROKER_ORDER,
                streaming_pb2.EVENT_TYPE_BROKER_POSITION,
            ],
        )
    )

    while True:
        await asyncio.sleep(60)


async def main():
    credentials = grpc.ssl_channel_credentials()
    metadata = (("x-api-key", API_KEY),)

    async with grpc.aio.secure_channel(STREAM_TARGET, credentials) as channel:
        stub = streaming_pb2_grpc.StreamingServiceStub(channel)
        responses = stub.Stream(stream_requests(), metadata=metadata)

        async for response in responses:
            if response.HasField("heartbeat"):
                print("heartbeat", response.heartbeat)
            elif response.HasField("status"):
                print("status", response.status.message)
            elif response.HasField("broker_order"):
                print("broker order", response.broker_order)
            elif response.HasField("broker_position"):
                print("broker position", response.broker_position)
            else:
                print("stream event", response)


if __name__ == "__main__":
    asyncio.run(main())

Unsubscribe flow

When your client no longer needs events for an account, send an Unsubscribe message on the same request stream.
yield streaming_pb2.StreamRequest(
    unsubscribe=streaming_pb2.Unsubscribe(
        trading_account_id=TRADING_ACCOUNT_ID,
    )
)
Keep the stream connected for live execution context and use REST for durable queries. The stream gives your application immediate broker updates, while REST gives you the persisted platform record for search, reconciliation, metrics, and historical analysis.