Chart Live WebSocket Service
Real-time candlestick chart data service for tokens via WebSocket connections.
WebSocket Endpoint
wss://api.solapi.live/ws/chart-liveAuthentication is required using the x-api-key header.
Connection and Subscription
1 Connect to the WebSocket endpoint
You'll receive a welcome message:
{
"type": "connected",
"message": "Connected to ChartLive WebSocket. Send a JSON object with
\"tokenAddress\" and optional \"timeframe\"."
}2 Send subscription message
{
"tokenAddress": "TOKEN_ADDRESS",
"timeframe": 60 // Optional, defaults to 60 seconds
}3 Receive confirmation
{
"type": "subscriptionConfirmed",
"message": "Subscribed to TOKEN_ADDRESS with 60s timeframe"
}4 Receive real-time candlestick data
{
"event": "chart",
"tokenAddress": "TOKEN_ADDRESS",
"quoteToken": "So11111111111111111111111111111111111111112",
"timeframe": 60,
"candle": {
"time": 1746026160000,
"datetime": "2025-04-30T15:16:00.000Z",
"open": 0.00009366684363629061,
"high": 0.00009366684363629061,
"low": 0.0000854575124444221,
"close": 0.00008664663888027205,
"volume": 2667017166926,
"volumeUsd": 233.23113453442505,
"trades": 6,
"buys": 3,
"sells": 3
}
}Candle Fields
| Field | Description |
|---|---|
| time | Unix timestamp in milliseconds |
| datetime | ISO 8601 formatted date-time string |
| open | Opening price of the candle |
| high | Highest price during the candle period |
| low | Lowest price during the candle period |
| close | Closing price of the candle |
| volume | Total trading volume in base token units |
| volumeUsd | Total trading volume in USD |
| trades | Total number of trades in the period |
| buys | Number of buy trades |
| sells | Number of sell trades |
Example Usage
import WebSocket from 'ws';
const TOKEN_ADDRESS = 'TOKEN_ADDRESS';
const TIMEFRAME = 1; // 1 second candles
const API_KEY = 'YOUR_API_KEY';
console.log(`Starting WebSocket client for ${TOKEN_ADDRESS} with ${TIMEFRAME}s timeframe`);
let ws = null;
let isSubscribed = false;
function connect() {
if (ws) {
console.log('WebSocket already exists, closing previous connection...');
ws.close();
}
// Create WebSocket connection with API key
ws = new WebSocket('wss://api.solapi.live/ws/chart-live', {
headers: {
'x-api-key': API_KEY
}
});
ws.on('open', () => {
console.log('Connected to WebSocket server');
if (!isSubscribed) {
// Send subscription message
const message = {
tokenAddress: TOKEN_ADDRESS,
timeframe: TIMEFRAME
};
ws.send(JSON.stringify(message));
isSubscribed = true;
}
});
ws.on('message', (data) => {
try {
const message = JSON.parse(data.toString());
if (message.type === 'connected' || message.type === 'subscriptionConfirmed' || message.type === 'error') {
console.log(message.message);
} else {
console.log(JSON.stringify(message, null, 2)); // Chart data
}
} catch (error) {
console.error('Error parsing message:', error.message);
}
});
ws.on('error', (error) => {
console.error('WebSocket error:', error.message);
});
ws.on('close', (code, reason) => {
console.log('Disconnected');
isSubscribed = false;
// Attempt to reconnect after a delay
setTimeout(connect, 5000);
});
}
// Initial connection
connect();
// Handle SIGINT for graceful shutdown
process.on('SIGINT', () => {
console.log('Closing connection...');
if (ws) {
ws.close();
}
process.exit(0);
});Error Messages
If an error occurs, you'll receive a message in this format:
{
"type": "error",
"message": "Error description"
}Common errors:
- Missing tokenAddress in subscription message
- Invalid JSON format
- Invalid timeframe values
- Token not found or not tracked
- Authentication failure