Skip to main content

Parameters

string
required
Trading pair UUID. Get this from sdk.market.getTradingPairBySymbol('BTC/USDC').
'SPOT' | 'MARGIN'
required
Trading mode for the orderbook subscription. Use 'SPOT' for spot markets and 'MARGIN' for perp markets.
number
required
Price level grouping magnitude. Valid values: 0.0001, 0.001, 0.01, 0.1, 1, 10, 100, 1000, 10000
'BASE' | 'QUOTE'
required
Quantity denomination. BASE shows quantities in base token, QUOTE multiplies by price.
number
default:"10"
Number of price levels to fetch (max: 100)

Return Values

OrderbookEvent | null
Current orderbook snapshot with bids, asks, best prices, and volumesProperties:
  • tradingPairId: Trading pair ID (UUID)
  • tradingMode: “SPOT” | “MARGIN”
  • bids: Array of { price, quantity, orderCount }
  • asks: Array of { price, quantity, orderCount }
  • bestBid: Best bid price
  • bestAsk: Best ask price
  • bidVolume: Total bid volume
  • askVolume: Total ask volume
  • priceChange: Price change info (optional) - { side, oldPrice?, newPrice?, levelRemoved, levelAdded }
  • baseDecimals: Base token decimals
  • quoteDecimals: Quote token decimals
  • timestamp: Snapshot timestamp
  • sequence: Sequence number for ordering
boolean
Whether currently subscribed to real-time updates
Error | null
Connection or subscription error if any
() => void
Clear the current error

Example

How It Works

  1. Initial Load: Fetches orderbook snapshot via REST API
  2. Real-time Updates: Subscribes to WebSocket for live updates
  3. Auto-cleanup: Unsubscribes when component unmounts or params change
The hook combines REST and WebSocket for the best experience - instant data on load, real-time updates after.