Placing and cancelling orders
Send place_order, cancel_order and cancel_all_orders on the same connection you stream on.
Who can trade
Order commands need an API key that belongs to a user and has the write scope. Other connections, including service keys, get ORDERS_NOT_ALLOWED.
The checks, limits and order records are the REST API's: the same order is accepted or refused the same way on both, with one exception, the price collar (below).
The API key rules (see Connecting and authentication) are applied again before every command, so a lock, an access-mode change, an allowlist change, the killswitch or a lost write scope takes effect on the next command.
Command ids and replies
Every command carries an id you choose. It is required and at most 64 bytes; plain ASCII is safest, as other characters take more than one byte. It is only used to match the reply to the command and is not stored.
Each command gets exactly one reply with the same id: order_ack, cancel_ack or cancel_all_ack, or an error. A missing or too long id is answered VALIDATION_FAILED with no id; nothing was run.
The id is not a duplicate check: the same place_order sent twice with the same id places two orders. There is no client order ID or idempotency key.
→ {"type":"place_order","id":"c-1","symbol":"CC/USDCx","side":"buy","quantity":10,"price":0.15}
← {"type":"order_ack","id":"c-1","request_id":51234}
place_order
Field names and rules are those of REST's POST /api/trading/orders.
| Field | Required | Description |
|---|---|---|
type | yes | place_order |
id | yes | Chosen by you, at most 64 bytes; echoed on the reply |
symbol | yes | Trading pair in any case, for example CC/USDCx (cc/usdcx is the same pair). REST matches exactly. |
side | yes | buy or sell |
quantity | yes | Base quantity, above 0, at most 10 decimals (fewer if the pair says so) |
price | yes | Above 0, at most the pair's price decimals. Required for market orders too; see Market orders below. |
order_type | no | limit (default) or market |
order_subtype | no | post_only |
expires_at | no | RFC 3339 date-time; must be in the future |
{"type":"place_order","id":"c-1","symbol":"CC/USDCx","side":"buy","quantity":10,"price":0.15,"order_subtype":"post_only"}An ack means queued, like REST's 201: the order creation request is stored and the matching engine picks it up within about 50 ms.
{"type":"order_ack","id":"c-1","request_id":51234}The order's user_data events carry the same request_id, so match them to the ack by request_id. An order the engine refuses after the ack (for example a post_only order that would cross) arrives as a user_order event with status rejected, a reason, and an empty order_id. It can arrive before or after the order_ack. See User events.
Market orders
price is not a limit on a market order: it fills against the book at the makers' prices, and any unfilled part is cancelled. The price you send is still used in two places:
- Our checks before the order is queued, the same on REST and the WebSocket. The balance check for a market buy is
quantity × pricein the quote asset, and the price must fit the pair's price decimals. A price far above the market can get a market buy refused withINSUFFICIENT_BALANCEeven though the real cost is lower. Send a realistic price, for example the current best ask for a buy. - The matching engine replaces it with the worst price the book needs to fill your quantity, and locks balance and fees on that. The
pricein the order's events is that worst price.
Time in force
There is no IOC, FOK or GTC setting. A limit order rests until it fills, you cancel it, or its expires_at passes. A market order behaves like IOC: what does not fill at once is cancelled.
cancel_order
Send order_id or request_id, not both. request_id works at every stage: before the order is live (before its first user_order event) and after, when it cancels the live order made from that request.
{"type":"cancel_order","id":"c-2","request_id":51234}{"type":"cancel_ack","id":"c-2","order_id":"51234","already_queued":false}| Reply field | Description |
|---|---|
order_id | The live order's ID, or the request_id when the order was not live yet |
already_queued | true when the cancellation was already queued before this command |
A cancel ack means queued too. A live order leaves the book, and the balance it locked is freed, with its user_order_inactive event (status canceled), usually tens of milliseconds after the cancel_ack. To place a replacement that needs that balance, wait for that event, not the ack.
An order cancelled before the engine processed it never goes live and never gets an order_id: its event is a user_order with status cancelled, an empty order_id, and its request_id.
ORDER_NOT_FOUND means the order is not yours, does not exist, or has already left the book (for example filled).
cancel_all_orders
Cancels all your live orders, or only one pair's when you send symbol.
{"type":"cancel_all_orders","id":"c-3","symbol":"CC/USDCx"}{"type":"cancel_all_ack","id":"c-3","canceled_count":2,"already_queued_count":0,"order_ids":["ord_a","ord_b"]}| Reply field | Description |
|---|---|
canceled_count | Orders this command queued for cancellation |
already_queued_count | Orders whose cancellation was already queued, by an earlier command or one running at the same time |
order_ids | Only the orders this command queued (the canceled_count ones), not the already queued ones |
Two cancel-alls sent at once never both count the same order.
Orders that are acked but not live yet are not cancelled by cancel_all_orders: they go live afterwards. To be sure nothing of yours is left, also cancel each order you have placed but not yet seen a user_order event for, with cancel_order and its request_id.
Commands run in parallel
One connection runs up to 16 commands at once, so replies can arrive in a different order from the commands, and two commands sent back to back can be applied in either order. When order matters (for example cancel, then place a replacement), wait for the first command's reply before sending the next.
Each connection queues up to 256 commands beyond the 16 running; past that, and when the server is at capacity, the reply is BUSY.
Commands with no reply
After a timeout or a dropped connection, a command may or may not have been applied. A command the server has received still runs after the connection drops; only its reply is lost.
How long a command can take. A command must start within 5 seconds of reaching the server, or it is answered BUSY and not run, so an order is never placed at a price you sent long ago. Once started, it has at most 10 seconds. So no order can be created from a place_order more than 15 seconds after the server received it. If you wait 20 seconds after sending, to allow for the network, and no order from it has appeared, it was not placed.
Finding the order. Without the order_ack you have no request_id, and there is no client order ID, so look for the order by its details:
- Open orders:
GET /api/trading/orders/active. - Orders that have already left the book (filled or cancelled):
GET /api/trading/orders/past. - Match on
symbol,side,quantity,priceand creation time.
If you do have the request_id, POST /api/trading/orders/by-request with {"request_ids":[51234]} returns the orders made from it, live or inactive. An order that is still queued, or was rejected before it went live, is not returned.
INTERNAL_ERROR on a place_order does not always mean the order was not placed; the message tells you. See Message reference.
Price collar
A limit order may not buy above, or sell below, the oracle price by more than the exchange's order collar (plus a 1% margin of it); the bounds are rounded outwards to the pair's price decimals. It is the matching engine's check, made before the order is queued and refused with PRICE_OUTSIDE_COLLAR; the message gives the bound.
REST does not check it: there the order is accepted and the engine then rejects it with a rejected user_order event. Market orders are not collared, and nor is a pair while it has no oracle price. Like the engine, the server reads the collar, the oracle prices and the pair's price decimals once a minute, so a change takes up to a minute to apply here and in the engine, not necessarily at the same moment.
Order limits
Order limits are the REST API's, with the same per-account overrides:
- Orders per minute: counted per account and trading pair, shared with REST: placing an order on a pair over REST uses the same count as placing one here. If your account has an account-wide limit instead, one count covers all pairs.
GET /api/trading/rate-limitsshows which applies (see Rate limits). Refused withORDER_RATE_LIMIT_EXCEEDED. - Max open orders (open plus acked but not yet live, per order type). Refused with
ORDER_LIMIT_EXCEEDED. - While trading is paused,
place_orderis refused withTRADING_PAUSED; cancels still work.
Cancel limit
cancel_order and cancel_all_orders are limited the way REST limits them: by the API key's requests per second, each command on its own counter. Over it, the reply is RATE_LIMITED with the command's id.
Each key has one count, the same one REST uses: cancels sent over REST and on any of the key's connections share the key's allowance. A second is a clock second, as on REST. Cancels refused here are not counted, so only the excess is refused; REST counts its refused requests too, so a key over its limit on REST has its cancels here refused as well until the next second.
Refused orders
A place_order that is placed counts only against your orders per minute, so you can send your whole budget in a burst. One that is refused (an unknown symbol, a price outside the collar, no balance) is also counted against your requests per second. With as many refusals in the current second as that limit, the next place_order is answered RATE_LIMITED without being run, until the next second. The refusals are counted per API key across all your connections (REST's refusals are not in this count). A client sending valid orders never meets this.
As on REST, a refusal for the price collar (PRICE_OUTSIDE_COLLAR), INSUFFICIENT_BALANCE, INSUFFICIENT_FEE_BALANCE or SELF_CROSS has already been counted against your orders per minute, as has an ORDER_RATE_LIMIT_EXCEEDED refusal. A refusal for the symbol, the size, the decimals, the account or max open orders has not.
A requests-per-second limit of 0 means the credential is switched off: every order command is answered RATE_LIMITED, as every REST request is.
The error codes order commands can get are listed in Message reference.
Updated 3 days ago

