For the complete documentation index, see llms.txt. This page is also available as Markdown.

Python SDK

Install the official AFX Python SDK and run examples.

The official Python SDK is maintained in afx-dex/afx-python-sdk.

Use this project instead of downloading standalone SDK files from the docs. The SDK includes the generated protobuf module under afx.protos, so users do not need to download dex.proto, generate dex_pb2.py, or keep a local dex_client.py.

Install

git clone https://github.com/afx-dex/afx-python-sdk.git
cd afx-python-sdk
python3 -m pip install -e .

Configure Wallets

Private keys are loaded only from environment variables:

export AFX_MASTER_PRIVATE_KEY="0xYOUR_MASTER_PRIVATE_KEY"
export AFX_AGENT_PRIVATE_KEY="0xYOUR_AGENT_PRIVATE_KEY"

Client Layout

from afx import AfxClient

client = AfxClient.from_env(testnet=True)

products = client.info.get_products()
order = client.exchange.place_order(
    symbol_code=1,
    px="50000",
    qty="0.001",
    side="BUY",
    ord_type="LIMIT",
    tif="GTC",
)

Trading actions are under client.exchange, read-only queries are under client.info, and WebSocket helpers are under client.websocket.

For order requests, pass active order types such as "LIMIT" or "MARKET". The proto default "NONE" and display-only OrdType values such as "MARKET_LIQ_SELLOFF", "LIMIT_LIQ_SELLOFF", "ADL", and "LIQUIDATION" may appear in query or stream data, but they must not be used in order requests.

Examples

Every public SDK feature has an example under the SDK repository's examples/ directory:

Example Index

Info queries

Exchange actions

WebSocket and advanced usage

Verify

The SDK tests cover signing helpers, protobuf serialization, client behavior, and example imports.

Last updated