AnalogTrader Risk API — Python SDK (typed, sync + async, retry-aware)
Project description
AnalogTrader Python SDK
Typed, production-grade client for the AnalogTrader Risk API (v1).
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file analogtrader_sdk-0.1.0.tar.gz.
File metadata
- Download URL: analogtrader_sdk-0.1.0.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d69855e9dc9166a6824eecb294c9213896d7970b1f0429f456d731ee9468941
|
|
| MD5 |
d597883eaa65ca61f415db35d0a77ef9
|
|
| BLAKE2b-256 |
ba97193ba39f6eb58c35490736dc9a9f34f905dfa208c40b3dcd61d8f2b0ec6e
|
File details
Details for the file analogtrader_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: analogtrader_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e192a83f71dba0ae7122906f55a4e07203056c952a6732d95348a1e4efdeb81
|
|
| MD5 |
393a44593bd350337cf5df91923e7389
|
|
| BLAKE2b-256 |
80227866f25a7de47ec2143304af94f1340889cf7302580581518125c5e72346
|