Skip to main content
The hook returns the same surface as 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?: string
    • tradingPairId?: string
    • status?: "OPEN" | "CLOSED" | "LIQUIDATING"
    • page?: number
    • pageSize?: number
Returns: { 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?: string
    • marginAccountId?: string
    • tradingPairId?: string
    • page?: number
    • pageSize?: 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:
  • transferCollateralToRiskBucket is the direct addPositionMargin replacement: by default it commits the amount to the open position’s stored margin (leverage drops and stays down); pass applyToPositionMargin: false to fund the bucket with spendable free collateral instead. The pair-scoped transferCollateralToMarginAccount is deprecated and matches the default.
  • transferCollateralFromMarginAccount (with tradingPairId) 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: string
  • request:
    • takeProfit?: TpSlLeg
    • stopLoss?: TpSlLeg
    • trailingStop?: TrailingStopLeg — { trailBps, activationPrice?, closePosition?, quantity?, slippageToleranceBps?, expiresAt? }; one per position, never part of oco. See Trailing Stop
    • oco?: 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: string
  • request:
    • closeType: "MARKET" | "LIMIT" | "IOC"
    • limitPrice?: string — required for LIMIT and IOC, forbidden only for MARKET
    • quantity?: string — defaults to full position size
    • slippageToleranceBps?: number — for MARKET / IOC
Example — partial market close:
(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 closed
    • slippageToleranceBps?: number — applied to each MARKET close
Example — close-all button:

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.