> ## 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.

# Getting started

> Connect to the Anchorage Digital WebSocket API for real-time market data.

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

The Anchorage Digital WebSocket API supports the WebSocket protocol for real-time market data.

**Endpoint:** `wss://api.anchorage.com/ws/v2/trading`

## Protocol

This WebSocket API uses a bidirectional protocol that encodes all messages as JSON objects. Each message includes a `messageType` attribute for handling message types appropriately.

## Subscribe

Send a subscribe message with the appropriate `messageType` to specify which channel you want to receive.

### Customer-specific market data

Subscribes to market data scoped to a specific account or subaccount by passing either the optional `accountId` or `subaccountId` field.

**By account:**

```json theme={null}
{
  "messageType": "MarketDataSnapshotRequest",
  "timestamp": "2023-01-24T08:22:18.598364",
  "payload": {
    "type": "subscribe",
    "symbol": "BTC-USD",
    "reqId": "0d921bca-6599-4841-95ee-7b6984e2486f",
    "accountId": "f7823b57-aeb2-11f0-a565-3ecdccd5480d"
  }
}
```

**By subaccount:**

```json theme={null}
{
  "messageType": "MarketDataSnapshotRequest",
  "timestamp": "2023-01-24T08:22:18.598364",
  "payload": {
    "type": "subscribe",
    "symbol": "BTC-USD",
    "reqId": "0d921bca-6599-4841-95ee-7b6984e2486f",
    "subaccountId": "5db3bae2-c3c6-4d7d-97af-47c923135661"
  }
}
```

| Field          | Type          | Required  | Description                                                                                   |
| -------------- | ------------- | --------- | --------------------------------------------------------------------------------------------- |
| `symbol`       | string        | <Check /> | Trading pair, 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. |

<Info>
  `subaccountId` applies to RIA customers only.
</Info>

### Global market data

Subscribes to market data without any account filter. All participants receive the same feed.

```json theme={null}
{
  "messageType": "MarketDataSnapshotRequest",
  "timestamp": "2023-01-24T08:22:18.598364",
  "payload": {
    "type": "subscribe",
    "symbol": "BTC-USD",
    "reqId": "0d921bca-6599-4841-95ee-7b6984e2486f"
  }
}
```

## Unsubscribe

To unsubscribe from a channel, send an unsubscribe message with the same `symbol`. The `reqId` does not need to match the original subscription request.

```json theme={null}
{
  "messageType": "MarketDataSnapshotRequest",
  "timestamp": "2023-01-24T09:04:57.146353",
  "payload": {
    "type": "unsubscribe",
    "symbol": "BTC-USD",
    "reqId": "88f401f3-f0d1-4f1d-85cc-3d0b377e8c9a"
  }
}
```

## Sequence numbers

Messages include a sequence number: an incrementing integer starting at `1`. Each message is exactly one greater than the previous.

## Supported channels

| Channel                   | Description          |
| ------------------------- | -------------------- |
| MarketDataSnapshotRequest | Market depth updates |
