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

# Asset prices

> Live crypto and FX price feeds

## Overview

The `/ws/v1/realtime` endpoint streams live asset prices. No authentication is required. Prices update approximately every second per symbol.

```
wss://socket.bayse.markets/ws/v1/realtime
```

## Available symbols

| Source     | Symbols                                |
| ---------- | -------------------------------------- |
| Binance    | `BTCUSDT`, `ETHUSDT`, `SOLUSDT`        |
| TwelveData | `XAUUSD`, `EURUSD`, `GBPUSD`, `USDNGN` |

## Subscribe

Send a `subscribe` message with the symbols you want to track:

```json theme={null}
{
  "type": "subscribe",
  "channel": "asset_prices",
  "symbols": ["BTCUSDT", "ETHUSDT", "SOLUSDT"]
}
```

You can subscribe to one or more symbols in a single message.

## Events received

**`asset_price`** — A price tick for a subscribed symbol.

```json theme={null}
{
  "type": "asset_price",
  "data": {
    "symbol": "BTCUSDT",
    "price": 67432.15,
    "timestamp": 1700000000000
  },
  "timestamp": 1700000000000
}
```

| Field            | Description                        |
| ---------------- | ---------------------------------- |
| `data.symbol`    | The ticker symbol.                 |
| `data.price`     | Current price.                     |
| `data.timestamp` | Source event time in milliseconds. |
| `timestamp`      | Server timestamp in milliseconds.  |

## Unsubscribe

Each symbol has its own room. To unsubscribe from a specific symbol:

```json theme={null}
{ "type": "unsubscribe", "room": "asset_prices:BTCUSDT" }
```

## Full example

<CodeGroup>
  ```javascript JavaScript theme={null}
  const ws = new WebSocket("wss://socket.bayse.markets/ws/v1/realtime");

  ws.addEventListener("open", () => {
    ws.send(JSON.stringify({
      type: "subscribe",
      channel: "asset_prices",
      symbols: ["BTCUSDT", "ETHUSDT", "SOLUSDT"]
    }));
  });

  ws.addEventListener("message", (event) => {
    for (const line of event.data.split("\n")) {
      if (!line.trim()) continue;
      const msg = JSON.parse(line);

      if (msg.type === "asset_price") {
        console.log(`${msg.data.symbol}: $${msg.data.price}`);
      }
    }
  });
  ```

  ```python Python theme={null}
  import asyncio
  import json
  import websockets

  async def stream_prices():
      async with websockets.connect("wss://socket.bayse.markets/ws/v1/realtime") as ws:
          await ws.send(json.dumps({
              "type": "subscribe",
              "channel": "asset_prices",
              "symbols": ["BTCUSDT", "ETHUSDT", "SOLUSDT"]
          }))

          async for message in ws:
              for line in message.split("\n"):
                  if not line.strip():
                      continue
                  msg = json.loads(line)

                  if msg["type"] == "asset_price":
                      data = msg["data"]
                      print(f"{data['symbol']}: ${data['price']}")

  asyncio.run(stream_prices())
  ```

  ```go Go theme={null}
  package main

  import (
  	"encoding/json"
  	"fmt"
  	"log"
  	"strings"

  	"github.com/gorilla/websocket"
  )

  func main() {
  	conn, _, err := websocket.DefaultDialer.Dial(
  		"wss://socket.bayse.markets/ws/v1/realtime", nil,
  	)
  	if err != nil {
  		log.Fatal(err)
  	}
  	defer conn.Close()

  	conn.WriteJSON(map[string]any{
  		"type":    "subscribe",
  		"channel": "asset_prices",
  		"symbols": []string{"BTCUSDT", "ETHUSDT", "SOLUSDT"},
  	})

  	for {
  		_, data, err := conn.ReadMessage()
  		if err != nil {
  			log.Fatal(err)
  		}
  		for _, line := range strings.Split(string(data), "\n") {
  			if strings.TrimSpace(line) == "" {
  				continue
  			}
  			var msg map[string]any
  			json.Unmarshal([]byte(line), &msg)

  			if msg["type"] == "asset_price" {
  				d := msg["data"].(map[string]any)
  				fmt.Printf("%s: %v\n", d["symbol"], d["price"])
  			}
  		}
  	}
  }
  ```
</CodeGroup>
