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

# Market data

> Subscribe to real-time market depth updates via MarketDataSnapshotRequest.

export const Check = () => <Icon icon="check" color="#049159" />;
export const Cross = () => <Icon icon="x" color="#dd0000" />;

## MarketDataSnapshotRequest

`MarketDataSnapshotRequest` subscribes to real-time market depth updates for a specified trading symbol.

Code example for subscribing to market data:

```python theme={null}
def subscribe_marketdata(ws, symbol, receiver, accountId=None, subaccountId=None):
    payload = {
        "type": "subscribe",
        "symbol": symbol,
        "reqId": str(uuid.uuid4())
    }
    if accountId is not None:
        payload["accountId"] = accountId
    if subaccountId is not None:
        payload["subaccountId"] = subaccountId

    msg = json.dumps({
        "messageType": "MarketDataSnapshotRequest",
        "timestamp": datetime.now().isoformat(),
        "payload": payload
    })
    ws.send(msg)
    while True:
        resp = json.loads(ws.recv())
        receiver(resp)
```

**Subscription example — BTC-USD:**

```json theme={null}
{
  "messageType": "MarketDataSnapshotRequest",
  "timestamp": "2023-02-08T14:19:43.901696",
  "payload": {
    "type": "subscribe",
    "symbol": "BTC-USD",
    "reqId": "e07b9683-af27-481a-b4db-1c492114e930"
  }
}
```

**Example response:**

```json theme={null}
{
  "messageType": "MarketDataSnapshot",
  "timestamp": "2023-02-08T14:19:44Z",
  "version": "1.0",
  "seqNum": 9,
  "sessionId": "fcd5d616-8208-401a-9001-d299bcc9a8c6",
  "payload": {
    "asks": [
      { "price": "23083.25076763", "size": "1" },
      { "price": "23084.28705625", "size": "4" },
      { "price": "23084.78", "size": "5" },
      { "price": "23089.14", "size": "40" },
      { "price": "23094.57", "size": "50" }
    ],
    "bids": [
      { "price": "23081.96", "size": "1" },
      { "price": "23080.96918517", "size": "4" },
      { "price": "23080.61566563", "size": "5" },
      { "price": "23074.06841953", "size": "40" },
      { "price": "23068.87", "size": "50" }
    ],
    "reqId": "e07b9683-af27-481a-b4db-1c492114e930",
    "symbol": "BTC-USD"
  }
}
```

***

### Subscription parameters

| Parameter      | Type          | Required  | Description                                                                                   |
| -------------- | ------------- | --------- | --------------------------------------------------------------------------------------------- |
| `messageType`  | string        | <Check /> | `"MarketDataSnapshotRequest"`                                                                 |
| `symbol`       | string        | <Check /> | Trading pair to subscribe to, e.g. `BTC-USD`                                                  |
| `reqId`        | string (UUID) | <Check /> | Unique request ID for this subscription                                                       |
| `accountId`    | string (UUID) | <Cross /> | Scopes the feed to a specific account. Use either `accountId` or `subaccountId`, not both.    |
| `subaccountId` | string (UUID) | <Cross /> | Scopes the feed to a specific subaccount. Use either `accountId` or `subaccountId`, not both. |

***

### Response parameters

| Parameter     | Type      | Required  | Description                                               |
| ------------- | --------- | --------- | --------------------------------------------------------- |
| `messageType` | string    | <Check /> | Identifies the message as a market data snapshot response |
| `symbol`      | string    | <Check /> | Trading pair for this snapshot, e.g. `BTC-USD`            |
| `asks`        | object\[] | <Check /> | Full list of asks                                         |
| ⤷ `price`     | string    | <Check /> | Limit price of the level                                  |
| ⤷ `size`      | string    | <Check /> | Size of this level                                        |
| `bids`        | object\[] | <Check /> | Full list of bids                                         |
| ⤷ `price`     | string    | <Check /> | Limit price of the level                                  |
| ⤷ `size`      | string    | <Check /> | Size of this level                                        |
