Best execution API
Merged order books across perps venues, and the cheapest split of an order across them after fees.
What it does
The API merges one asset's order books from several perps venues into one book, and works out the cheapest way to fill an order across those venues after each venue's taker fee. It answers with one child order a venue. Your client signs those orders with its own keys; the API can pass the signed orders on to the venues. It never holds keys, secrets or funds.
Base URL https://exec.at.market Reference https://exec.at.market/v1/openapi.json
Keys and limits
Every /v1 route except /v1/health and /v1/openapi.json takes an API key. A WebSocket client that cannot set headers passes ?key= on /v1/stream.
Authorization: Bearer bx_...
Each key has a limit in requests a minute. Every answer carries x-ratelimit-limit and x-ratelimit-remaining; over the limit the answer is 429 with the code rate_limited. Requests are counted against the key by UTC day and route, and so are stream minutes.
Numbers and freshness
- Prices, sizes, fees and amounts are exact decimals written as JSON strings, such as
"60431.5". Send them as strings too. - Merged books and routes are in the asset's units: price per unit of the asset, size in units of it. A child order is in its venue's units:
sizein contracts,limit_pricein the venue's price.asset_sizegives the child in units of the asset. - Quote assets that are US dollar stablecoins count as one dollar.
- Fees are each venue's base taker rate, listed by
GET /v1/venueswith their source. Pass your own rates withfees, in bps by venue id. - A venue's
age_msis the time since its market socket last said anything. A venue older thanmax_age_ms(10,000 by default, at most 60,000) isstaleand left out. The first request for an asset waits up to 3 seconds for the first books.
A quote
curl -s https://exec.at.market/v1/quote \
-H "Authorization: Bearer $KEY" \
-d '{"asset":"BTC","side":"buy","size":"5"}'routeis the fill across venues, withchildren: one order a venue market.average_priceandall_in_priceare per unit before and after fees;slippage_bpsandcost_bpscompare them with the mid.single_venueis the same order on the best single venue, andsavingwhat the route saves against it, in dollars and bps.savingisnullunless both fill the whole order.complete: falsewithunfilledmeans the order is larger than all visible depth. It is not an error.- Every level of every fresh venue on the side the order takes is ranked by its price after the venue's taker fee and taken best first. What is taken on a venue is cut to its size step. A venue whose share would be under its minimum order is left out and the route is worked out again.
Orders
The API prepares the order each venue expects and checks what you signed. Signing is always yours.
- Get a quote and take
route.children. - For each venue in the children,
POST /v1/orders/preparewithvenue,orders(its children),slippage_bps(room added to each limit against you, 0 to 500) andaccount(the fieldsGET /v1/venueslists asorder_account). - Sign what comes back, as
signingsays.eip712_l1_action: signtyped_datawith the account's agent key or wallet, or signdigest.eip712_agent_message: sign each call'styped_datawith the agent named assigner.api_key_transaction: sign eachtx_hashwith the account's API key and put the base64 signature intx_info'sSig. POST /v1/orderswith thesubmitobject filled in. The API checks the signature, posts the order to the venue once and answers with the venue's own reply. It never retries.
Each child goes as an immediate-or-cancel order at its worst price. A venue that cannot work this way answers 501 with venue_not_supported.
The stream
wss://exec.at.market/v1/stream?asset=BTC&depth=20&key=bx_...&fills=<venue>:<account>
- Every 500 ms:
{"type":"book","at_ms":...,"book":{...}}, the merged book asGET /v1/booksanswers it. - With
fills:{"type":"fills","venue":...,"account":...,"snapshot":...,"fills":[...]}as the venue publishes the account's trades. Up to 5 accounts, each an address or an account index asfills_accountinGET /v1/venuessays. - Send
pingto get{"type":"pong"}. A stream closes after 60 minutes; open a new one.
Errors
Every error is {"error":{"code":...,"message":...}}. The codes do not change.
| Code | Status | When |
|---|---|---|
bad_request | 400 | A field is missing or malformed |
bad_signature | 400 | A submitted order's signature does not check |
unauthorized | 401 | No key, or not a key this service made |
key_revoked | 403 | The key was revoked |
not_found | 404 | No such route |
unknown_asset | 404 | No covered venue trades the asset |
method_not_allowed | 405 | The route takes another method |
upgrade_required | 426 | /v1/stream opened without a WebSocket |
rate_limited | 429 | Over the key's limit a minute |
venue_not_supported | 501 | The venue takes no orders or fills through this API |
no_fresh_books | 503 | No venue has a fresh book on that side |
upstream_unavailable | 503 | A venue or a part of the service did not answer |
internal | 500 | Anything else |
Routes
/v1/venues/v1/markets/v1/books/{asset}Merged order book
| Parameter | In | Type | What |
|---|---|---|---|
asset required | path | string | |
depth | query | integer | |
group | query | decimal string | Bucket prices to this step: bids down, asks up. |
max_age_ms | query | integer | A venue whose book is older than this is left out, ms. |
venues | query | string | Only these venues, comma-separated venue ids. |
Answers: 200 Book, 400 Error, 401 Error, 403 Error, 404 Error, 429 Error, 503 Error
/v1/quoteBest execution route
| Parameter | In | Type | What |
|---|---|---|---|
asset required | query | string | |
side required | query | string | |
size | query | decimal string | Units of the asset. |
notional | query | decimal string | Dollars. |
fees | query | string | venue:bps pairs, comma-separated. |
max_age_ms | query | integer | A venue whose book is older than this is left out, ms. |
venues | query | string | Only these venues, comma-separated venue ids. |
Answers: 200 Quote, 400 Error, 401 Error, 403 Error, 404 Error, 429 Error, 503 Error
/v1/quote/v1/orders/prepare/v1/ordersPass a signed order to its venue
Checks the signature (it must recover to the signer the order names, where the venue uses one) and posts the order to the venue once. Never retried.
Body: SubmitRequest
Answers: 200 SubmitResult, 400 Error, 401 Error, 403 Error, 429 Error, 501 Error, 503 Error
/v1/streamWebSocket: merged book and fills
Open as a WebSocket (wss://exec.at.market/v1/stream?asset=BTC&key=...). Every 500 ms: {"type":"book","at_ms":...,"book":Book}. With fills=venue:account,...: {"type":"fills","venue","account","snapshot","fills":[...]} as the venue publishes them. Send "ping" for {"type":"pong"}. A stream closes after 60 minutes; open a new one. Each stream minute is counted against the key.
| Parameter | In | Type | What |
|---|---|---|---|
asset required | query | string | |
depth | query | integer | |
fills | query | string | Up to 5 venue:account pairs. An account is an address or an account index, as GET /v1/venues lists in fills_account. |
key | query | string | The API key, for clients that cannot set headers on a WebSocket. It is not logged. |
Answers: 101, 400 Error, 401 Error, 403 Error, 426 Error, 429 Error, 501 Error, 503 Error
/v1/healthService health
No key needed.
Answers: 200 object
/v1/openapi.jsonThis document
No key needed.
Answers: 200 object
Schemas
Book
| Field | Type | What |
|---|---|---|
asks | MergedLevel list | Lowest first. |
asset | string | |
best_ask | Top | |
best_bid | Top | |
bids | MergedLevel list | Highest first. |
crossed | boolean | One venue's best bid is at or over another's best ask. |
mid | decimal string or null | |
spread | decimal string or null | |
spread_bps | decimal string or null | |
venues | VenueState list |
Child One order to send to one venue market.
| Field | Type | What |
|---|---|---|
asset_size | decimal string | The size in units of the asset. |
average_price | decimal string | The expected average, in the venue's price. |
fee | decimal string | The fee in dollars. |
fee_bps | decimal string | Taker fee used, bps. |
instrument | string | |
levels | integer | |
limit_price | decimal string | The worst level taken, in the venue's price: an immediate-or-cancel limit here takes exactly these levels if the book has not moved. |
market | string | |
notional | decimal string | Dollars filled, before the fee. |
quote | string | |
side | string | |
size | decimal string | In the venue's contracts, on its size step. |
venue | string | |
venue_name | string |
ChildOrder
| Field | Type | What |
|---|---|---|
limit_price | decimal string | Venue price. |
market | string | |
side | string | |
size | decimal string | Venue contracts. |
Error
| Field | Type | What |
|---|---|---|
error | object |
Fill
| Field | Type | What |
|---|---|---|
all_in_price | decimal string or null | |
average_price | decimal string or null | |
children | Child list | |
complete | boolean | The whole amount filled, to within one size step. False when the order is larger than all visible depth. |
cost_bps | decimal string or null | |
fees | decimal string | Dollars. |
filled | decimal string | Units of the asset filled. |
notional | decimal string | Dollars filled before fees. |
slippage_bps | decimal string or null | |
total | decimal string | A buy pays this in all; a sell receives it. |
unfilled | decimal string | What is left, in the order's unit. |
MergedLevel
| Field | Type | What |
|---|---|---|
price | decimal string | Price per unit |
size | decimal string | Every venue's size at the price |
venues | object list |
PrepareRequest
| Field | Type | What |
|---|---|---|
account | object | The fields GET /v1/venues lists as order_account for the venue: vault_address (optional) for eip712_l1_action; user and signer (the agent that signs) for eip712_agent_message; account_index, api_key_index and nonce (optional, read from the venue when left out) for api_key_transaction. |
orders | ChildOrder list | A quote's route.children for this venue. |
slippage_bps | decimal string | Room added to each limit against the trader, 0 to 500. |
venue | string |
Quote
| Field | Type | What |
|---|---|---|
asset | string | |
mid | decimal string or null | |
order | object | |
route | Fill | |
saving | object or null | Null unless the route and the single venue both fill the whole order. |
single_venue | object or null | The order on the best single venue. Null when only one venue is fresh. |
venues | VenueState list |
QuoteRequest
| Field | Type | What |
|---|---|---|
asset | string | |
fees | object | Your own taker fee per venue, bps, in place of the base rate. |
max_age_ms | integer | |
notional | decimal string | Dollars of fills before fees. Give size or notional. |
side | string | |
size | decimal string | Units of the asset. Give size or notional. |
venues | string list |
Rules The venue's price grid, size step and minimums for the market, in the venue's own units.
| Field | Type | What |
|---|---|---|
close_only | boolean | |
isolated_only | boolean | |
max_leverage | integer or null | |
min_notional | object | {"quote":{"min":"10"}} or "none". |
min_size | decimal string or null | |
price | object | {"tick":{"tick":"0.1"}} or {"sig_figs":{"sig":5,"max_dp":1}}. |
size_step | decimal string | Sizes are whole multiples of this. |
SubmitRequest eip712_l1_action: action (the prepared text, unchanged), nonce, vault_address, signature (0x, r, s, v). eip712_agent_message: msg (unchanged), signature. api_key_transaction: tx_type, tx_info (with its Sig).
| Field | Type | What |
|---|---|---|
action | string | |
msg | string | |
nonce | integer | |
signature | string | |
tx_info | string | |
tx_type | integer | |
vault_address | string or null | |
venue | string |
SubmitResult
| Field | Type | What |
|---|---|---|
answer | any | The venue's reply as it came. |
signer | string or null | The address the signature recovers to. |
status | integer | The venue's HTTP status. |
venue | string |
Top
| Field | Type | What |
|---|---|---|
price | decimal string | Price |
size | decimal string | That venue's size there |
venue | string | |
venue_name | string |
Venue
| Field | Type | What |
|---|---|---|
book | VenueState or null | With ?asset=, its book for the asset. |
collateral | string list | |
fee_source | string | |
fee_tier | string | |
fills | boolean | The stream can follow an account's fills on it. |
fills_account | string or null | |
listing | object | |
maker_bps | decimal string | Base maker fee, bps. |
markets | integer | Assets it trades that can be routed. |
name | string | |
order_account | string list | The account fields a prepare takes; ? marks an optional one. |
orders | boolean | POST /v1/orders/prepare and POST /v1/orders work for it. |
signing | string or null | |
taker_bps | decimal string | Base taker fee, bps. |
venue | string | |
website | string or null |
VenueState A venue's market for the asset and how its book stands. Prices are per unit of the asset, sizes in units of it.
| Field | Type | What |
|---|---|---|
age_ms | integer or null | Since the venue's socket last said anything. |
ask_size | decimal string or null | |
best_ask | decimal string or null | |
best_bid | decimal string or null | |
bid_size | decimal string or null | |
instrument | string | venue:perp:market |
market | string | The venue's own name for the market: what an order there names. |
multiplier | decimal string | Units of the asset a contract. |
quote | string | |
state | string | |
taker_bps | decimal string | The taker fee used, bps. |
venue | string | |
venue_name | string |