Caelum 351d54efb7
docs(sdk): runnable quant-tools examples (Python/TS/Go) (#9)
* docs(sdk): runnable quant-tools examples (Python + TypeScript)

Show the quant endpoints through the SDKs: ta/fees/sizer/pnl. Both read-only,
graceful on a down API. Python imports the local package; TS declares a minimal
process shim (dependency-free) and typechecks clean against the SDK.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* docs(sdk): Go quant-tools example (parity with Python/TS)

clients/go/example/quant: calls TA/Fees/Sizer/PnL read-only, exits 0 offline.
go vet + build clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-16 14:57:05 +03:00

45 lines
1.4 KiB
Python

#!/usr/bin/env python3
"""Demonstrate the Guardrail quant endpoints via the Python SDK.
Run a Guardrail API locally first (`cargo run -p guardrail-api`), then:
python3 clients/python/examples/quant_tools.py
Every call is read-only. Set GUARDRAIL_API to point at a non-default host.
"""
from __future__ import annotations
import os
import sys
# Allow running from the repo root without installing the package.
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
from guardrail_client import GuardrailClient # noqa: E402
def main() -> int:
client = GuardrailClient(base_url=os.environ.get("GUARDRAIL_API", "http://127.0.0.1:8080"))
try:
rsi = client.ta("rsi", [44, 44.3, 44.1, 43.6, 44.3, 44.8, 45.1, 45.4, 45.8, 46.0], period=5)
print("RSI:", rsi.get("result", rsi))
cost = client.fees(notional_usd=25000, quantity=12, side="buy")
print("swap cost:", cost.get("breakdown", cost))
size = client.sizer("kelly", win_prob=0.6, odds=1.5)
print("kelly size:", size.get("output", size))
pnl = client.pnl(fills="CAKE,buy,10,2;CAKE,sell,4,3", marks="CAKE:3")
print("pnl total:", pnl.get("report", {}).get("total", pnl))
except Exception as err: # noqa: BLE001 - example: surface any connection error plainly
print(f"error (is the API running?): {err}", file=sys.stderr)
return 1
return 0
if __name__ == "__main__":
raise SystemExit(main())