Polymarket is the largest prediction market, running on Polygon. Horizon supports the CLOB (Central Limit Order Book) API with EIP-712 signed orders.Documentation Index
Fetch the complete documentation index at: https://mathematicalcompany.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Quick Setup
Credentials
There are three ways to provide credentials:- Private key only
- Full credentials
- Environment variables
When only You can also call the derivation manually before
private_key is set, Horizon automatically derives API credentials from the CLOB /auth/derive-api-key endpoint on startup (requires eth-account package):hz.run():This requires
pip install eth-account. The automatic derivation only happens in live mode. Call derive_api_credentials() manually if you need the credentials earlier.Polymarket Configuration
| Field | Default | Description |
|---|---|---|
private_key | None | Ethereum private key for EIP-712 signing |
clob_url | https://clob.polymarket.com | CLOB API base URL |
gamma_url | https://gamma-api.polymarket.com | Gamma API for market metadata |
api_key | None | CLOB API key |
api_secret | None | CLOB API secret (base64-encoded, used as HMAC-SHA256 key) |
api_passphrase | None | CLOB API passphrase |
funder | None | Gnosis Safe or proxy wallet address that holds funds (required for signature_type > 0) |
signature_type | 0 | Signing mode: 0 = EOA, 1 = Polymarket Proxy, 2 = Gnosis Safe |
EIP-712 Signing
Polymarket orders require EIP-712 typed data signatures for the CTF Exchange contract on Polygon (chainId 137). Horizon handles this entirely in Rust usingk256 (secp256k1). No Python crypto dependencies needed.
The signing flow:
- Build
CtfOrderstruct (token_id, maker address, price, size, nonce, etc.) - Generate a cryptographically random salt (UUID v4)
- Compute EIP-712 struct hash and domain separator
- Sign the digest with the private key (ECDSA on secp256k1)
- Submit the signed order to the CLOB API
Gnosis Safe / Contract Wallet Support
If you connected to Polymarket via MetaMask or WalletConnect through the web interface, your account likely uses a Gnosis Safe proxy wallet. In this setup, your EOA (the private key you control) is an owner of a Safe contract that actually holds your USDC and conditional tokens. To trade with this configuration, setsignature_type=2 and provide the Safe address as funder:
How It Works
| Field | EOA (type 0) | Gnosis Safe (type 2) |
|---|---|---|
maker (EIP-712) | EOA address | Safe address (funder) |
signer (EIP-712) | EOA address | EOA address |
signatureType | 0 | 2 |
| Funds held by | EOA directly | Safe contract |
| ECDSA signer | EOA private key | Same EOA private key |
getSafeAddress(signer) == maker using CREATE2, confirming the EOA is an owner of the Safe.
Supported Signature Types
| Type | Name | Description |
|---|---|---|
0 | EOA | Direct wallet signing (default). Maker and signer are the same address. |
1 | POLY_PROXY | Polymarket Proxy wallet. For accounts created via Polymarket’s proxy system. |
2 | POLY_GNOSIS_SAFE | Gnosis Safe wallet. For accounts connected via MetaMask/WalletConnect. |
Finding Your Safe Address
Your Gnosis Safe address is the address shown on polymarket.com under your profile. It is distinct from the EOA address that appears in MetaMask. You can also find it in the Polymarket account settings or on PolygonScan by looking at the Safe deployment transaction from your EOA.Order Types & Time-in-Force
Polymarket supports four time-in-force modes for limit orders, plus market orders:| Order Type | TimeInForce | Behavior |
|---|---|---|
| Limit | GTC | Good-til-Canceled. Rests on the book until filled or canceled. |
| Limit | GTD | Good-til-Date. Expires at a specified time. |
| Limit | FOK | Fill-or-Kill. Must fill entirely in one match or is rejected. |
| Limit | FAK | Fill-and-Kill (Immediate-or-Cancel). Fills what it can, cancels the rest. |
| Market | (auto) | Uses FOK semantics. Executes immediately at best available price or fails. |
Order Management
Submit Orders
Orders are submitted through the pipeline viahz.Quote objects, or directly via the engine:
Cancel Orders
In the pipeline loop,
hz.run() automatically calls cancel_market() before submitting new quotes each cycle (cancel-before-requote pattern). You typically don’t need to cancel manually.Amend Orders
Token ID Routing
Polymarket uses numeric token IDs (not market slugs) to identify outcomes. Each market has a Yes token and a No token:Market Resolution
Whenmode="live", Horizon queries the Gamma API to resolve market metadata:
yes_token_id/no_token_id(from thetokensarray orclobTokenIdsfield)condition_idneg_riskexchange = "polymarket"
RuntimeError is raised to prevent trading with an invalid market.
Position Reconciliation
Horizon can fetch your current Polymarket positions for reconciliation:Position objects with:
market_id(the asset/token ID)side(Yes or No, parsed from theoutcomefield)sizeandavg_entry_priceexchange = "polymarket"
Fill Polling
Polymarket fills arrive via polling the/trades endpoint. Each cycle, drain_fills() calls poll_fills_async() which:
- Queries recent trades for tracked order IDs
- Deduplicates against previously seen fill IDs (FIFO eviction, capped at 10k)
- Returns new fills with exchange-assigned timestamps
Order Scoring & Rewards
Polymarket pays USDC liquidity rewards to qualifying market makers. You can check if a live order qualifies:GET /order-scoring?order_id=... endpoint. Returns False for non-Polymarket exchanges.
For full rewards tracking (eligible markets, rebate estimation, pipeline integration), see the Rewards Tracker documentation.
HMAC-SHA256 Authentication
API requests are authenticated with HMAC-SHA256:- The
api_secretis base64-decoded and used as the HMAC-SHA256 key - Each request includes headers:
POLY_TIMESTAMP,POLY_API_KEY,POLY_SIGNATURE, andPOLY_PASSPHRASE - The signature covers the timestamp, HTTP method, request path, and body
POLY_SIGNATURE header.