Appearance
Trade Channel
wss://api.valr.com/ws/tradeThe Trade WebSocket channel provides real-time market data including order book updates, trades, and market summaries.
Authentication
The Trade channel supports both authenticated and unauthenticated connections. Unauthenticated connections can receive all market data events but are automatically disconnected after 15 minutes.
To authenticate (optional):
Connection Headers
Authentication is performed by passing HTTP headers during the WebSocket handshake. The following headers are required:
| Header | Description |
|---|---|
X-VALR-API-KEY | Your API key |
X-VALR-SIGNATURE | HMAC-SHA512 signature (see below) |
X-VALR-TIMESTAMP | Current Unix timestamp in milliseconds |
The signature is computed as:
Signature = HMAC-SHA512(API_SECRET, TIMESTAMP + "GET" + "/ws/trade")Example connection:
javascript
const WebSocket = require('ws');
const headers = {
'X-VALR-API-KEY': 'YOUR_API_KEY',
'X-VALR-SIGNATURE': signature,
'X-VALR-TIMESTAMP': timestamp
};
const ws = new WebSocket('wss://api.valr.com/ws/trade', { headers });Subscribing to Events
All Trade channel events require an explicit subscription. You can optionally filter by currency pairs:
json
{
"type": "SUBSCRIBE",
"subscriptions": [
{
"event": "AGGREGATED_ORDERBOOK_UPDATE",
"pairs": ["BTCZAR", "ETHZAR"]
},
{
"event": "NEW_TRADE",
"pairs": ["BTCZAR"]
},
{
"event": "MARKET_SUMMARY_UPDATE"
}
]
}If pairs is omitted, you receive events for all available currency pairs.
To unsubscribe from an event, send a SUBSCRIBE message with an empty pairs array for that event. This removes all pair subscriptions, effectively unsubscribing you:
json
{
"type": "SUBSCRIBE",
"subscriptions": [
{
"event": "AGGREGATED_ORDERBOOK_UPDATE",
"pairs": []
}
]
}Events
| Event | Description |
|---|---|
AGGREGATED_ORDERBOOK_UPDATE | Full order book aggregated by price level |
NEW_TRADE | New trades with price, quantity, and taker side |
MARKET_SUMMARY_UPDATE | Market statistics including bid/ask, volume, and 24-hour change |
Message Format
Trade events include the currency pair in the message:
json
{
"type": "EVENT_TYPE",
"currencyPairSymbol": "BTCZAR",
"data": { ... }
}For full payload schemas, see the individual operation pages in the sidebar.