Skip to main content
The Python SDK wraps the gateway so you write trading logic, not HTTP. It handles auth, venue signing, idempotency keys, pagination, retries, and typed Pydantic responses. The only configuration is an API key.

Installation

Quick start

Your exchange credentials never touch the SDK — you attach them once in the dashboard, and Mithril signs orders server-side. The SDK only ever holds your mk_live_ / mk_test_ key.

The client

Every resource hangs off the client: client.subaccounts, client.markets, client.orders, client.complex_orders, client.risk_limits, client.risk, client.positions, client.fills, client.portfolio, client.receipts, client.analytics.

Subaccounts

Subaccounts isolate strategies — each with its own credentials, positions, and risk limits. Most calls take a subaccount_id, so discover it rather than hardcoding.
Attach exchange credentials (write-only — never returned):

Market data

One normalized data plane across venues — prices are probabilities in (0, 1), and one mkt_ id maps the same event on both.
str
required
Free-text search across both venues.
str
Filter to "polymarket" or "kalshi".
str
Filter by market status (e.g. "open").
int
default:"50"
Page size, max 200.

Orders

Place a limit or market order. Mithril risk-checks it, signs it, submits it, and maps the venue’s response to one status model. The idempotency-key is attached automatically, so a retry after a timeout never double-places.
str
Pass your own stable key for end-to-end safe retries across process restarts. Omit it and the SDK generates one per call.
Order statuses: submitted, open, partial, filled, cancelled, rejected. A rejected order carries a reject_reason (often a guardrail).

Smart execution

Thin books punish size. Preview an order’s impact, then let Mithril work it under a slippage cap and hand you a transaction-cost report.
Create a worked order by choosing a type and passing its params. Four strategies:
Watch it work, then read the receipt:
Conditional orders (take-profit / stop-loss / stop) are on the roadmap and are rejected at submission today, so you never get a plan nothing will act on.

Guardrails

Set the limits every order is checked against — server-side, before it reaches the venue.
Fields: max_order_notional, max_position_per_market, max_total_notional, slippage_bps, max_concentration_bps, max_open_orders, max_daily_loss, kill_switch. Notional fields are decimal strings; "0" means unlimited.

Risk & portfolio

One call each for exposure, P&L, fills, positions, and portfolio — per subaccount or across the whole workspace.

Errors

Failed calls raise typed exceptions carrying code, message, and request_id:

Pagination

List endpoints return a Page — a list that also carries .has_more and .next_cursor. Use .iterate() to walk every page automatically:
iterate() is available on markets, orders, positions, and fills.

Responses

Responses are Pydantic models — typed attributes, validation, and unknown fields preserved so a new API field never breaks you:

Runnable examples

Six scripts — one per stack layer — all built on this SDK.