Chart Live WebSocket Service

Real-time candlestick chart data service for tokens via WebSocket connections.

WebSocket Endpoint

wss://api.solapi.live/ws/chart-live

Authentication 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

FieldDescription
timeUnix timestamp in milliseconds
datetimeISO 8601 formatted date-time string
openOpening price of the candle
highHighest price during the candle period
lowLowest price during the candle period
closeClosing price of the candle
volumeTotal trading volume in base token units
volumeUsdTotal trading volume in USD
tradesTotal number of trades in the period
buysNumber of buy trades
sellsNumber 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