Skip to main content
v0.1Sports and event markets in preview

Trade prediction markets from code.

One API for canonical sports and event markets, quotes and orders. Name the outcome you want; Lean finds the venue across Kalshi, Polymarket, Polymarket US and Hyperliquid, prices the route and places the order.

REST and WebSocketOne JSON envelope
Idempotent ordersRetry without doubling
OpenAPI 3Generate any client

One call to buy

With a test key, nothing real moves:
Polymarket takes ioc buys by dollar amount only. On a market only Polymarket lists, send "notional": "25" in place of quantity; see Limitations. The response is the order. If the book was on Polymarket and the account’s cash on Hyperliquid, or the other way round, Lean moved the cash and bought on the venue with the book, and route says so; otherwise route is null:
Read it back by id:
See Orders and idempotency for every field.

From a new key to a reconciled trade in five calls

Every step is a plain HTTPS request with a bearer key.
  1. 01

    Create a key

    Start with a test key that simulates fills. Each key has its own per order and daily limit.

    Authentication
  2. 02

    Find a market

    List canonical sports and event markets. You name the outcome; Lean knows the venues.

    GET/v1/markets
  3. 03

    Place the order

    One limit order with your own ID, on any venue and safe to retry on a dropped connection.

    POST/v1/orders
  4. 04

    Read it back

    Read the order by its ID to see its status and fills.

    GET/v1/orders/
  5. 05

    Reconcile

    Read positions and balances back until the books agree.

    GET/v1/positions

Designed for programs that move money

Preview before you trade

POST /v1/orders/preview takes the exact order body and returns the venue, route plan and refusals, with a read only key.

Retries are safe

Every order carries your client_order_id. Sending it again returns the original order, never a second order.

Limits live on the key

Each key has its own per order and rolling daily notional limit, checked before anything reaches a venue.

One shape everywhere

{ success, data, meta } on success and a stable error code on failure, with a request ID to quote when you report a problem.

Conventions

  • Every response uses one envelope: { "success": true, "data": …, "meta": … } or { "success": false, "error": { "code", "message", "details" }, "meta": … }.
  • meta.requestId (also sent as the X-Request-ID header) identifies the request. Include it when you report a problem.
  • Prices are decimal strings in dollars per share, strictly between 0 and 1.
  • Quantities are shares, as decimal strings. Amounts are USD, as decimal strings.
  • The number of decimal places can differ between endpoints and venues for the same field, so "4", "4.00" and "4.000000" are the same quantity. Parse decimal strings as numbers before you compare them.
  • Times are ISO 8601 strings, at up to microsecond precision, so parse them rather than compare the text.
  • Field names are snake_case.
  • data.livemode in every successful response is false for a test key and true for a live key. See Test mode and live mode.

What the API covers

How it works

  • Each sports market names the part of the game it covers in group.period. game is the full game, overtime included.
  • Lean chooses the venues. A buy is split across eligible venues by best price; a sell takes the best bids across the venues that hold the shares.
  • Event markets, such as elections and central bank decisions, list on one venue, Polymarket or Hyperliquid, and trade through the same order API on that venue. Smart order routing across venues is for sports markets.
  • Between Polymarket and Hyperliquid, a buy can pay with cash on the other venue: Lean moves it and buys on the venue with the book, in the same call. Kalshi and Polymarket US orders pay with the cash already on that venue. Shares can’t move between venues.
  • Live orders route to Kalshi, Polymarket, Polymarket US and Hyperliquid. Orders on Lighter crypto markets also run live. Test orders are simulated and never reach a venue.
  • Kalshi and Polymarket US are user wide accounts: every trading account of a user shares the same Kalshi and Polymarket US balances and positions, and live orders there use the venue API key the user connected in the Lean app.
  • Deposits, withdrawals and routed orders cover Polymarket and Hyperliquid only. Live transfers also reach Lighter.
  • Quotes price buys, and sells of shares the account holds.
  • Hyperliquid does not cancel resting orders at kickoff. Send gtd with expires_at game_start and Lean cancels them for you. See Orders.