Skip to Content
API ReferenceREST APIWebSocket Endpoints

WebSocket Endpoints

The Nord API provides WebSocket connections for real-time data streaming.

Base URLs

EnvironmentURL
Mainnetwss://zo-mainnet.n1.xyz
Devnetwss://zo-devnet.n1.xyz

Candle Data Stream

Stream real-time candlestick (OHLCV) data for charting.

Endpoint

wss://{host}/ws/candle@{symbol}:{resolution}

Parameters:

NameTypeDescription
symbolstringTrading pair (e.g., “BTCUSD”, “ETHUSD”)
resolutionstringTimeframe: “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:

FieldTypeDescription
resstringResolution/timeframe
midnumberMarket ID
tnumberCandle timestamp (Unix seconds)
onumberOpen price
hnumberHigh price
lnumberLow price
cnumberClose price
vnumberVolume (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

  1. Reconnection: Implement automatic reconnection with exponential backoff
  2. Heartbeat: The server may send periodic pings; respond with pongs to keep the connection alive
  3. Single connection per stream: Each WebSocket connection handles one symbol/resolution pair
  4. 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