Skip to main content

AnalogTrader Python SDK

Typed, production-grade client for the AnalogTrader Risk API (v1).

PyPI Python

pip install analogtrader-sdk

Quick start

from analogtrader_sdk import AnalogTraderClient

client = AnalogTraderClient(
    base_url="https://api.analogtrader.com",
    api_key="at_live_xxx",
)

# Health check (no auth)
health = client.health()
print(health.ok, health.checks)

# Risk validation (requires API key with risk.validate scope)
result = client.risk_validate(
    venue="MT5",
    symbol="XAUUSD",
    side="BUY",
    size_usd=100.0,
    conviction=0.72,         # optional
    regime="calm",           # optional
)
print(result.approved, result.risk_grade)
for name, gate in result.gates.items():
    print(f"  {name}: pass={gate.pass_} value={gate.value} limit={gate.limit}")

Async usage

import asyncio
from analogtrader_sdk import AsyncAnalogTraderClient

async def main():
    async with AsyncAnalogTraderClient(
        base_url="https://api.analogtrader.com",
        api_key="at_live_xxx",
    ) as client:
        result = await client.risk_validate(
            venue="MT5", symbol="XAUUSD", side="BUY", size_usd=100.0,
        )
        print(result.approved, result.risk_grade)

asyncio.run(main())

Configuration

Parameter Default Notes
base_url required https://api.analogtrader.com
api_key optional Required for /v1/risk/* endpoints
timeout 10.0s Per-request timeout (httpx)
max_retries 3 0 disables retry
backoff_base 0.2s First-retry delay before jitter
backoff_max 5.0s Cap on exponential backoff

Retries fire on 429, 502, 503, 504, network errors, and timeouts. Backoff is jittered exponential (base × 2^attempt, capped, randomized 50%-100% to avoid thundering-herd).

Error handling

from analogtrader_sdk import (
    ATApiError,           # API returned non-2xx
    ATConnectionError,    # network failure
    ATTimeoutError,       # request timed out (subclass of ATConnectionError)
)

try:
    result = client.risk_validate(...)
except ATApiError as e:
    print(e.status, e.code, e.type, e.request_id, e.details)
except ATTimeoutError as e:
    print("timeout", e)
except ATConnectionError as e:
    print("network", e)

ATApiError carries the structured error body the API returns (error.type, error.code, error.message, error.details, request_id).

Tracing

Every request emits X-Request-ID: <uuid>. The meta.request_id field on every response (mirrored back from the server) lets you correlate client-side logs with server-side audit chain.

Versioning

This SDK follows semver. The Risk API contract is frozen at v1; new endpoints land additively, breaking changes require a major bump.

See CHANGELOG.md.

License

MIT.

Release files for analogtrader-sdk 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for analogtrader-sdk 0.1.0
File Size Uploaded
analogtrader_sdk-0.1.0.tar.gz 11.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for analogtrader-sdk 0.1.0
File Interpreter ABI Platform
analogtrader_sdk-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.8 kB

Release files / analogtrader_sdk-0.1.0.tar.gz

Download URL analogtrader_sdk-0.1.0.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
4d69855e9dc9166a6824eecb294c9213896d7970b1f0429f456d731ee9468941
BLAKE2b-256 checksum
How to use checksums
ba97193ba39f6eb58c35490736dc9a9f34f905dfa208c40b3dcd61d8f2b0ec6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / analogtrader_sdk-0.1.0-py3-none-any.whl

Download URL analogtrader_sdk-0.1.0-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6e192a83f71dba0ae7122906f55a4e07203056c952a6732d95348a1e4efdeb81
BLAKE2b-256 checksum
How to use checksums
80227866f25a7de47ec2143304af94f1340889cf7302580581518125c5e72346
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page