Setup
Generate an SDK key from horizon.mathematicalcompany.com under Settings > SDK Keys.Quick Start - Full Lifecycle
API Reference
Constructor
Methods
| Method | Description |
|---|---|
create_strategy(name, code, ...) | Create a strategy from Python code |
validate(strategy_id) | Validate code (static + sandbox) |
list_strategies() | List all strategies |
get_strategy(id) | Get strategy details |
save_credentials(private_key, ...) | Save exchange credentials (encrypted) |
list_credentials() | List credential metadata (no keys) |
deploy(id, credential_id, mode, markets) | Deploy a strategy |
stop(id) | Stop active deployments |
status(id) | Current deployment status |
deployments(id) | List deployment history |
metrics(id, limit=50) | Performance metrics |
logs(id, limit=100, level, deployment_id) | Deployment logs |
account() | Plan, limits, usage |
wait_for_running(id, timeout=120) | Block until running |
Create Strategy
- Forbidden imports blocked:
os,subprocess,socket,requests,pickle,ctypes, etc. - Forbidden builtins blocked:
eval(),exec(),compile(),open(),__import__(), etc. - Required SDK patterns: at least one
def ...(ctx)pipeline function andhz.quotes()/hz.run()usage. - Code is sanitized: BOM stripped, line endings normalized, common whitespace dedented.
422 with detailed errors:
Validate
Two-phase validation:- Static analysis (platform-side, instant): forbidden patterns, import whitelist, SDK usage checks.
- Sandbox validation (worker-side): AST parsing, import resolution, forbidden attribute access.
Save Credentials
- Private key is transmitted over HTTPS only.
- Encrypted at rest with AES-256-GCM (platform-side encryption key, not stored in DB).
- Never returned in any API response - not in
list_credentials, not insave_credentialsresponse. - Decrypted only in-memory at deploy time, then sent to the worker over HMAC-signed HTTPS.
- Max 10 credentials per user.
- All credential operations are critically audited (audit log insert failure throws, preventing silent loss).
Deploy
mode="paper"- dry run, no real orders.mode="live"- requires Pro/Ultra plan + circuit breaker enabled.markets- patcheshz.run(markets=[...])in the strategy code.
Logs
Security Architecture
Every request goes through multiple security layers - all enforced server-side, never in the SDK client:Authentication & Authorization
| Layer | How it works |
|---|---|
| API key validation | SHA-256 hash lookup in sdk_keys table. |
| Expiration | Keys can have an expires_at date. Expired keys are rejected. |
| Rate limiting | Per-user, per-action limits via Upstash Redis (in-memory fallback for dev). |
| Audit logging | Every create/deploy/stop/credential action is logged. Credential ops are critical (failure throws). |
Code Security
| Layer | What it blocks |
|---|---|
| Import whitelist | Only horizon, hz, datetime, collections, math, typing, enum, statistics, pydantic, abc |
| Forbidden builtins | eval, exec, compile, open, __import__, globals, locals, getattr, setattr, breakpoint |
| Forbidden modules | os, sys, subprocess, socket, http, urllib, requests, pickle, ctypes, threading, multiprocessing, importlib, shutil, tempfile |
| Forbidden attributes | __builtins__, __subclasses__, __bases__, __globals__, __code__, __closure__, __mro__, __reduce__ |
| Line continuation block | Backslash \ continuations blocked to prevent pattern bypass |
| Code sanitization | BOM stripping, line ending normalization, leading whitespace dedent |
| Worker sandbox | AST-level validation, import resolution check, separate process isolation |
Credential Security
- Encryption key is a 256-bit hex string stored in platform env (
ENCRYPTION_KEY), never in the database. - Worker communication uses Bearer token + HMAC-SHA256 signature + HTTPS-only enforcement.
- Worker URL must be
https://in production (localhost exempted for dev).
Deployment Security
| Check | When |
|---|---|
Strategy must be validated/stopped/error/deployed status | Before deploy |
| Circuit breaker required for live trading | Before deploy |
| Double-deploy guard (409 if already active) | Before deploy |
| Worker capacity check (queue if full) | Before deploy |
| Plan limits (concurrent deploys, live trading) | Before deploy |
Risk overrides injected by platform_runner.py | At runtime (worker) |
| Strategy runs in isolated subprocess | At runtime (worker) |
Plan Limits
All limits are enforced server-side before any action proceeds.| Limit | Free | Pro | Ultra |
|---|---|---|---|
| Max strategies | 1 | 10 | Unlimited |
| Concurrent deploys | 1 | 5 | 10 |
| Live trading | No | Yes | Yes |
| Backtests / week | 1 | 10 | Unlimited |
| Priority execution | No | No | Yes |
Deployment Lifecycle
| Status | Meaning |
|---|---|
pending | Created, worker being contacted |
queued | Worker at capacity, waiting for a slot |
starting | Worker acknowledged, process launching |
running | Strategy is actively trading |
stopped | Gracefully stopped (via cloud.stop() or platform UI) |
error | Crashed or timed out |
Rate Limits
| Action | Limit |
|---|---|
| Read endpoints (strategies, metrics, logs, credentials) | 30 / minute |
| Create strategy | 10 / minute |
| Validate | 10 / minute |
| Deploy | 5 / minute |
| Stop | 10 / minute |
| Save credentials | 5 / minute |
429 Too Many Requests.
MCP Tools
When running the MCP server, cloud operations are available via thecloud compound tool with an action parameter:
| Action | Description |
|---|---|
create_strategy | Create strategy from code |
validate | Validate strategy code |
save_credentials | Save exchange credentials (encrypted) |
list_credentials | List credential metadata |
list_strategies | List strategies |
get_strategy | Get strategy details |
deploy | Deploy a strategy |
stop | Stop a deployment |
status | Get deployment status |
metrics | Get performance metrics |
logs | Get deployment logs |
account | Get account info |
“Create a market making strategy, save my Polymarket key, and deploy it in paper mode”
HORIZON_API_KEY from the environment for authentication.
Error Handling
All API errors raiseHorizonCloudError with status_code and body:
| Status | Meaning |
|---|---|
| 400 | Bad request (invalid params, missing code, key format error) |
| 401 | Invalid or missing API key |
| 403 | Plan limit exceeded |
| 404 | Strategy or credential not found |
| 409 | Strategy already has an active deployment |
| 422 | Code validation failed (includes validation_errors list) |
| 429 | Rate limit exceeded |
| 500 | Worker or platform error |
Architecture
HorizonCloud) calls the Platform’s v1 REST API over HTTPS using your SDK key. The Platform validates the key (SHA-256 hash lookup), enforces plan limits and rate limits, then forwards deploy requests to the Worker over HMAC-signed HTTPS. The Worker validates the code in a sandbox, spawns an isolated subprocess running your strategy with risk overrides injected, and reports metrics back via webhooks.