sdk.positions. Each method is the same async function, ready to call from components or effects. There’s no state, subscriptions, or auto-refresh built in — wrap calls in your own useEffect / SWR / React Query as suits your app.
For end-to-end flow and UI patterns, see Positions.
Read
(params?: ListPositionsParams) => Promise<ListPositionsResponse>
Paginated list of positions.Parameters:
params?:marginAccountId?: stringtradingPairId?: stringstatus?:"OPEN" | "CLOSED" | "LIQUIDATING"page?: numberpageSize?: number
{ positions: Position[]; total: number; page: number; pageSize: number }Example — positions panel:(positionId: string) => Promise<Position>
Full snapshot of a single position. Includes side, size, entry/mark/liquidation prices, isolated margin, leverage, and PnL. See
Position type.(positionId: string) => Promise<PositionRisk>
Volatile risk fields (mark price, liquidation price, margin ratio, unrealized PnL). Cheaper than
getPosition for live displays.Example — live liquidation distance:(params?: ListPositionHistoryParams) => Promise<ListPositionHistoryResponse>
Lifecycle events for one position or all positions in scope.Parameters:
params?:positionId?: stringmarginAccountId?: stringtradingPairId?: stringpage?: numberpageSize?: number
Modify
addPositionMargin and reducePositionMargin were removed from this hook.
Adjust a position’s margin through the margin-account SDK surface — every leg
moves collateral between a risk bucket and the parent margin account, never to
or from the spot wallet:transferCollateralToRiskBucketis the directaddPositionMarginreplacement: by default it commits the amount to the open position’s stored margin (leverage drops and stays down); passapplyToPositionMargin: falseto fund the bucket with spendable free collateral instead. The pair-scopedtransferCollateralToMarginAccountis deprecated and matches the default.transferCollateralFromMarginAccount(withtradingPairId) releases collateral back to the parent.
(positionId, request) => Promise<AttachPositionTpSlResponse>
Attach take-profit and/or stop-loss conditional orders to the position. At least one leg is required. Pass
oco: true to cancel the sibling once one leg triggers (requires both legs).Parameters:positionId: stringrequest:takeProfit?:TpSlLegstopLoss?:TpSlLegtrailingStop?:TrailingStopLeg—{ trailBps, activationPrice?, closePosition?, quantity?, slippageToleranceBps?, expiresAt? }; one per position, never part ofoco. See Trailing Stopoco?: boolean — cancel the sibling leg after one triggers; requires both fixed legs
TpSlLeg: { triggerPrice, orderType: "MARKET" | "LIMIT", limitPrice?, closePosition?, quantity?, timeInForce?, slippageToleranceBps?, expiresAt? }. Set closePosition: true to resolve the full live position size on trigger (omit quantity). See Order Management.Example — TP/SL modal submit:Close
(positionId, request) => Promise<ClosePositionResponse>
Submit a closing order. Position transitions to
CLOSED only after the closing order fills.Parameters:positionId: stringrequest:closeType:"MARKET" | "LIMIT" | "IOC"limitPrice?: string — required forLIMITandIOC, forbidden only forMARKETquantity?: string — defaults to full position sizeslippageToleranceBps?: number — forMARKET/IOC
(request?: BatchCloseAllRequest) => Promise<BatchCloseAllResponse>
Submit a MARKET reduce-only close for every open position owned by the caller — a one-call “panic close”. Best-effort and partial: each position closes independently, and per-position failures are reported in
results instead of aborting the batch. See BatchCloseAllResponse type.Parameters:request?:tradingPairId?: string — limit the close to one trading pair; if omitted, all open positions are closedslippageToleranceBps?: number — applied to each MARKET close
Subscribing to lifecycle events
usePositions doesn’t ship a built-in subscription. For live updates of conditional-order lifecycle (TP/SL state changes), use sdk.ws.conditionalOrders — see the WebSocket reference.
For order-fill confirmations after a closePosition or attached-TP/SL trigger, subscribe to sdk.ws.userOrders.
