Metadata-Version: 2.4
Name: analogtrader-sdk
Version: 0.1.0
Summary: AnalogTrader Risk API — Python SDK (typed, sync + async, retry-aware)
Author: AnalogTrader
License: MIT License
        
        Copyright (c) 2026 AnalogTrader
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in
        all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
        THE SOFTWARE.
        
Project-URL: Source, https://github.com/godbrainquantum/godbrain-os
Project-URL: Issues, https://github.com/godbrainquantum/godbrain-os/issues
Project-URL: Changelog, https://github.com/godbrainquantum/godbrain-os/blob/main/analogtrader/sdk/python/CHANGELOG.md
Keywords: analogtrader,risk,trading,sdk,fintech
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Office/Business :: Financial
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx<1,>=0.27
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: pytest-asyncio>=0.24; extra == "dev"
Requires-Dist: ruff>=0.6; extra == "dev"
Dynamic: license-file

# AnalogTrader Python SDK

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

[![PyPI](https://img.shields.io/pypi/v/analogtrader-sdk)](https://pypi.org/project/analogtrader-sdk)
[![Python](https://img.shields.io/pypi/pyversions/analogtrader-sdk)](https://pypi.org/project/analogtrader-sdk)

```bash
pip install analogtrader-sdk
```

## Quick start

```python
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

```python
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

```python
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](./CHANGELOG.md).

## License

MIT.
