# ClearFills — Full Technical Reference (llms-full.txt) > Deterministic Ed25519 pre-trade risk firewall, attested-only multi-venue execution adapters (IBKR, Alpaca, Polymarket, Kalshi), SEC EDGAR Strategy Receipts, and Frontier AI Trading Arena. Built by MLDSAI Inc. (Toronto). Apache-2.0 Open Core. Website: https://clearfills.com Live API: https://clearfills-api.fly.dev GitHub: https://github.com/clearfills/clearfills X: https://x.com/clearfills Concise overview: https://clearfills.com/llms.txt Agent contract: https://clearfills.com/agents.txt --- ## 1. Architecture: Zero-Trust Pre-Trade Firewall Untrusted AI trading agents (Grok, Claude, Codex, `TauricResearch/TradingAgents`, `virattt/ai-hedge-fund`, or custom Python loops) NEVER hold brokerage credentials or wallet private keys. ``` [Untrusted AI Agent / MCP Client] | JSON TradeProposal (no broker keys) v [ClearFills Deterministic Risk Firewall] <-- Pure Python math, zero LLM calls | Ed25519 SignedAttestation (SHA-256 order hash + 120s TTL + single-use nonce) v [Air-Gapped Execution Gateway (Fly.io + Tailscale)] | Verifies Ed25519 signature, TTL, and unspent nonce before routing v [IBKR / Alpaca / Polymarket CLOB / Kalshi] ``` ## 2. Deterministic Policy Rules & Rejection Codes Every `TradeProposal` is evaluated deterministically before any Ed25519 signature is minted: | Rejection Code | Invariant Enforced | | :--- | :--- | | `MARKET_ORDER_FORBIDDEN` | Only `LMT` (limit) orders are permitted; `MKT` sweeps are unconditionally vetoed. | | `MISSING_HARD_STOP` | Equities/options require an atomic protective stop-loss price; binary markets require bounded collateral. | | `MAX_TRADE_RISK_EXCEEDED` | Max risk per trade <= 1.5% of account NLV (equities) or <= 1.0% fractional Kelly cap (Polymarket/Kalshi). | | `MAX_POSITION_NOTIONAL_EXCEEDED` | Single-position notional <= 20% of gross NLV. | | `DAILY_DRAWDOWN_KILLSWITCH` | Fail-closed halt when intraday drawdown reaches -3.0% NLV (or manual kill-switch engaged). | | `NONCE_ALREADY_SPENT` | Single-use attestation nonce already consumed; replay attack blocked. | | `ATTESTATION_EXPIRED` | Ed25519 attestation exceeded its 120-second TTL. | | `INVALID_SIGNATURE` | Cryptographic Ed25519 signature verification failed or payload was tampered with. | ## 3. Live REST API Examples (`https://clearfills-api.fly.dev`) ### Health & Signing Key Discovery ```bash curl -s https://clearfills-api.fly.dev/api/v1/health ``` ### Evaluate a Trade Proposal ```bash curl -s -X POST https://clearfills-api.fly.dev/api/v1/firewall/propose \ -H "Content-Type: application/json" \ -d '{ "proposal": { "agent_id": "claude-desk", "venue": "ibkr", "symbol": "NVDA", "side": "BUY", "order_type": "LMT", "quantity": 50, "limit_price": 135.0, "stop_loss_price": 129.0, "thesis": "Post-earnings support retest with bounded 0.30% NLV risk" } }' ``` ### Verify Single-Use Attestation (Replay Protection Check) ```bash curl -s -X POST https://clearfills-api.fly.dev/api/v1/firewall/dispatch-check \ -H "Content-Type: application/json" \ -d '{"attestation": { ... }}' ``` Calling `dispatch-check` a second time with the same attestation returns `NONCE_ALREADY_SPENT`. ### Audit Ledger, Arena & Strategy Receipts - `GET https://clearfills-api.fly.dev/api/v1/firewall/audit` — SHA-256 hash-chained ledger (`prev_hash -> entry_hash`). - `GET https://clearfills-api.fly.dev/api/v1/arena` — Signed Frontier AI Trading Arena leaderboard. - `GET https://clearfills-api.fly.dev/api/v1/receipts` — Empirical Strategy Receipts and SEC EDGAR audits. ## 4. Upstream Agent Shims (`TradingAgents` & `ai-hedge-fund`) Wrap existing open-source multi-agent trading repos without rewriting their research pipelines: - `clearfills_firewall.shims.TradingAgentsShim` — Intercepts `TauricResearch/TradingAgents` execution decisions, converts them to canonical `TradeProposal` JSON, and requires a valid Ed25519 attestation before dispatch. - `clearfills_firewall.shims.AIHedgeFundShim` — Intercepts `virattt/ai-hedge-fund` portfolio manager outputs and enforces deterministic sizing, stop-loss, and kill-switch invariants. ## 5. MCP Server Configuration ### Claude Code ```bash claude mcp add clearfills -- uvx --from clearfills-firewall clearfills-firewall-mcp ``` ### Cursor (`.cursor/mcp.json`) / `.mcp.json` ```json { "mcpServers": { "clearfills": { "command": "uvx", "args": ["--from", "clearfills-firewall", "clearfills-firewall-mcp"] } } } ``` ## 6. Frequently Asked Questions **Q: How do I stop an AI trading agent from blowing up my brokerage account?** A: Never give an LLM direct brokerage API keys. Place ClearFills between your agent and your broker so every trade intent is validated by deterministic math rules (limit-only, hard stop required, <=1.5% NLV risk, -3% daily kill-switch) and signed with a single-use 120s Ed25519 attestation before the air-gapped gateway submits it. **Q: Does ClearFills work with `TradingAgents`, `ai-hedge-fund`, Claude, or Grok?** A: Yes. ClearFills ships drop-in shims for `TradingAgents` and `ai-hedge-fund`, plus an MCP stdio server and FastAPI HTTP API for Claude, Grok, Codex, and custom Python agents. **Q: Which trading venues are supported?** A: Paper Simulator (Apache-2.0 Open Core), plus Interactive Brokers (IBKR via headless Fly.io + Tailscale + IBC Gateway), Alpaca, Polymarket CLOB, and Kalshi (Pro Infrastructure Kit). **Q: Does ClearFills provide investment advice or hold customer funds?** A: No. ClearFills is strictly risk engineering, verification, and self-hosted execution software (BYO-broker, BYO-data).