WebSocket Endpoints
The Nord API provides WebSocket connections for real-time data streaming.
Base URLs
| Environment | URL |
|---|---|
| Mainnet | wss://zo-mainnet.n1.xyz |
| Devnet | wss://zo-devnet.n1.xyz |
Candle Data Stream
Stream real-time candlestick (OHLCV) data for charting.
Endpoint
wss://{host}/ws/candle@{symbol}:{resolution}Parameters:
| Name | Type | Description |
|---|---|---|
symbol | string | Trading pair (e.g., “BTCUSD”, “ETHUSD”) |
resolution | string | Timeframe: “1”, “5”, “15”, “60”, “240”, “1D” |
Message Format
{
"res": "1",
"mid": 0,
"t": 1705312800,
"o": 97500.0,
"h": 97550.0,
"l": 97480.0,
"c": 97520.0,
"v": 125.5
}Fields:
| Field | Type | Description |
|---|---|---|
res | string | Resolution/timeframe |
mid | number | Market ID |
t | number | Candle timestamp (Unix seconds) |
o | number | Open price |
h | number | High price |
l | number | Low price |
c | number | Close price |
v | number | Volume (optional) |
Example: JavaScript
const ws = new WebSocket("wss://zo-mainnet.n1.xyz/ws/candle@BTCUSD:1");
ws.onopen = () => {
console.log("Connected to BTCUSD 1m candles");
};
ws.onmessage = (event) => {
const candle = JSON.parse(event.data);
console.log(`${new Date(candle.t * 1000).toLocaleTimeString()} | O: ${candle.o} H: ${candle.h} L: ${candle.l} C: ${candle.c}`);
};
ws.onclose = () => {
console.log("Connection closed");
};Example: Python
import asyncio
import websockets
import json
async def stream_candles():
uri = "wss://zo-mainnet.n1.xyz/ws/candle@BTCUSD:1"
async with websockets.connect(uri) as ws:
print("Connected to BTCUSD 1m candles")
async for message in ws:
candle = json.loads(message)
print(f"O: {candle['o']:.1f} H: {candle['h']:.1f} L: {candle['l']:.1f} C: {candle['c']:.1f}")
asyncio.run(stream_candles())Connection Best Practices
- Reconnection: Implement automatic reconnection with exponential backoff
- Heartbeat: The server may send periodic pings; respond with pongs to keep the connection alive
- Single connection per stream: Each WebSocket connection handles one symbol/resolution pair
- Resource cleanup: Close connections when switching symbols or when the component unmounts
Example: Reconnecting Client
import asyncio
import websockets
import json
async def resilient_stream(symbol: str, resolution: str):
uri = f"wss://zo-mainnet.n1.xyz/ws/candle@{symbol}:{resolution}"
retry_delay = 1
while True:
try:
async with websockets.connect(uri) as ws:
print(f"Connected to {symbol} {resolution} stream")
retry_delay = 1 # Reset on successful connection
async for message in ws:
candle = json.loads(message)
yield candle
except websockets.ConnectionClosed:
print(f"Connection closed, reconnecting in {retry_delay}s...")
await asyncio.sleep(retry_delay)
retry_delay = min(retry_delay * 2, 30) # Max 30s delay
async def main():
async for candle in resilient_stream("BTCUSD", "1"):
print(f"Price: ${candle['c']:,.1f}")
asyncio.run(main())Last updated on