Best execution API

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

A quote

curl -s https://exec.at.market/v1/quote \
  -H "Authorization: Bearer $KEY" \
  -d '{"asset":"BTC","side":"buy","size":"5"}'

Orders

The API prepares the order each venue expects and checks what you signed. Signing is always yours.

  1. Get a quote and take route.children.
  2. For each venue in the children, POST /v1/orders/prepare with venue, orders (its children), slippage_bps (room added to each limit against you, 0 to 500) and account (the fields GET /v1/venues lists as order_account).
  3. Sign what comes back, as signing says. eip712_l1_action: sign typed_data with the account's agent key or wallet, or sign digest. eip712_agent_message: sign each call's typed_data with the agent named as signer. api_key_transaction: sign each tx_hash with the account's API key and put the base64 signature in tx_info's Sig.
  4. POST /v1/orders with the submit object 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>

Errors

Every error is {"error":{"code":...,"message":...}}. The codes do not change.

CodeStatusWhen
bad_request400A field is missing or malformed
bad_signature400A submitted order's signature does not check
unauthorized401No key, or not a key this service made
key_revoked403The key was revoked
not_found404No such route
unknown_asset404No covered venue trades the asset
method_not_allowed405The route takes another method
upgrade_required426/v1/stream opened without a WebSocket
rate_limited429Over the key's limit a minute
venue_not_supported501The venue takes no orders or fills through this API
no_fresh_books503No venue has a fresh book on that side
upstream_unavailable503A venue or a part of the service did not answer
internal500Anything else

Routes

GET/v1/venues

Covered venues, their fees and freshness

ParameterInTypeWhat
assetquerystringAdds each venue's book state for this asset.

Answers: 200 object, 400 Error, 401 Error, 403 Error, 429 Error, 503 Error

GET/v1/markets

Assets and venue markets

Without asset: every asset with the venues that trade it. With asset: that asset's market on each venue, with its rules.

ParameterInTypeWhat
assetquerystring

Answers: 200 object, 400 Error, 401 Error, 403 Error, 404 Error, 429 Error, 503 Error

GET/v1/books/{asset}

Merged order book

ParameterInTypeWhat
asset requiredpathstring
depthqueryinteger
groupquerydecimal stringBucket prices to this step: bids down, asks up.
max_age_msqueryintegerA venue whose book is older than this is left out, ms.
venuesquerystringOnly these venues, comma-separated venue ids.

Answers: 200 Book, 400 Error, 401 Error, 403 Error, 404 Error, 429 Error, 503 Error

GET/v1/quote

Best execution route

ParameterInTypeWhat
asset requiredquerystring
side requiredquerystring
sizequerydecimal stringUnits of the asset.
notionalquerydecimal stringDollars.
feesquerystringvenue:bps pairs, comma-separated.
max_age_msqueryintegerA venue whose book is older than this is left out, ms.
venuesquerystringOnly these venues, comma-separated venue ids.

Answers: 200 Quote, 400 Error, 401 Error, 403 Error, 404 Error, 429 Error, 503 Error

POST/v1/quote

Best execution route (JSON body)

Body: QuoteRequest

Answers: 200 Quote, 400 Error, 401 Error, 403 Error, 404 Error, 429 Error, 503 Error

POST/v1/orders/prepare

Unsigned venue orders for a route's children

Answers each venue's own order before it is signed. Your client signs it with its own key and sends it to POST /v1/orders. The service holds no keys.

Body: PrepareRequest

Answers: 200 object, 400 Error, 401 Error, 403 Error, 429 Error, 501 Error, 503 Error

POST/v1/orders

Pass 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

GET/v1/stream

WebSocket: 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.

ParameterInTypeWhat
asset requiredquerystring
depthqueryinteger
fillsquerystringUp to 5 venue:account pairs. An account is an address or an account index, as GET /v1/venues lists in fills_account.
keyquerystringThe 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

GET/v1/health

Service health

No key needed.

Answers: 200 object

GET/v1/openapi.json

This document

No key needed.

Answers: 200 object

Schemas

Book
FieldTypeWhat
asksMergedLevel listLowest first.
assetstring
best_askTop
best_bidTop
bidsMergedLevel listHighest first.
crossedbooleanOne venue's best bid is at or over another's best ask.
middecimal string or null
spreaddecimal string or null
spread_bpsdecimal string or null
venuesVenueState list
Child One order to send to one venue market.
FieldTypeWhat
asset_sizedecimal stringThe size in units of the asset.
average_pricedecimal stringThe expected average, in the venue's price.
feedecimal stringThe fee in dollars.
fee_bpsdecimal stringTaker fee used, bps.
instrumentstring
levelsinteger
limit_pricedecimal stringThe worst level taken, in the venue's price: an immediate-or-cancel limit here takes exactly these levels if the book has not moved.
marketstring
notionaldecimal stringDollars filled, before the fee.
quotestring
sidestring
sizedecimal stringIn the venue's contracts, on its size step.
venuestring
venue_namestring
ChildOrder
FieldTypeWhat
limit_pricedecimal stringVenue price.
marketstring
sidestring
sizedecimal stringVenue contracts.
Error
FieldTypeWhat
errorobject
Fill
FieldTypeWhat
all_in_pricedecimal string or null
average_pricedecimal string or null
childrenChild list
completebooleanThe whole amount filled, to within one size step. False when the order is larger than all visible depth.
cost_bpsdecimal string or null
feesdecimal stringDollars.
filleddecimal stringUnits of the asset filled.
notionaldecimal stringDollars filled before fees.
slippage_bpsdecimal string or null
totaldecimal stringA buy pays this in all; a sell receives it.
unfilleddecimal stringWhat is left, in the order's unit.
MergedLevel
FieldTypeWhat
pricedecimal stringPrice per unit
sizedecimal stringEvery venue's size at the price
venuesobject list
PrepareRequest
FieldTypeWhat
accountobjectThe 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.
ordersChildOrder listA quote's route.children for this venue.
slippage_bpsdecimal stringRoom added to each limit against the trader, 0 to 500.
venuestring
Quote
FieldTypeWhat
assetstring
middecimal string or null
orderobject
routeFill
savingobject or nullNull unless the route and the single venue both fill the whole order.
single_venueobject or nullThe order on the best single venue. Null when only one venue is fresh.
venuesVenueState list
QuoteRequest
FieldTypeWhat
assetstring
feesobjectYour own taker fee per venue, bps, in place of the base rate.
max_age_msinteger
notionaldecimal stringDollars of fills before fees. Give size or notional.
sidestring
sizedecimal stringUnits of the asset. Give size or notional.
venuesstring list
Rules The venue's price grid, size step and minimums for the market, in the venue's own units.
FieldTypeWhat
close_onlyboolean
isolated_onlyboolean
max_leverageinteger or null
min_notionalobject{"quote":{"min":"10"}} or "none".
min_sizedecimal string or null
priceobject{"tick":{"tick":"0.1"}} or {"sig_figs":{"sig":5,"max_dp":1}}.
size_stepdecimal stringSizes 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).
FieldTypeWhat
actionstring
msgstring
nonceinteger
signaturestring
tx_infostring
tx_typeinteger
vault_addressstring or null
venuestring
SubmitResult
FieldTypeWhat
answeranyThe venue's reply as it came.
signerstring or nullThe address the signature recovers to.
statusintegerThe venue's HTTP status.
venuestring
Top
FieldTypeWhat
pricedecimal stringPrice
sizedecimal stringThat venue's size there
venuestring
venue_namestring
Venue
FieldTypeWhat
bookVenueState or nullWith ?asset=, its book for the asset.
collateralstring list
fee_sourcestring
fee_tierstring
fillsbooleanThe stream can follow an account's fills on it.
fills_accountstring or null
listingobject
maker_bpsdecimal stringBase maker fee, bps.
marketsintegerAssets it trades that can be routed.
namestring
order_accountstring listThe account fields a prepare takes; ? marks an optional one.
ordersbooleanPOST /v1/orders/prepare and POST /v1/orders work for it.
signingstring or null
taker_bpsdecimal stringBase taker fee, bps.
venuestring
websitestring 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.
FieldTypeWhat
age_msinteger or nullSince the venue's socket last said anything.
ask_sizedecimal string or null
best_askdecimal string or null
best_biddecimal string or null
bid_sizedecimal string or null
instrumentstringvenue:perp:market
marketstringThe venue's own name for the market: what an order there names.
multiplierdecimal stringUnits of the asset a contract.
quotestring
statestring
taker_bpsdecimal stringThe taker fee used, bps.
venuestring
venue_namestring