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

# Connect to the WebSocket Market Data Feed

> Open a WebSocket connection to the Sandbox BTC Market Data feed.

Use the command line to open a WebSocket connection to the Sandbox BTC Market Data Feed.

> See the [WebSocket API reference](/guides/developer/api-websocket) for more details.

## ➊ Install WebSocket Client

The quickest way to open a connection is by using [wscat](https://github.com/websockets/wscat), which runs in the terminal.
Using the Python [websocket-client](https://pypi.org/project/websocket-client) package requires a bit of code and the Python shell.

<Tabs>
  <Tab title="SHELL">
    Open the terminal and install [wscat](https://github.com/websockets/wscat) using the `-g` (global) flag.

    ```shell theme={null}
    npm install -g wscat
    ```

    Ensure [wscat](https://github.com/websockets/wscat) is working. If you see the version number, the module is working:

    ```shell theme={null}
    wscat --version
    ```
  </Tab>

  <Tab title="PYTHON">
    Open the terminal and install the Python3 [websocket-client](https://pypi.org/project/websocket-client) library.

    ```shell theme={null}
    pip3 install websocket-client
    ```

    Start the Python3 shell and check that [websocket-client](https://pypi.org/project/websocket-client) was installed correctly.
    If you don't see a `ModuleNotFoundError` message, the library is installed.

    ```py theme={null}
    python3
    ...
    >>> import websocket
    >>> 
    ```
  </Tab>
</Tabs>

Leave the terminal window open.

## ➋ Connect to Sandbox Feed

Open a long-lived connection to the Sandbox BTC Market Data Feed.

<Tabs>
  <Tab title="SHELL">
    ```shell theme={null}
    wscat --connect wss://ws.sandbox.paxos.com/marketdata/BTCUSD
    ```
  </Tab>

  <Tab title="PYTHON">
    ```py theme={null}
    >>> import websocket # From the previous step
    >>> def on_message(wsapp, message):
    ...     print(message)
    ...
    >>> wsapp = websocket.WebSocketApp("wss://ws.sandbox.paxos.com/marketdata/BTCUSD", on_message=on_message)
    >>> wsapp.run_forever() # Press CTRL+C to quit
    ```
  </Tab>
</Tabs>

## ➌ Review Sandbox Feed

If everything worked, you see the initial `SNAPSHOT` and then an `UPDATE` stream in the terminal.

<Tabs>
  <Tab title="SHELL">
    ```json title="Sandbox BTC Market Data Feed (wscat)" theme={null}
    Connected (press CTRL+C to quit)
    < {
        "type": "SNAPSHOT",
        "market": "BTCUSD",
        "bids": [
          {
            "price": "19994.25",
            "amount": "0.7755"
          },
          {
            "price": "19993.75",
            "amount": "0.83676985"
          },
          ...
        ],
        "asks": [
          {
            "price": "19994.5",
            "amount": "0.97548541"
          },  
          {
            "price": "19996",
            "amount": "1.135"
          },
          ...
        ],
        "final_snapshot": true
      }

    < {
        "type": "UPDATE",
        "market": "BTCUSD",
        "side": "BUY",
        "price": "19958.5",
        "amount": "0.62649999"
      }

    < {
        "type": "UPDATE",
        "market": "BTCUSD",
        "side": "SELL",
        "price": "20115.25",
        "amount": "0"
      }
      ...
    ```
  </Tab>

  <Tab title="PYTHON">
    ```json title="Sandbox BTC Market Data Feed (websocket-client)" theme={null}
    {
      "type": "SNAPSHOT",
      "market": "BTCUSD",
      "bids": [
        {
          "price": "19994.25",
          "amount": "0.7755"
        },
        {
          "price": "19993.75",
          "amount": "0.83676985"
        },
        ...
      ],
      "asks": [
        {
          "price": "19994.5",
          "amount": "0.97548541"
        },
        {
          "price": "19996",
          "amount": "1.135"
        },
        ...
      ],
      "final_snapshot": true
    }

    {
      "type": "UPDATE",
      "market": "BTCUSD",
      "side": "BUY",
      "price": "19958.5",
      "amount": "0.62649999"
    }

    {
      "type": "UPDATE",
      "market": "BTCUSD",
      "side": "SELL",
      "price": "20115.25",
      "amount": "0"
    }
    ...
    ```
  </Tab>
</Tabs>
