> ## Documentation Index
> Fetch the complete documentation index at: https://docs.0xmonaco.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Orderbooks & Trades

> Read orderbook snapshots, recent trades, candles, and live public market streams.

Use orderbooks, trades, and candles after resolving a `tradingPairId` from [Markets](/developers/markets). REST gives you snapshots or history. WebSockets keep market views live.

## Surface Map

| Surface | Use |
| - | - |
| REST | `GET /api/v1/orderbook/{tradingPairId}`, `GET /api/v1/trades/{tradingPairId}`, `GET /api/v1/trades/by-id/{tradeId}`, `GET /api/v1/market/pairs/charts/candlestick/{tradingPairId}/{interval}` |
| TypeScript SDK | `sdk.orderbook.getOrderbook()`, `sdk.trades.getTrades()`, `sdk.trades.getTradeById()`, `sdk.market.getCandlesticks()` |
| React SDK | `useOrderbook()`, `useTradeFeed()`, `useOHLCV()` |
| WebSocket | `orderbook:{id}:{mode}:{magnitude}:{denomination}`, `trades:{id}`, `ohlcv:{id}:{mode}:{interval}` |
| gRPC | `OrderbookService`, `TradesService`, `MarketService.GetCandles` |

## Candles

Candles are historical over REST and live over WebSocket. Use REST to backfill charts, then subscribe to the matching OHLCV channel for updates.

<CodeGroup>
  ```typescript TypeScript SDK theme={null}
  const pair = await sdk.market.getTradingPairBySymbol("SOL/USDC");
  const candles = await sdk.market.getCandlesticks(pair.id, "1m", {
    limit: 300,
  });

  const unsubscribe = sdk.ws.ohlcv(pair.id, "SPOT", "1m", (event) => {
    console.log(event.data);
  });
  ```

  ```bash REST + WebSocket theme={null}
  curl "https://staging.apimonaco.xyz/api/v1/market/pairs/charts/candlestick/$TRADING_PAIR_ID/1m?limit=300"

  wscat -c "wss://ws-staging.apimonaco.xyz/ws"
  > {"type":"Subscribe","channels":["ohlcv:$TRADING_PAIR_ID:SPOT:1m"]}
  ```
</CodeGroup>

## Orderbooks

Use REST for an initial snapshot. Use WebSocket for live depth. `magnitude` controls price grouping and `denomination` controls whether quantities are shown in base or quote units.

<CodeGroup>
  ```typescript TypeScript SDK theme={null}
  const orderbook = await sdk.orderbook.getOrderbook(pair.id, {
    depth: 20,
    tradingMode: "SPOT",
    magnitude: 1,
    denomination: "BASE",
  });

  const unsubscribe = sdk.ws.orderbook(
    pair.id,
    "SPOT",
    1,
    "BASE",
    (event) => {
      console.log(event.bestBid, event.bestAsk, event.bids, event.asks);
    },
  );
  ```

  ```bash REST + WebSocket theme={null}
  curl "https://staging.apimonaco.xyz/api/v1/orderbook/$TRADING_PAIR_ID?levels=20&tradingMode=SPOT&magnitude=1&denomination=base"

  wscat -c "wss://ws-staging.apimonaco.xyz/ws"
  > {"type":"Subscribe","channels":["orderbook:$TRADING_PAIR_ID:SPOT:1:base"]}
  ```
</CodeGroup>

## Trades

Use REST for recent historical trades. Use WebSocket for live executions.

The trades listing is cursor paged: omit `pageToken` to start at the newest
trade, then follow `nextPageToken` until it comes back empty. There is no `page`
parameter — sending one returns `400`.

<CodeGroup>
  ```typescript TypeScript SDK theme={null}
  const { trades, nextPageToken } = await sdk.trades.getTrades(pair.id, {
    pageSize: 50,
  });

  const unsubscribe = sdk.ws.trades(pair.id, (event) => {
    console.log(event.data.price, event.data.quantity);
  });
  ```

  ```bash REST + WebSocket theme={null}
  curl "https://staging.apimonaco.xyz/api/v1/trades/$TRADING_PAIR_ID?pageSize=50"
  # then, from the previous response's nextPageToken:
  curl "https://staging.apimonaco.xyz/api/v1/trades/$TRADING_PAIR_ID?pageSize=50&pageToken=$NEXT_PAGE_TOKEN"

  wscat -c "wss://ws-staging.apimonaco.xyz/ws"
  > {"type":"Subscribe","channels":["trades:$TRADING_PAIR_ID"]}
  ```
</CodeGroup>

## Builder Notes

* Treat REST as snapshot or history and WebSocket as live state.
* Reconcile WebSocket streams against periodic REST refreshes when correctness matters.
* Public market data does not require authentication.
* All WebSocket channel parameters use trading pair IDs, not symbols.

## Related Pages

* [Markets](/developers/markets) for pair IDs, product support, metadata, and funding.
* [WebSocket API](/reference/websockets) for raw channel grammar.
* [TypeScript WebSockets](/sdk/typescript/websockets) for SDK subscription helpers.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.