sdk.trading.
Place Orders
(pairId, side, quantity, price, options?) => Promise<CreateOrderResponse>
Place a limit order. Spot by default; opt into perp with
tradingMode: "MARGIN" and leverage.options:tradingMode?:"SPOT" | "MARGIN"useMasterBalance?: booleanexpirationDate?: string — ISO 8601; pair withGTCfor an order that expires at a set timetimeInForce?:"GTC" | "IOC" | "FOK"(GTDis declared in the protos but never implemented — the server rejects it)postOnly?: boolean — maker-only; the order is rejected instead of matching if it would cross the book.GTConly — rejected onMARKETorders and withIOC/FOK. See Post-Only OrdersselfTradePreventionMode?:"CANCEL_MAKER" | "CANCEL_TAKER" | "CANCEL_BOTH" | "SKIP"— how the engine resolves this order meeting one of your own resting orders (your whole wallet family). Overrides the wallet default; omit to inherit that, or the platform defaultCANCEL_MAKER. See Self-Trade Preventionleverage?: string — decimal string; required for normal margin orders, omit only for reduce-onlyreduceOnly?: boolean — order can only shrink existing exposuremarginAccountId?: string — optional legacy override; omit for normal perp orderspositionSide?:"LONG" | "SHORT" | "NONE"— deprecated.sideis the authoritative direction; if supplied,positionSidemust agree (BUY↔LONG,SELL↔SHORT)clientOrderId?: string — correlation handle echoed on order reads andordersWebSocket events (≤64 chars fromA-Za-z0-9._:-); not an idempotency key. Restate it onreplaceOrder— a replacement inherits nothing. See Client Order IDsidempotencyKey?: string — durable submission key. The SDK generates one for this call when omitted; retain and reuse an explicit key with the same payload to recover across calls or restarts within 24 hours. See Safe Retries
side sets the direction. Attach TP/SL at entry with takeProfit/stopLoss (margin entry orders only; legs activate when the order fills), or attach to the open position with usePositions().attachPositionTpSl. A trailingStop leg attaches the same way, arms only when the order fully fills, and returns trailingStopOrderId only when the trailing stop materializes (a full fill on arrival or a resting remainder; a partial IOC / MARKET fill whose remainder is cancelled creates none) — see Trailing Stop.Perp example:(pairId, side, quantity, options?) => Promise<CreateOrderResponse>
Place a market order. Market orders execute inside a mandatory 1,000 bps server-side price band (see Market-order price protection) and can partially fill with the remainder cancelled, or be rejected when no liquidity sits inside the band.
options:tradingMode?:"SPOT" | "MARGIN"slippageTolerance?: number — tightens the 1,000 bps band (e.g.0.01for 1%); cannot widen itleverage?: string — required for normal margin orders, omit only for reduce-onlyreduceOnly?: booleanmarginAccountId?: string — optional legacy override; omit for normal perp orderspositionSide?:"LONG" | "SHORT" | "NONE"— deprecated;sideis authoritativeclientOrderId?: string — correlation handle echoed on order reads andordersWebSocket events (≤64 chars fromA-Za-z0-9._:-); not an idempotency key. See Client Order IDsselfTradePreventionMode?:"CANCEL_MAKER" | "CANCEL_TAKER" | "CANCEL_BOTH" | "SKIP"— how the engine resolves this order meeting one of your own resting orders (your whole wallet family). Overrides the wallet default; omit to inherit that, or the platform defaultCANCEL_MAKER. See Self-Trade PreventionidempotencyKey?: string — durable submission key. The SDK generates one for this call when omitted; retain and reuse an explicit key with the same payload to recover across calls or restarts within 24 hours. See Safe Retries
Order Management
(orderId) => Promise<CancelOrderResponse>
Cancel an existing order
(orderIds: string[]) => Promise<BatchCancelOrdersResponse>
Cancel specific orders by their IDs.Returns:
totalRequested: numbertotalCancelled: numbertotalFailed: numberresults:BatchCancelResult[]— each withorderId, optionalcancelledAt, optionalerror: { code, message }
totalFailed === 0 for an overall-success check.Capped at 100 order IDs per request by the API (enforced server-side, no client-side schema check); a longer list is rejected with 400 At most 100 orders per batch request. batchCancelAll enumerates active orders server-side, with a separate cap of 20,000 matching active orders.Example:(tradingPairId?: string) => Promise<BatchCancelOrdersResponse>
Cancel all active orders, optionally scoped to one trading pair.The API caps the request at 20,000 matching active orders. Above that cap, it cancels nothing and returns REST
400; narrow by trading pair or cancel explicit batches of at most 100 IDs. The cap check is all-or-nothing and runs before any cancellation.Returns the same shape as batchCancel.Throws:- REST
400when the pair UUID is invalid or more than 20,000 matching active orders would be cancelled - REST
401when authentication is missing or invalid - REST
403when a delegated session omits the required pair scope or lacks permission - REST
500for an internal matching-engine failure - REST
503for a transient matching-engine or transport failure
(orderId, newOrder) => Promise<ReplaceOrderResponse>
Modify an existing order’s price or quantity.
quantity is the order’s new total (a partially filled order rests total - filled and must exceed the filled amount; omit it to keep the total), and the replacement inherits the original’s fill history — see replaceOrder for the full semantics. newOrder also accepts postOnly, clientOrderId and selfTradePreventionMode — a replacement is a new order and inherits none of them, so restate clientOrderId to keep the handle and selfTradePreventionMode to keep the override. batchReplace items take the same three. See Client Order IDs.Batch Operations
(orders: BatchCreateOrderParams[]) => Promise<BatchCreateOrdersResponse>
Create multiple orders in a single request. Capped at 100 items — a longer array is rejected client-side (
At most 100 orders per batch request, exported as MAX_BATCH_ORDER_ITEMS) before the request is sent.BatchCreateOrderParams:tradingPairId: stringorderType:"LIMIT" | "MARKET"side:"BUY" | "SELL"quantity: stringprice?: string — required for LIMITtimeInForce?:"GTC" | "IOC" | "FOK"— LIMIT items only; the SDK rejects it on a MARKET item (market orders take no time-in-force and always execute IOC-style inside the price band)postOnly?: boolean — maker-only; the item is rejected instead of matching if it would cross the book, reported per-item aserror.code === "POST_ONLY_WOULD_CROSS". LIMIT items withGTConly. See Post-Only OrdersselfTradePreventionMode?:"CANCEL_MAKER" | "CANCEL_TAKER" | "CANCEL_BOTH" | "SKIP"— per-item self-trade-prevention override. The value is validated client-side, so an unknown mode throwsValidationErrorbefore the request is sent; the per-itemerror.codeINVALID_SELF_TRADE_PREVENTION_MODEis the raw REST/gRPC caller’s shape. See Self-Trade PreventionslippageTolerance?: number — for MARKETexpirationDate?: string — ISO 8601, custom expiry for GTCuseMasterBalance?: booleanclientOrderId?: string — per-item correlation handle echoed on order reads andordersWebSocket events (≤64 chars fromA-Za-z0-9._:-); a malformed value fails that item witherror.code === "INVALID_CLIENT_ORDER_ID". Not an idempotency key. See Client Order IDsidempotencyKey?: string — per-item durable submission key. The SDK generates one per item when omitted. Retain explicit per-item keys for recovery across calls; each key protects only its own item and does not make the batch atomic. See Safe Retries
BatchCreateOrdersResponse:totalRequested: numbertotalSucceeded: numbertotalFailed: numberresults:BatchCreateResult[]
BatchCreateResult:orderId: string — empty if creation failed before ID assignmentmatchResult?:MatchResult— present if order was immediately matchederror?:BatchError—{ code, message }. Treat absence oferroras success.
(orders: BatchReplaceOrderParams[]) => Promise<BatchReplaceOrdersResponse>
Replace multiple orders in a single request. Each replacement atomically cancels the original and creates a new one. Capped at 100 items — a longer array is rejected client-side (
At most 100 orders per batch request) before the request is sent.BatchReplaceOrderParams:orderId: stringprice?: stringquantity?: string — the order’s new total (same rule asreplaceOrder): a partially filled order reststotal - filledand the total must exceed the filled amount; omit it to keep the order’s total. Margin reduce-only replacements are exempt (the quantity stays a close size), and the replacement inherits the original’s fill historyuseMasterBalance?: booleanclientOrderId?: string — per-item correlation handle for the replacement order (a replacement does not carry over the original’sclientOrderId, so restate it). A malformed handle fails its item alone (error.codeINVALID_CLIENT_ORDER_ID, the same code batch-create uses) with its original untouched. See Client Order IDspostOnly?: boolean — maker-only intent for the replacement; never inherited from the original. See Post-Only OrdersselfTradePreventionMode?:"CANCEL_MAKER" | "CANCEL_TAKER" | "CANCEL_BOTH" | "SKIP"— per-item self-trade-prevention override for the replacement, likewise never inherited; omit it to fall back to your wallet default. An unknown value is rejected client-side withValidationErrorbefore sending;error.codeINVALID_SELF_TRADE_PREVENTION_MODEis what a raw REST/gRPC caller gets on that item alone. See Self-Trade Prevention
BatchReplaceOrderItemSchema requires at least one of price or quantity, so an item carrying only selfTradePreventionMode (or only postOnly) throws ValidationError before the request is sent. Restate the price or quantity alongside the option.Returns — BatchReplaceOrdersResponse:totalRequested,totalSucceeded,totalFailed: numberresults:BatchReplaceResult[]
BatchReplaceResult:originalOrderId: stringnewOrderId?: stringupdatedFields?:{ price?, quantity? }matchResult?:MatchResulterror?:BatchError—{ code, message }. Absence oferrorindicates success.
Conditional Orders (Perp TP/SL)
Attach TP/SL and trailing stops at entry viatakeProfit/stopLoss/trailingStop on placeLimitOrder / placeMarketOrder, or to an open position with usePositions().attachPositionTpSl. The hook below covers listing and cancelling conditional orders. Concepts and lifecycle: Order Management.
(conditionalOrderId: string) => Promise<CancelConditionalOrderResponse>
Cancel an active conditional order.
(params?: ListConditionalOrdersParams) => Promise<ListConditionalOrdersResponse>
List conditional orders for the authenticated user. Passes
params straight to sdk.trading.listConditionalOrders, so cursor (pageToken) pagination is the default: follow each response’s nextPageToken until it comes back empty.Parameters:marginAccountId?,tradingPairId?,state?,pageToken?,pageSize?(up to1000in cursor mode),page?(deprecated — selects legacy page-number mode, maxpageSize100)
Order Queries
(params?) => Promise<GetPaginatedOrdersResponse>
Fetch paginated orders
(orderId) => Promise<GetOrderResponse>
Get order details by ID

