Skip to main content
PlaceOrder · write key · write rate class Places one order: open a position, add to one, close one, or protect one with a take-profit or stop-loss.

Body

Every price, trigger, take-profit and stop-loss must be a multiple of the market’s tickSize from ListMarkets.

Response

The last four are sent for an order that fills during the call, a MARKET or a LIMIT that crosses the book. They carry at most 8 decimal places. ListTrades has the price, quantity, fee and position of each recorded trade, and ListOrderHistory has the fill price once it is recorded on the order. A resting order answers none of them; once it fills, a retry with its clientOrderId answers all four, omitting them until that fill’s trades are recorded.

Retrying safely

After a timeout, a 500 or a lost connection, the order may still have gone through. Retry only with the clientOrderId the first attempt carried: you get the first order back and nothing new is placed.
  • Any RFC 9562 UUID version is accepted, in the 36-character hyphenated form, and will stay accepted, so a version 8 UUID that packs your own id works.
  • The same clientOrderId with a different order answers failed_precondition, except a retry that only asks for a larger quantity, which can still answer the first order, with acceptedQuantity when the stored quantity is smaller than the retry asked for.
  • maxSlippageBps is not compared: a retry answers the first order’s execution whatever cap it carries, so a tighter cap on a retry neither reprices nor refuses a fill that already happened. Repeat the first attempt’s parameters.
  • A clientOrderId that already names an order on another account answers already_exists.

Order types

MARKET

  • Fills against the book. A fill that would move past maxSlippageBps refuses the whole order with failed_precondition before any of it executes.
  • maxSlippageBps is accepted on a MARKET order that opens or adds to a position and on a reduce-only MARKET, and refused on every other type, so an exit that rests or waits for a trigger is never price-capped.
  • In the default one-way position mode, a MARKET order without reduceOnly, takeProfitPrice or stopLossPrice, opposite an open position that is not a pair leg, no larger than it and naming no other positionId, is placed as that position’s reduce-only exit: it fills the visible depth instead of being refused for its size (maxSlippageBps still applies), acceptedQuantity gives the size filled, and it is listed with reduceOnly and the positionId.
  • If the position or the mode cannot be read at that moment, the order is placed as an ordinary opening order instead, and if the position has closed meanwhile it opens one on the other side. For an exit that can never open a position, send reduceOnly: true with the positionId, or call ClosePosition.

LIMIT

  • A LIMIT that crosses the book fills at once, as taker, at the book’s average price.
  • A crossing LIMIT without reduceOnly, even one opposite a position, is refused with failed_precondition when the visible depth is short of its size, or when that average is worse than its limit price by more than a tolerance, 10 basis points today.
  • A LIMIT without reduceOnly is sized at its limit price, however far through the book: quantity × price must fit maxPositionSize, and attached exits must sit on the right side of price, or it answers invalid_argument.
  • A LIMIT priced not to cross usually rests, but the market can move first, so it can still fill as taker. Only postOnly would guarantee a maker order, and PlaceOrder does not accept it.
A reduce-only LIMIT that crosses has no price bound: it fills the visible depth however far past its limit. To cap an exit’s price, send a reduce-only MARKET with maxSlippageBps instead.

Triggered orders

  • STOP_MARKET, TAKE_PROFIT and STOP_LOSS fire when the mark price or the best bid or offer on their executing side reaches triggerPrice, whichever comes first.
  • A triggerPrice that the mark price or that best bid or offer has already reached answers invalid_argument, and the message names the price it had to be beyond. A stop refused this way means its level is already hit, so close at market instead of retrying the stop.
  • A take-profit or stop-loss on an open position is TAKE_PROFIT or STOP_LOSS with its positionId and triggerPrice.
  • Exits attached with takeProfitPrice and stopLossPrice appear only as fields on the opening order until it fills, then become separate TAKE_PROFIT and STOP_LOSS orders with their own ids. Find them in ListOpenOrders by positionId and type.

Markets with a fill cap

On markets whose fills are capped near the mark price, today BRENTOIL, CL, GOLD, SILVER, SP500 and XYZ100, size the book cannot fill within the cap fills at the cap price, so depth neither refuses nor cuts a LIMIT there. While the cap cannot be set, as when the mark price is stale or far from the book, a MARKET or crossing LIMIT without reduceOnly there is refused with failed_precondition and can be retried a moment later; a reduce-only one fills the visible depth, and a triggered STOP_MARKET fills uncapped.

Exits

  • To close or reduce a position, send reduceOnly: true with its positionId, the position’s symbol, the opposite side and the quantity to close. A take-profit or stop-loss names the same symbol and side.
  • A reduce-only MARKET larger than the position is trimmed to it, so it closes the whole position unless book liquidity sizes it down. ClosePosition does the same without a quantity, on the exit budget.
  • Reduce-only LIMITs, take-profits and stop-losses each form their own ladder: one kind together covers at most the position’s size, and the one closest to the market fills first.
  • A new exit closer to the market than one of its kind shrinks or cancels the farther one, with no error. One lying wholly beyond what its ladder covers answers failed_precondition, kind REDUCE_ONLY_NO_CAPACITY. A reduce-only STOP_MARKET never uses ladder capacity.
  • An exit listed with closePosition, as the one an entry attaches with stopLossPrice or takeProfitPrice can be, covers the whole position and sits outside its ladder. A sized exit of the same kind placed farther from the market than it succeeds, and moves that protection: the whole-position order is cancelled and placed again under a new orderId, sized at the position less the sized exits, and your new order becomes the whole-position exit, listed with closePosition. On a 1 BTC long with an attached stop at 45,000, a 0.3 BTC stop at 44,000 leaves 0.7 BTC stopped at 45,000 and makes 44,000 the stop for whatever remains. When your new exit and the other sized exits already cover the whole position, nothing replaces the whole-position order: a 1 BTC stop at 44,000 on that long leaves it stopped at 44,000 only, so a full-size backup stop placed farther out removes the nearer one. Read ListOpenOrders after placing an exit to see what now protects the position.
  • When the position closes, its reduce-only orders are cancelled, and a partial close shrinks any that would exceed what remains.
  • An exit on a position that has already closed, as when two closes race, answers failed_precondition, kind POSITION_ALREADY_CLOSED: treat the close as done.
  • An exit on a leg of a pair trade answers failed_precondition: a pair closes as a pair, in the app or through CloseAllPositions.

Limits

An account is limited to 300 resting orders that open or add to a position, untriggered stops included. One more answers failed_precondition, kind TOO_MANY_OPEN_ORDERS, until one fills or is cancelled; reduce-only orders, take-profits and stop-losses do not count. An account may separately be limited to 300 resting reduce-only orders, take-profits and stop-losses. One more answers the same code and kind, and so does an order that attaches takeProfitPrice or stopLossPrice. The message tells the two limits apart, beginning too many open orders or too many open exit orders, and says how many to cancel. The exits an entry attaches are still created when it fills, so an account can hold more than 300, and a reduce-only MARKET is never refused for either limit, so a position can always be closed. An order may also be refused with invalid_argument when it is worth less than $10, on every market. A LIMIT is valued at its price, a STOP_MARKET at its triggerPrice and a MARKET at the price it would fill at. Reduce-only orders, take-profits, stop-losses and a MARKET placed as a position’s reduce-only exit are never refused for it. A LIMIT or STOP_MARKET without reduceOnly is measured even when it would only reduce a position, so send a small exit with reduceOnly: true.

Examples