Skip to main content
Trading workflows require an authenticated session.
Perps trading changes account exposure on an instrument. An order expresses what the account wants to do, but exposure only changes when the order fills. An accepted order can rest on the book before it fills. Use order state to track accepted, resting, modified, canceled, or rejected orders. Use fills and portfolio state to confirm any exposure change.

Start an Authenticated Session

Open an authenticated session before reading private account state or submitting trading commands. See Authenticated Sessions for the full setup flow.
Create a SecureClient.
Open the Perps session.

Prepare a Trade

Start by identifying the Perps instrument you want to trade. Instruments define the market and include the constraints used later when building an order.
Fetch instruments and select the market you want to trade.
Keep the selected instrument available for the next steps.

Choose Direction and Size

Before placing an order, decide whether it should open new exposure, increase existing exposure, reduce exposure, or close the position. The effect of a buy or sell depends on the current position. To close a position, submit an order in the opposite direction for the current open position size.
Read the portfolio when the order decision depends on current exposure.
Positive position.size means the account is long. Negative position.size means the account is short. No matching position means the account has no open exposure for that instrument.

Place Orders

Place an order when the account is ready to express buy or sell intent. Use an explicit limit price when you need price protection. Use immediate-or-cancel execution when the order should fill immediately or cancel any unfilled quantity.
1

Choose a Price

Fetch a ticker when you need a lightweight current-price reference. Fetch the book when the order price depends on spread, depth, or top-of-book liquidity.
Set price as pUSD per quantity unit, rounded to instrument.priceDecimals.
2

Build the Order

Create the order request from the direction, price, quantity, and execution behavior you chose. This example submits an immediate-or-cancel (IOC) buy order for 0.01 BTC-PERP at 65000 pUSD per quantity unit.
  • side sets direction based on how you intend to open, increase, reduce, or close the position.
  • price is the price you chose in the first step, in pUSD per quantity unit.
  • quantity is the number of quantity units. Use no more than instrument.quantityDecimals decimal places.
Use clientOrderId when your integration needs its own identifier for tracking or canceling the order.
3

Submit the Order

Submit the request with placeOrder. It resolves with the matching private order update after the order is accepted.
Use the returned order to track whether the order filled, expired, canceled, or remains on the book.
For an IOC order, status can be one of these values.

Take Profit & Stop Loss

Use take-profit and stop-loss (TP/SL) orders to place conditional exits for a position. A take-profit order exits when price moves in your favor. A stop-loss order exits when price moves against you.

How Triggers Work

TP/SL orders watch the mark price, not the last traded price. A trigger fires when the mark price touches the trigger price, then submits a reduce-only order to close exposure. For a long position, take-profit triggers usually sit above the current mark and stop-loss triggers usually sit below it. For a short position, the directions are reversed.

Market and Limit Closes

Choose how the exit should execute after the trigger fires.

Place a Bracket Order

A bracket order submits one entry order with up to one take-profit and one stop-loss trigger. The triggers stay dormant until the entry fills in full. If the entry is canceled, rejected, or only partially filled, the triggers are canceled too. A bracket protects the completed entry, not a partial fill.
You cannot attach TP/SL triggers to an order that is already resting on the book. To protect a position from an existing order, wait for the fill and then protect the position.
Place a GTC entry order with take-profit and stop-loss triggers.
result.order is the entry order. result.tpSl contains the order IDs for the conditional exits that were accepted with the entry order.
Add limitPrice to a trigger when the exit should place a limit order at trigger time.

Protect an Existing Position

Add TP/SL orders to a position that is already open. Position TP/SL closes the full position at trigger time, so it does not use a fixed quantity. Position TP/SL has a few placement rules:
  • The account must already hold a position in the instrument.
  • The account can have at most one position take-profit and one position stop-loss per instrument.
  • When the trigger fires, the exit submits immediately. Position TP/SL does not support limit prices.
  • A position trigger is rejected if the current mark has already crossed it, because it would fire immediately.
Place TP/SL orders for the full current position.
placePositionTpSl sizes the exit at trigger time, so you do not pass a position side or quantity.

Update or Cancel TP/SL

TP/SL orders cannot be modified in place. To change a trigger price or execution type, cancel the old trigger and create a replacement.
  • For position TP/SL, cancel the old trigger before creating another trigger of the same kind for the instrument.
  • For a bracket whose entry is still resting, cancel the entry and place a new bracket with the updated triggers.
  • For a bracket whose entry already filled, cancel the armed trigger and create position TP/SL as the replacement.
Cancel-then-create is not atomic. Between the cancel and the replacement, the position may be unprotected.

Configure Order Behavior

So far, we have used immediate-or-cancel orders. Next, we’ll look at how to control whether an order rests, fills immediately, or only adds liquidity.

Good-Til-Canceled Orders

Use good-til-canceled orders when the order can rest on the book until it fills or you cancel it.
Set timeInForce to GTC.
For a GTC order, order.status can be one of these values.If a GTC order partially fills and rests, inspect filledQuantity and restingQuantity on the returned order.

Post-Only Orders

A post-only order is a special type of good-til-canceled order that only adds liquidity. If it would cross the book and take liquidity, it is rejected instead.
Set postOnly: true on a GTC order.
For a post-only order, order.status can be one of these values.

Fill-Or-Kill Orders

Use fill-or-kill orders when the full quantity must fill immediately or cancel. These orders do not rest on the book.
Set timeInForce to FOK.
For a FOK order, order.status can be one of these values.

Cancel Orders

Cancel resting orders when they are stale, conflict with updated strategy, or should no longer remain on the book. Canceling a resting order does not close any filled position.

Cancel Single Orders

Cancel stale orders by order ID or by client order ID.
Use result.status to confirm whether the cancel request was accepted.Canceling a working order removes it from the book.

Cancel All Orders

Cancel every open order for your account in a single request, for example when pulling quotes during a fast move or shutting down a strategy. Scope the request to one instrument to clear only that book while quotes on other instruments stay live. A successful response confirms the request was accepted, not that every order is already gone: individual orders can still race with fills or other cancels. Confirm the final state from your open orders.
Cancel all open orders, or only the open orders on one instrument.
The call resolves once the request is accepted and throws if it is rejected. Use session.fetchOpenOrders() to confirm the remaining open orders.

Close a Position

Closing a position is a new order in the opposite direction of the open position. Use the full open position size to close. Use a smaller quantity to reduce instead. Mark close orders reduce-only so they cannot flip the account into new exposure if position state changes before execution. Reduce-only is a safeguard, not a sizing shortcut. You still choose the quantity: use the full position size to close or a smaller quantity to reduce. If the order would increase exposure, flip the position, or exceed the remaining closeable size, it is rejected. The remaining closeable size accounts for other resting reduce-only orders on the same instrument.
Find the current position by market symbol and parse its decimal size.
Close a long position by selling the full size, or close a short position by buying the absolute position size.
These examples use an IOC order with no price and only treat the close as complete when order.status is PerpsOrderStatus.Filled. Include a price when you want to limit execution, or use FOK or GTC when the close should follow a different order behavior.For reduce-only orders, also handle these statuses.

Update Leverage

Leverage controls how much notional exposure a position can carry relative to its margin. Cross margin uses available account collateral for the position; non-cross margin keeps the position isolated. Some instruments support only isolated margin and reject cross margin. Validate leverage against the instrument’s maximum leverage and current risk tiers before submitting the change.
1

Read Current Configuration

Read the current account configuration before changing leverage.
config includes the current leverage and margin mode for the instrument.
2

Update Leverage

Update leverage and whether the position uses cross margin. Validate leverage against instrument.maxLeverage and the current instrument.riskTiers, and request crossMargin: true only when instrument.isolatedOnly is false.
The result includes the effective leverage configuration after the update.
Example Result

Reconcile Trade State

Keep local trading state in sync by starting from a local snapshot, applying live updates, and reconciling again whenever the session tells you state may have been missed. TP/SL orders appear alongside regular orders in open-order and order-history reads. Track their lifecycle in addition to the position and fills they protect.
1

Fetch a Startup Snapshot

Fetch a snapshot when the session starts.
2

Apply Live Events

Then apply trading live events while the session is open.
3

Reconcile on Resync

When event.type is "resync", use account reads as the first step to reconcile local state before applying more local assumptions.

Trading Fees

Use the fee schedule when you need to display or account for the default maker and taker trading fees. Fee rates are decimal strings, so "0.0004" means 0.04%. The schedule returns default ($0 tier) rates. The account’s actual rate on each fill depends on its trailing 30-day volume tier. See Fees for the tier table.
Fetch the current Perps fee schedule.
Each fee entry contains the market category and its default maker and taker fee rates.
makerFeeRate applies when an order adds liquidity, such as a resting or post-only order. takerFeeRate applies when an order removes liquidity, such as an immediately filled IOC order.