# Orderbook

Retrieve the live orderbook for a market.

## Get Orderbook

Returns the current orderbook snapshot for a market.

```
GET /api/v1/orderbook/{marketId}
```

### Path Parameters

| Parameter  | Type    | Description       |
| ---------- | ------- | ----------------- |
| `marketId` | bytes32 | Market identifier |

### Query Parameters

| Parameter | Type   | Required | Description                                                                   |
| --------- | ------ | -------- | ----------------------------------------------------------------------------- |
| `outcome` | string | No       | Filter by outcome: `YES` or `0`, `NO` or `1`. If omitted, returns all orders. |

### Response

```json
{
  "marketId": "0x1234...abcd",
  "bids": [
    {
      "price": 500000,
      "size": 10000000
    },
    {
      "price": 490000,
      "size": 20000000
    }
  ],
  "asks": [
    {
      "price": 520000,
      "size": 15000000
    }
  ],
  "lastUpdate": 1735689000
}
```

| Field        | Type    | Description                                            |
| ------------ | ------- | ------------------------------------------------------ |
| `marketId`   | bytes32 | Market identifier                                      |
| `bids`       | array   | Buy orders sorted by price descending (best bid first) |
| `asks`       | array   | Sell orders sorted by price ascending (best ask first) |
| `lastUpdate` | uint64  | Unix timestamp of last orderbook update                |

### Price Level Fields

| Field   | Type   | Description                                                         |
| ------- | ------ | ------------------------------------------------------------------- |
| `price` | uint64 | Price in USDC (6 decimals). `500000` = $0.50                        |
| `size`  | uint64 | Total size at this price level (6 decimals). `10000000` = 10 shares |

### Per-Outcome Orderbooks

YES and NO each have separate orderbooks. A BUY YES order only matches against SELL YES orders, never SELL NO.

When you specify `outcome=YES`, you get the YES orderbook:

* **Bids**: Users wanting to buy YES tokens
* **Asks**: Users wanting to sell YES tokens

### Examples

```bash
# All orders (both YES and NO)
curl "https://api.turbinefi.com/api/v1/orderbook/0x1234...abcd"

# YES orderbook only
curl "https://api.turbinefi.com/api/v1/orderbook/0x1234...abcd?outcome=YES"

# NO orderbook only
curl "https://api.turbinefi.com/api/v1/orderbook/0x1234...abcd?outcome=NO"
```

If no orderbook exists for a market, an empty snapshot is returned with `bids: []` and `asks: []`.
