Trading
Orders.
Every order type, how the engine fills it, time in force, sizes and prices, and how to never place an order twice.
On this page
An order is one POST to /v1/accounts/{account_id}/orders. This page explains what each field does and, just as important, exactly how the engine fills what you send. A bot that knows the fill rules never gets surprised by them.
Order types#
type | What it does | How it fills |
|---|---|---|
market | Trades now | The whole size at the ask (buy) or the bid (sell) |
limit | Waits for a better price | At your limit, once the last price trades strictly through it |
stop_market | Waits for the price to break a level, then trades | At the ask plus one tick (buy) or the bid minus one tick (sell) once the last price reaches the stop |
stop_limit | Like a stop, but never worse than your limit | At the last price, once it is at or through the stop and strictly better than the limit |
take_market | Takes profit at a level, then trades | Like stop_market, on the profit side |
take_limit | Takes profit at a level, never worse than your limit | Like stop_limit, on the profit side |
You place the first four through the API. The two take_ types are orders placed from a trading platform: you see them in your order lists, and for your own take profits the API uses exits.
Two facts shape everything else:
- Fills are whole. An order fills completely or not at all. There are no partial fills, so
filled_sizeis0or the full size. - A limit already through the market fills at once, at the ask or bid, which can be worse than your limit if the limit sits inside the spread. The API refuses that case with
limit_inside_spreadinstead, so you never pay more than you meant to. Sendpost_only: trueto be refused whenever an order would fill at once. Both hold when you change a limit's price later (PATCH): a post-only order stays post-only.
Sizes and prices#
Sizes are in the base asset (BTC for BTC-USD) and must be a multiple of the market's size_step. Prices must be a multiple of its tick_size. Both are in GET /v1/markets. A size off the step is refused with invalid_size_step, and the error's details.nearest gives the valid sizes around yours (a price off the tick, invalid_price_tick, the same).
An order must also be worth at least the market's min_notional ($10); a smaller one is refused with order_too_small, its details.smallest_notional_usd saying the smallest order value the market takes now (one size step at least, so more on markets with a coarse step). Send notional_usd instead of size to size in dollars: the API rounds down to the step.
An order is checked against the market's last price: changed within 10 seconds, or, on a quiet market, unchanged within 120 seconds while other markets move. Without such a price it is refused with stale_quote (retryable); GET /v1/markets shows such a market as halted (crypto) or closed (FX, metals, indices, outside their hours).
Prices, sizes and money are decimal strings ("62500.00"), never floats, so nothing is lost to rounding.
A market's last is its last trade; bid and ask are the book now. On a quiet market last can sit outside the bid and ask until the next trade: price your orders from the bid and ask, never from last.
Two orders one after the other#
The trading engine takes the orders that open or add to a position on an account at least 600 ms apart (GET /v1/limits says it as orders.open_spacing_ms). Send two at once and the API spaces them for you: the second goes out once the first is answered and the spacing has passed, so an oco, a ladder or two orders in a row are all placed. A request whose wait would be longer than its answer may take is answered 429 rate_limited with details.scope order_spacing and a Retry-After; send it again then. Orders that only reduce (reduce_only, closes, exits) and cancels are never spaced. An engine refusal for the spacing, the orders an hour or the working orders an account may hold comes back as what it is (rate_limited with its Retry-After and details.scope order_spacing or account_orders_hour, or working_order_cap), never a bare order_rejected.
A program that cuts an order into slices (twap, vwap, scaled) checks every slice against the market's minimum, not only the smallest: an order whose slices would be too small is refused with order_too_small and its details.slices, smallest_slice_size and max_slices. A reduce-only program can end on a slice under the minimum when the position left is smaller: that last slice closes it.
Time in force#
| Type | Choices | Default |
|---|---|---|
market | ioc, fok | ioc |
limit | gtc, gtd, ioc, fok | gtc |
| stops and takes | gtc, gtd | gtc |
gtd needs expires_at, in Unix milliseconds. Because fills are whole, fok and ioc behave the same.
Slippage#
A market order never fills worse than its worst price. Set it in percent with max_slippage_pct, or as a price with worst_price. Without either, the market's default applies; GET /v1/markets shows it with its bounds. When the market moved past your worst price, the order is refused with slippage_exceeded and nothing fills.
Protecting a position#
Attach exits to the order itself, and they are placed the moment it fills:
{
"market": "BTC-USD",
"side": "buy",
"type": "market",
"size": "0.010",
"exits": {
"take_profit": [{ "percent": "2" }],
"stop_loss": {
"percent": "1",
"trail": { "distance": "350.00" },
"break_even": { "trigger_percent": "0.5", "offset_ticks": 2 }
}
}
}Each exit is a price, or a distance or percent from the fill. Several take profits split the size evenly (size_pct sets each one's share; the farthest takes what the size step leaves). The exits live on our servers as reduce-only orders: when one fills, the other is canceled, and they shrink if you reduce the position. They keep protecting you if your bot goes offline. Change them later with PUT .../positions/{market}/exits.
Never place an order twice#
Send an Idempotency-Key header with every order: any unique string, like a UUID. If the connection drops and you retry with the same key and the same body, you get the first order back instead of a second one. The key is remembered for 24 hours. The SDKs do this for you. To change an order (PATCH), a key is optional: give one to send the same change again safely.
You can also give the order your own client_order_id and find it later with GET .../orders?client_order_id=, even from another process.
Statuses#
status | Meaning |
|---|---|
pending | Accepted by the API, on its way to the engine |
working | Resting on the engine, waiting for its price |
filled | Done. average_fill_price and fee are set |
canceled | Canceled; cancel_reason says why |
rejected | Refused; reject.code says why |
expired | An ioc, fok or gtd order that ended unfilled |
unconfirmed | The engine's answer was lost on the way. Read the order again in a second: it settles to one of the above |
A market order's answer waits up to two seconds for the fill, so you usually get filled straight away.
When the engine restarts#
If the trading engine restarts, it cancels every working order with cancel_reason: system_restart, and positions it held are closed. The API tells you on the account stream and your webhooks, and places nothing back by itself: your bot decides what to re-place.