Overview
ChainStream DEX WebSocket API provides real-time data subscription services, supporting the following data types:
- Candle Data
- Token Series
- Wallet Series
- Ranking Series
- Trade Series
- DexPool Series
Base URL
wss://realtime-dex.chainstream.io/connection/websocket
Quick Start
1. Establish Connection
First, create a WebSocket connection. WebSocket connections require the token query parameter in the URL for authentication.
Using SDK (Recommended)
Using Native WebSocket
Command Line Testing
If using the Go or JavaScript SDK, authentication is handled automatically:import { ChainStreamClient } from '@chainstream-io/sdk';
import { Resolution } from '@chainstream-io/sdk/openapi';
const client = new ChainStreamClient('YOUR_ACCESS_TOKEN');
// Just subscribe directly, SDK handles WebSocket connection and authentication automatically
client.stream.subscribeTokenCandles({
chain: 'sol',
tokenAddress: '6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN',
resolution: Resolution._1m,
callback: (data) => {
console.log('Received data:', data);
}
});
When calling subscribeXXX methods, SDK automatically checks connection status and establishes connection if not connected. No need to manually call connect().
SDK Installation:
- JavaScript:
npm install @chainstream-io/sdk (npm)
- Go:
go get github.com/chainstream-io/chainstream-go-sdk (GitHub)
When using browser native WebSocket or other WebSocket libraries, append the token parameter to the URL:// Works in both browser and Node.js
const token = 'YOUR_ACCESS_TOKEN';
const ws = new WebSocket(
`wss://realtime-dex.chainstream.io/connection/websocket?token=${token}`
);
ws.onopen = () => {
console.log('Connection established');
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Received data:', data);
};
By passing the token via URL parameter, both browser native WebSocket and various third-party libraries can be used without special header handling.
Using wscat for testing:$ wscat -c "wss://realtime-dex.chainstream.io/connection/websocket?token=YOUR_ACCESS_TOKEN"
2. Subscribe to Data
Choose the data type you want to subscribe to:
// Example of subscribing to candle data
ws.send(JSON.stringify({
type: "subscribe",
channel: "dex-candle:sol_6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN_1m"
}));
3. Handle Data
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Received data:', data);
};
Data Subscriptions
Candles
Candles Data
Get real-time price movement data for tokens.
Subscription Format
dex-candle:{chain}_{tokenAddress}_{resolution}
Parameters
Blockchain name, e.g., sol
Token contract address, e.g., 6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN
Candle period, supports: 1m, 5m, 15m, 1h, 4h, 1d
Optional filter condition using Google Common Expression Language (CEL) syntax. Example: volume > 1000
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names to improve code readability.
{
"o": number, // Open price
"c": number, // Close price
"h": number, // High price
"l": number, // Low price
"v": number, // Volume
"r": string, // Resolution
"t": number // Timestamp
}
{
"open": number, // Open price
"close": number, // Close price
"high": number, // High price
"low": number, // Low price
"volume": number, // Volume
"resolution": string, // Resolution
"time": number // Timestamp
}
Token Series
Token Stats
Get real-time market statistics for tokens.
Subscription Format
dex-token-stats:{chain}_{tokenAddress}
Parameters
Blockchain name, e.g., sol
Token contract address, e.g., 6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN
Optional filter condition using Google Common Expression Language (CEL) syntax. Example: price > 0.01
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names to improve code readability.
{
"a": string, // Token address
"t": number, // Timestamp
"b1m": number, // Buys in 1m
"s1m": number, // Sells in 1m
"be1m": number, // Buyers in 1m
"se1m": number, // Sellers in 1m
"bviu1m": number, // Buy volume in USD 1m
"sviu1m": number, // Sell volume in USD 1m
"p1m": number, // Price 1m
"oiu1m": number, // Open price in USD 1m
"ciu1m": number, // Close price in USD 1m
"b5m": number, // Buys in 5m
"s5m": number, // Sells in 5m
"be5m": number, // Buyers in 5m
"se5m": number, // Sellers in 5m
"bviu5m": number, // Buy volume in USD 5m
"sviu5m": number, // Sell volume in USD 5m
"p5m": number, // Price 5m
"oiu5m": number, // Open price in USD 5m
"ciu5m": number, // Close price in USD 5m
"b15m": number, // Buys in 15m
"s15m": number, // Sells in 15m
"be15m": number, // Buyers in 15m
"se15m": number, // Sellers in 15m
"bviu15m": number,// Buy volume in USD 15m
"sviu15m": number,// Sell volume in USD 15m
"p15m": number, // Price 15m
"oiu15m": number, // Open price in USD 15m
"ciu15m": number, // Close price in USD 15m
"b30m": number, // Buys in 30m
"s30m": number, // Sells in 30m
"be30m": number, // Buyers in 30m
"se30m": number, // Sellers in 30m
"bviu30m": number,// Buy volume in USD 30m
"sviu30m": number,// Sell volume in USD 30m
"p30m": number, // Price 30m
"oiu30m": number, // Open price in USD 30m
"ciu30m": number, // Close price in USD 30m
"b1h": number, // Buys in 1h
"s1h": number, // Sells in 1h
"be1h": number, // Buyers in 1h
"se1h": number, // Sellers in 1h
"bviu1h": number, // Buy volume in USD 1h
"sviu1h": number, // Sell volume in USD 1h
"p1h": number, // Price 1h
"oiu1h": number, // Open price in USD 1h
"ciu1h": number, // Close price in USD 1h
"b4h": number, // Buys in 4h
"s4h": number, // Sells in 4h
"be4h": number, // Buyers in 4h
"se4h": number, // Sellers in 4h
"bviu4h": number, // Buy volume in USD 4h
"sviu4h": number, // Sell volume in USD 4h
"p4h": number, // Price 4h
"oiu4h": number, // Open price in USD 4h
"ciu4h": number, // Close price in USD 4h
"b24h": number, // Buys in 24h
"s24h": number, // Sells in 24h
"be24h": number, // Buyers in 24h
"se24h": number, // Sellers in 24h
"bviu24h": number,// Buy volume in USD 24h
"sviu24h": number,// Sell volume in USD 24h
"p24h": number, // Price 24h
"oiu24h": number, // Open price in USD 24h
"ciu24h": number, // Close price in USD 24h
"p": number // Current price
}
{
"address": string, // Token address
"timestamp": number, // Timestamp
"buys1m": number, // Buys in 1m
"sells1m": number, // Sells in 1m
"buyers1m": number, // Buyers in 1m
"sellers1m": number, // Sellers in 1m
"buyVolumeInUsd1m": number, // Buy volume in USD 1m
"sellVolumeInUsd1m": number,// Sell volume in USD 1m
"price1m": number, // Price 1m
"openInUsd1m": number, // Open price in USD 1m
"closeInUsd1m": number, // Close price in USD 1m
"buys5m": number, // Buys in 5m
"sells5m": number, // Sells in 5m
"buyers5m": number, // Buyers in 5m
"sellers5m": number, // Sellers in 5m
"buyVolumeInUsd5m": number, // Buy volume in USD 5m
"sellVolumeInUsd5m": number,// Sell volume in USD 5m
"price5m": number, // Price 5m
"openInUsd5m": number, // Open price in USD 5m
"closeInUsd5m": number, // Close price in USD 5m
"buys15m": number, // Buys in 15m
"sells15m": number, // Sells in 15m
"buyers15m": number, // Buyers in 15m
"sellers15m": number, // Sellers in 15m
"buyVolumeInUsd15m": number,// Buy volume in USD 15m
"sellVolumeInUsd15m": number,// Sell volume in USD 15m
"price15m": number, // Price 15m
"openInUsd15m": number, // Open price in USD 15m
"closeInUsd15m": number, // Close price in USD 15m
"buys30m": number, // Buys in 30m
"sells30m": number, // Sells in 30m
"buyers30m": number, // Buyers in 30m
"sellers30m": number, // Sellers in 30m
"buyVolumeInUsd30m": number,// Buy volume in USD 30m
"sellVolumeInUsd30m": number,// Sell volume in USD 30m
"price30m": number, // Price 30m
"openInUsd30m": number, // Open price in USD 30m
"closeInUsd30m": number, // Close price in USD 30m
"buys1h": number, // Buys in 1h
"sells1h": number, // Sells in 1h
"buyers1h": number, // Buyers in 1h
"sellers1h": number, // Sellers in 1h
"buyVolumeInUsd1h": number, // Buy volume in USD 1h
"sellVolumeInUsd1h": number,// Sell volume in USD 1h
"price1h": number, // Price 1h
"openInUsd1h": number, // Open price in USD 1h
"closeInUsd1h": number, // Close price in USD 1h
"buys4h": number, // Buys in 4h
"sells4h": number, // Sells in 4h
"buyers4h": number, // Buyers in 4h
"sellers4h": number, // Sellers in 4h
"buyVolumeInUsd4h": number, // Buy volume in USD 4h
"sellVolumeInUsd4h": number,// Sell volume in USD 4h
"price4h": number, // Price 4h
"openInUsd4h": number, // Open price in USD 4h
"closeInUsd4h": number, // Close price in USD 4h
"buys24h": number, // Buys in 24h
"sells24h": number, // Sells in 24h
"buyers24h": number, // Buyers in 24h
"sellers24h": number, // Sellers in 24h
"buyVolumeInUsd24h": number,// Buy volume in USD 24h
"sellVolumeInUsd24h": number,// Sell volume in USD 24h
"price24h": number, // Price 24h
"openInUsd24h": number, // Open price in USD 24h
"closeInUsd24h": number, // Close price in USD 24h
"price": number // Current price
}
Token Holders Statistics
Get real-time token holder statistics.
Subscription Format
dex-token-holding:{chain}_{tokenAddress}
Parameters
Blockchain name, e.g., sol
Token contract address, e.g., 6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN
Optional filter condition using Google Common Expression Language (CEL) syntax. Example: holders > 200
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names to improve code readability.
{
"a": string, // Token address
"h": number, // Number of holders
"t100a": number, // Top 100 holders total amount
"t10a": number, // Top 10 holders total amount
"t100h": number, // Top 100 holders count
"t10h": number, // Top 10 holders count
"t100r": number, // Top 100 holders ratio
"t10r": number, // Top 10 holders ratio
"ch": number, // Creators holders count
"ca": number, // Creators amount
"cr": number, // Creators ratio
"ts": number // Timestamp
}
{
"tokenAddress": string, // Token address
"holders": number, // Number of holders
"top100Amount": number, // Top 100 holders total amount
"top10Amount": number, // Top 10 holders total amount
"top100Holders": number, // Top 100 holders count
"top10Holders": number, // Top 10 holders count
"top100Ratio": number, // Top 100 holders ratio
"top10Ratio": number, // Top 10 holders ratio
"creatorsHolders": number, // Creators holders count
"creatorsAmount": number, // Creators amount
"creatorsRatio": number, // Creators ratio
"timestamp": number // Timestamp
}
Get real-time metadata for newly listed tokens.
Subscription Format
dex-new-tokens-metadata:{chain}
Parameters
Blockchain name, e.g., sol
Optional filter condition using Google Common Expression Language (CEL) syntax. Example: name == “USDC”
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names to improve code readability.
[
{
"a": string, // Token address
"n": string, // Name
"s": string, // Symbol
"iu": string, // Image URL
"de": string, // Description
"sm": { // Social media
"tw": string, // Twitter
"tg": string, // Telegram
"w": string, // Website
"tt": string, // TikTok
"dc": string, // Discord
"fb": string, // Facebook
"gh": string, // GitHub
"ig": string, // Instagram
"li": string, // LinkedIn
"md": string, // Medium
"rd": string, // Reddit
"yt": string, // YouTube
"bb": string // BitBucket
},
"cts": number // Created timestamp (ms)
}
]
[
{
"tokenAddress": string, // Token address
"name": string, // Name
"symbol": string, // Symbol
"imageUrl": string, // Image URL
"description": string, // Description
"socialMedia": { // Social media
"twitter": string, // Twitter
"telegram": string, // Telegram
"website": string, // Website
"tiktok": string, // TikTok
"discord": string, // Discord
"facebook": string, // Facebook
"github": string, // GitHub
"instagram": string, // Instagram
"linkedin": string, // LinkedIn
"medium": string, // Medium
"reddit": string, // Reddit
"youtube": string, // YouTube
"bitbucket": string // BitBucket
},
"createdAtMs": number // Created timestamp (ms)
}
]
New Token
Get information about newly created token.
Subscription Format
Parameters
Blockchain name, e.g., sol
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names to improve code readability.
{
"a": string, // Token address
"n": string, // Name
"s": string, // Symbol
"dec": number, // Decimals
"cts": number, // Created timestamp (ms)
"lf": { // Launch from information
"pa": string, // Program address
"pf": string, // Protocol family
"pn": string // Protocol name
}
}
{
"tokenAddress": string, // Token address
"name": string, // Name
"symbol": string, // Symbol
"decimals": number, // Decimals
"createdAtMs": number, // Created timestamp (ms)
"launchFrom": { // Launch from information
"programAddress": string, // Program address
"protocolFamily": string, // Protocol family
"protocolName": string // Protocol name
}
}
Token Supply
Get real-time token supply and market cap information.
Subscription Format
dex-token-supply:{chain}_{tokenAddress}
Parameters
Blockchain name, e.g., sol
Token contract address, e.g., 6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN
Optional filter condition using Google Common Expression Language (CEL) syntax. Example: supply > 1000000
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names for better code readability.
{
"a": string, // Token address
"s": number, // Supply
"mc": number, // Market cap in USD
"ts": number // Timestamp
}
{
"tokenAddress": string, // Token address
"supply": number, // Supply
"marketCapInUsd": number, // Market cap in USD
"timestamp": number // Timestamp
}
Token Liquidity
Get real-time token liquidity statistics.
Subscription Format
dex-token-general-stat-num:{chain}_{tokenAddress}
Parameters
Blockchain name, e.g., sol
Optional filter condition using Google Common Expression Language (CEL) syntax. Example: value > 1000000
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names for better code readability.
{
"a": string, // Token address
"t": string, // Metric type
"v": number, // Value
"ts": number // Timestamp
}
{
"tokenAddress": string, // Token address
"metricType": string, // Metric type
"value": number, // Value
"timestamp": number // Timestamp
}
Ranking Series
Ranking Token Statistics
Get real-time market statistics for ranking tokens.
Subscription Format
dex-ranking-token-stats-list:{chain}_{channelType}
Parameters
Blockchain name, e.g., sol
Channel type, support:new、trending、us_stocks、completed、graduated
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names to improve code readability.
[
{
"a": string, // Token address
"t": number, // Timestamp
"b1m": number, // Buys in 1m
"s1m": number, // Sells in 1m
"be1m": number, // Buyers in 1m
"se1m": number, // Sellers in 1m
"bviu1m": number, // Buy volume in USD 1m
"sviu1m": number, // Sell volume in USD 1m
"p1m": number, // Price 1m
"oiu1m": number, // Open price in USD 1m
"ciu1m": number, // Close price in USD 1m
"b5m": number, // Buys in 5m
"s5m": number, // Sells in 5m
"be5m": number, // Buyers in 5m
"se5m": number, // Sellers in 5m
"bviu5m": number, // Buy volume in USD 5m
"sviu5m": number, // Sell volume in USD 5m
"p5m": number, // Price 5m
"oiu5m": number, // Open price in USD 5m
"ciu5m": number, // Close price in USD 5m
"b15m": number, // Buys in 15m
"s15m": number, // Sells in 15m
"be15m": number, // Buyers in 15m
"se15m": number, // Sellers in 15m
"bviu15m": number,// Buy volume in USD 15m
"sviu15m": number,// Sell volume in USD 15m
"p15m": number, // Price 15m
"oiu15m": number, // Open price in USD 15m
"ciu15m": number, // Close price in USD 15m
"b30m": number, // Buys in 30m
"s30m": number, // Sells in 30m
"be30m": number, // Buyers in 30m
"se30m": number, // Sellers in 30m
"bviu30m": number,// Buy volume in USD 30m
"sviu30m": number,// Sell volume in USD 30m
"p30m": number, // Price 30m
"oiu30m": number, // Open price in USD 30m
"ciu30m": number, // Close price in USD 30m
"b1h": number, // Buys in 1h
"s1h": number, // Sells in 1h
"be1h": number, // Buyers in 1h
"se1h": number, // Sellers in 1h
"bviu1h": number, // Buy volume in USD 1h
"sviu1h": number, // Sell volume in USD 1h
"p1h": number, // Price 1h
"oiu1h": number, // Open price in USD 1h
"ciu1h": number, // Close price in USD 1h
"b4h": number, // Buys in 4h
"s4h": number, // Sells in 4h
"be4h": number, // Buyers in 4h
"se4h": number, // Sellers in 4h
"bviu4h": number, // Buy volume in USD 4h
"sviu4h": number, // Sell volume in USD 4h
"p4h": number, // Price 4h
"oiu4h": number, // Open price in USD 4h
"ciu4h": number, // Close price in USD 4h
"b24h": number, // Buys in 24h
"s24h": number, // Sells in 24h
"be24h": number, // Buyers in 24h
"se24h": number, // Sellers in 24h
"bviu24h": number,// Buy volume in USD 24h
"sviu24h": number,// Sell volume in USD 24h
"p24h": number, // Price 24h
"oiu24h": number, // Open price in USD 24h
"ciu24h": number, // Close price in USD 24h
"p": number // Current price
}
]
[
{
"address": string, // Token address
"timestamp": number, // Timestamp
"buys1m": number, // Buys in 1m
"sells1m": number, // Sells in 1m
"buyers1m": number, // Buyers in 1m
"sellers1m": number, // Sellers in 1m
"buyVolumeInUsd1m": number, // Buy volume in USD 1m
"sellVolumeInUsd1m": number,// Sell volume in USD 1m
"price1m": number, // Price 1m
"openInUsd1m": number, // Open price in USD 1m
"closeInUsd1m": number, // Close price in USD 1m
"buys5m": number, // Buys in 5m
"sells5m": number, // Sells in 5m
"buyers5m": number, // Buyers in 5m
"sellers5m": number, // Sellers in 5m
"buyVolumeInUsd5m": number, // Buy volume in USD 5m
"sellVolumeInUsd5m": number,// Sell volume in USD 5m
"price5m": number, // Price 5m
"openInUsd5m": number, // Open price in USD 5m
"closeInUsd5m": number, // Close price in USD 5m
"buys15m": number, // Buys in 15m
"sells15m": number, // Sells in 15m
"buyers15m": number, // Buyers in 15m
"sellers15m": number, // Sellers in 15m
"buyVolumeInUsd15m": number,// Buy volume in USD 15m
"sellVolumeInUsd15m": number,// Sell volume in USD 15m
"price15m": number, // Price 15m
"openInUsd15m": number, // Open price in USD 15m
"closeInUsd15m": number, // Close price in USD 15m
"buys30m": number, // Buys in 30m
"sells30m": number, // Sells in 30m
"buyers30m": number, // Buyers in 30m
"sellers30m": number, // Sellers in 30m
"buyVolumeInUsd30m": number,// Buy volume in USD 30m
"sellVolumeInUsd30m": number,// Sell volume in USD 30m
"price30m": number, // Price 30m
"openInUsd30m": number, // Open price in USD 30m
"closeInUsd30m": number, // Close price in USD 30m
"buys1h": number, // Buys in 1h
"sells1h": number, // Sells in 1h
"buyers1h": number, // Buyers in 1h
"sellers1h": number, // Sellers in 1h
"buyVolumeInUsd1h": number, // Buy volume in USD 1h
"sellVolumeInUsd1h": number,// Sell volume in USD 1h
"price1h": number, // Price 1h
"openInUsd1h": number, // Open price in USD 1h
"closeInUsd1h": number, // Close price in USD 1h
"buys4h": number, // Buys in 4h
"sells4h": number, // Sells in 4h
"buyers4h": number, // Buyers in 4h
"sellers4h": number, // Sellers in 4h
"buyVolumeInUsd4h": number, // Buy volume in USD 4h
"sellVolumeInUsd4h": number,// Sell volume in USD 4h
"price4h": number, // Price 4h
"openInUsd4h": number, // Open price in USD 4h
"closeInUsd4h": number, // Close price in USD 4h
"buys24h": number, // Buys in 24h
"sells24h": number, // Sells in 24h
"buyers24h": number, // Buyers in 24h
"sellers24h": number, // Sellers in 24h
"buyVolumeInUsd24h": number,// Buy volume in USD 24h
"sellVolumeInUsd24h": number,// Sell volume in USD 24h
"price24h": number, // Price 24h
"openInUsd24h": number, // Open price in USD 24h
"closeInUsd24h": number, // Close price in USD 24h
"price": number // Current price
}
]
Ranking Token Holders Statistics
Get real-time token holder statistics for ranking tokens.
Subscription Format
dex-ranking-token-holding-list:{chain}_{channelType}
Parameters
Blockchain name, e.g., sol
Channel type, support:new、trending、us_stocks、completed、graduated
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names to improve code readability.
[
{
"a": string, // Token address
"h": number, // Number of holders
"t100a": number, // Top 100 holders total amount
"t10a": number, // Top 10 holders total amount
"t100h": number, // Top 100 holders count
"t10h": number, // Top 10 holders count
"t100r": number, // Top 100 holders ratio
"t10r": number, // Top 10 holders ratio
"ts": number // Timestamp
}
]
[
{
"tokenAddress": string, // Token address
"holders": number, // Number of holders
"top100Amount": number, // Top 100 holders total amount
"top10Amount": number, // Top 10 holders total amount
"top100Holders": number, // Top 100 holders count
"top10Holders": number, // Top 10 holders count
"top100Ratio": number, // Top 100 holders ratio
"top10Ratio": number, // Top 10 holders ratio
"timestamp": number // Timestamp
}
]
Ranking Token Supply Data
Get real-time supply and market cap information for ranking tokens.
Subscription Format
dex-ranking-token-supply-list:{chain}_{channelType}
Parameters
Blockchain name, e.g., sol
Channel type, support:new、trending、us_stocks、completed、graduated
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names to improve code readability.
[
{
"a": string, // Token address
"s": number, // Supply
"mc": number, // Market cap in USD
"ts": number // Timestamp
}
]
[
{
"tokenAddress": string, // Token address
"supply": number, // Supply
"marketCapInUsd": number, // Market cap in USD
"timestamp": number // Timestamp
}
]
Ranking Token Liquidity Data
Get real-time liquidity statistics for ranking tokens.
Subscription Format
dex-ranking-token-general_stat_num-list:{chain}_{channelType}
Parameters
Blockchain name, e.g., sol
Channel type, support:new、trending、us_stocks、completed、graduated
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names to improve code readability.
[
{
"a": string, // Token address
"t": string, // Metric type
"v": number, // Value
"ts": number // Timestamp
}
]
[
{
"tokenAddress": string, // Token address
"metricType": string, // Metric type
"value": number, // Value
"timestamp": number // Timestamp
}
]
Ranking Token List
Get real-time complete information list for ranking tokens, including metadata, holder statistics, supply and market data.
Subscription Format
dex-ranking-list:{chain}_{ranking_type}
# Or specify DEX
dex-ranking-list:{chain}_{ranking_type}_{dex}
Parameters
Blockchain name, e.g., sol
Ranking type, support:new、trending、us_stocks、completed、graduated
Optional DEX platform, support:pump_fun、raydium_launchpad、meteora_dynamic_bounding_curve、bonk_fun、boop_fun、moonit_fun
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names to improve code readability.
[
{
// TokenMetadata (t)
"t": {
"a": string, // Token address
"n": string, // Name
"s": string, // Symbol
"iu": string, // Image URL
"de": string, // Description
"dec": number, // Decimals
"cts": number, // Created timestamp (ms)
"lf": { // Launch from information
"pa": string, // Program address
"pf": string, // Protocol family
"pn": string // Protocol name
},
"mt": { // Migrated to information
"pa": string, // Program address
"pf": string, // Protocol family
"pn": string // Protocol name
},
"sm": { // Social media
"tw": string, // Twitter
"tg": string, // Telegram
"w": string, // Website
"tt": string, // TikTok
"dc": string, // Discord
"fb": string, // Facebook
"gh": string, // GitHub
"ig": string, // Instagram
"li": string, // LinkedIn
"md": string, // Medium
"rd": string, // Reddit
"yt": string, // YouTube
"bb": string // BitBucket
}
},
// TokenBondingCurve (bc)
"bc": {
"pr": number // Progress ratio
},
// TokenHolder (h)
"h": {
"a": string, // Token address
"h": number, // Number of holders
"t100a": number, // Top 100 holders total amount
"t10a": number, // Top 10 holders total amount
"t100h": number, // Top 100 holders count
"t10h": number, // Top 10 holders count
"t100r": number, // Top 100 holders ratio
"t10r": number, // Top 10 holders ratio
"ts": number // Timestamp
},
// TokenSupply (s)
"s": {
"a": string, // Token address
"s": number, // Supply
"mc": number, // Market cap in USD
"ts": number // Timestamp
},
// TokenStat (ts)
"ts": {
"a": string, // Token address
"t": number, // Timestamp
"b1m": number, // Buys in 1m
"s1m": number, // Sells in 1m
"be1m": number, // Buyers in 1m
"se1m": number, // Sellers in 1m
"bviu1m": number, // Buy volume in USD 1m
"sviu1m": number, // Sell volume in USD 1m
"p1m": number, // Price 1m
"oiu1m": number, // Open price in USD 1m
"ciu1m": number, // Close price in USD 1m
"b5m": number, // Buys in 5m
"s5m": number, // Sells in 5m
"be5m": number, // Buyers in 5m
"se5m": number, // Sellers in 5m
"bviu5m": number, // Buy volume in USD 5m
"sviu5m": number, // Sell volume in USD 5m
"p5m": number, // Price 5m
"oiu5m": number, // Open price in USD 5m
"ciu5m": number, // Close price in USD 5m
"b15m": number, // Buys in 15m
"s15m": number, // Sells in 15m
"be15m": number, // Buyers in 15m
"se15m": number, // Sellers in 15m
"bviu15m": number,// Buy volume in USD 15m
"sviu15m": number,// Sell volume in USD 15m
"p15m": number, // Price 15m
"oiu15m": number, // Open price in USD 15m
"ciu15m": number, // Close price in USD 15m
"b30m": number, // Buys in 30m
"s30m": number, // Sells in 30m
"be30m": number, // Buyers in 30m
"se30m": number, // Sellers in 30m
"bviu30m": number,// Buy volume in USD 30m
"sviu30m": number,// Sell volume in USD 30m
"p30m": number, // Price 30m
"oiu30m": number, // Open price in USD 30m
"ciu30m": number, // Close price in USD 30m
"b1h": number, // Buys in 1h
"s1h": number, // Sells in 1h
"be1h": number, // Buyers in 1h
"se1h": number, // Sellers in 1h
"bviu1h": number, // Buy volume in USD 1h
"sviu1h": number, // Sell volume in USD 1h
"p1h": number, // Price 1h
"oiu1h": number, // Open price in USD 1h
"ciu1h": number, // Close price in USD 1h
"b4h": number, // Buys in 4h
"s4h": number, // Sells in 4h
"be4h": number, // Buyers in 4h
"se4h": number, // Sellers in 4h
"bviu4h": number, // Buy volume in USD 4h
"sviu4h": number, // Sell volume in USD 4h
"p4h": number, // Price 4h
"oiu4h": number, // Open price in USD 4h
"ciu4h": number, // Close price in USD 4h
"b24h": number, // Buys in 24h
"s24h": number, // Sells in 24h
"be24h": number, // Buyers in 24h
"se24h": number, // Sellers in 24h
"bviu24h": number,// Buy volume in USD 24h
"sviu24h": number,// Sell volume in USD 24h
"p24h": number, // Price 24h
"oiu24h": number, // Open price in USD 24h
"ciu24h": number, // Close price in USD 24h
"p": number // Current price
}
}
]
[
{
// Token metadata
"metadata": {
"tokenAddress": string, // Token address
"name": string, // Name
"symbol": string, // Symbol
"imageUrl": string, // Image URL
"description": string, // Description
"decimals": number, // Decimals
"createdAtMs": number, // Created timestamp (ms)
"launchFrom": { // Launch from information
"programAddress": string, // Program address
"protocolFamily": string, // Protocol family
"protocolName": string // Protocol name
},
"migratedTo": { // Migrated to information
"programAddress": string, // Program address
"protocolFamily": string, // Protocol family
"protocolName": string // Protocol name
},
"socialMedia": { // Social media
"twitter": string, // Twitter
"telegram": string, // Telegram
"website": string, // Website
"tiktok": string, // TikTok
"discord": string, // Discord
"facebook": string, // Facebook
"github": string, // GitHub
"instagram": string, // Instagram
"linkedin": string, // LinkedIn
"medium": string, // Medium
"reddit": string, // Reddit
"youtube": string, // YouTube
"bitbucket": string // BitBucket
}
},
// Bonding curve information
"bondingCurve": {
"progressRatio": number // Progress ratio
},
// Holder statistics
"holder": {
"tokenAddress": string, // Token address
"timestamp": number, // Timestamp
"holders": number, // Number of holders
"top100Amount": number, // Top 100 holders total amount
"top10Amount": number, // Top 10 holders total amount
"top100Holders": number, // Top 100 holders count
"top10Holders": number, // Top 10 holders count
"top100Ratio": number, // Top 100 holders ratio
"top10Ratio": number // Top 10 holders ratio
},
// Supply information
"supply": {
"tokenAddress": string, // Token address
"timestamp": number, // Timestamp
"supply": number, // Supply
"marketCapInUsd": number // Market cap in USD
},
// Market statistics
"stat": {
"address": string, // Token address
"timestamp": number, // Timestamp
"buys1m": number, // Buys in 1m
"sells1m": number, // Sells in 1m
"buyers1m": number, // Buyers in 1m
"sellers1m": number, // Sellers in 1m
"buyVolumeInUsd1m": number, // Buy volume in USD 1m
"sellVolumeInUsd1m": number,// Sell volume in USD 1m
"price1m": number, // Price 1m
"openInUsd1m": number, // Open price in USD 1m
"closeInUsd1m": number, // Close price in USD 1m
"buys5m": number, // Buys in 5m
"sells5m": number, // Sells in 5m
"buyers5m": number, // Buyers in 5m
"sellers5m": number, // Sellers in 5m
"buyVolumeInUsd5m": number, // Buy volume in USD 5m
"sellVolumeInUsd5m": number,// Sell volume in USD 5m
"price5m": number, // Price 5m
"openInUsd5m": number, // Open price in USD 5m
"closeInUsd5m": number, // Close price in USD 5m
"buys15m": number, // Buys in 15m
"sells15m": number, // Sells in 15m
"buyers15m": number, // Buyers in 15m
"sellers15m": number, // Sellers in 15m
"buyVolumeInUsd15m": number,// Buy volume in USD 15m
"sellVolumeInUsd15m": number,// Sell volume in USD 15m
"price15m": number, // Price 15m
"openInUsd15m": number, // Open price in USD 15m
"closeInUsd15m": number, // Close price in USD 15m
"buys30m": number, // Buys in 30m
"sells30m": number, // Sells in 30m
"buyers30m": number, // Buyers in 30m
"sellers30m": number, // Sellers in 30m
"buyVolumeInUsd30m": number,// Buy volume in USD 30m
"sellVolumeInUsd30m": number,// Sell volume in USD 30m
"price30m": number, // Price 30m
"openInUsd30m": number, // Open price in USD 30m
"closeInUsd30m": number, // Close price in USD 30m
"buys1h": number, // Buys in 1h
"sells1h": number, // Sells in 1h
"buyers1h": number, // Buyers in 1h
"sellers1h": number, // Sellers in 1h
"buyVolumeInUsd1h": number, // Buy volume in USD 1h
"sellVolumeInUsd1h": number,// Sell volume in USD 1h
"price1h": number, // Price 1h
"openInUsd1h": number, // Open price in USD 1h
"closeInUsd1h": number, // Close price in USD 1h
"buys4h": number, // Buys in 4h
"sells4h": number, // Sells in 4h
"buyers4h": number, // Buyers in 4h
"sellers4h": number, // Sellers in 4h
"buyVolumeInUsd4h": number, // Buy volume in USD 4h
"sellVolumeInUsd4h": number,// Sell volume in USD 4h
"price4h": number, // Price 4h
"openInUsd4h": number, // Open price in USD 4h
"closeInUsd4h": number, // Close price in USD 4h
"buys24h": number, // Buys in 24h
"sells24h": number, // Sells in 24h
"buyers24h": number, // Buyers in 24h
"sellers24h": number, // Sellers in 24h
"buyVolumeInUsd24h": number,// Buy volume in USD 24h
"sellVolumeInUsd24h": number,// Sell volume in USD 24h
"price24h": number, // Price 24h
"openInUsd24h": number, // Open price in USD 24h
"closeInUsd24h": number, // Close price in USD 24h
"price": number // Current price
}
}
]
Wallet Series
Wallet Balance
Get real-time wallet balance information.
Subscription Format
dex-wallet-balance:{chain}_{walletAddress}
Parameters
Blockchain name, e.g., sol
Wallet address, e.g., HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH
Optional filter condition using Google Common Expression Language (CEL) syntax. Example: balance > 1000
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names to improve code readability.
[
{
"a": string, // Wallet address
"ta": string, // Token address
"tpiu": number, // Token price in USD
"b": number, // Balance
"t": number // Timestamp
}
]
[
{
"walletAddress": string, // Wallet address
"tokenAddress": string, // Token address
"tokenPriceInUsd": number, // Token price in USD
"balance": number, // Balance
"timestamp": number // Timestamp
}
]
Wallet PnL Data (Token Level)
Get real-time wallet profit and loss (PnL) statistics.
Subscription Format
dex-wallet-token-pnl:{chain}_{walletAddress}
Parameters
Blockchain name, e.g., sol
Optional filter condition using Google Common Expression Language (CEL) syntax. Example: buyAmount > 1000
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names for better code readability.
{
"a": string, // Wallet address
"ta": string, // Token address
"tpiu": number, // Token price in USD
"t": number, // Timestamp
"ot": number, // Open time
"lt": number, // Last time
"ct": number, // Close time
"ba": number, // Buy amount
"baiu": number, // Buy amount in USD
"bs": number, // Buy count
"bs30d": number, // Buy count 30d
"bs7d": number, // Buy count 7d
"sa": number, // Sell amount
"saiu": number, // Sell amount in USD
"ss": number, // Sell count
"ss30d": number, // Sell count 30d
"ss7d": number, // Sell count 7d
"hdts": number, // Held duration timestamp
"abpiu": number, // Average buy price in USD
"aspiu": number, // Average sell price in USD
"upiu": number, // Unrealized profit in USD
"upr": number, // Unrealized profit ratio
"rpiu": number, // Realized profit in USD
"rpr": number, // Realized profit ratio
"trpiu": number, // Total realized profit in USD
"trr": number // Total realized profit ratio
}
{
"walletAddress": string, // Wallet address
"tokenAddress": string, // Token address
"tokenPriceInUsd": number, // Token price in USD
"timestamp": number, // Timestamp
"opentime": number, // Open time
"lasttime": number, // Last time
"closetime": number, // Close time
"buyAmount": number, // Buy amount
"buyAmountInUsd": number, // Buy amount in USD
"buyCount": number, // Buy count
"buyCount30d": number, // Buy count 30d
"buyCount7d": number, // Buy count 7d
"sellAmount": number, // Sell amount
"sellAmountInUsd": number, // Sell amount in USD
"sellCount": number, // Sell count
"sellCount30d": number, // Sell count 30d
"sellCount7d": number, // Sell count 7d
"heldDurationTimestamp": number, // Held duration timestamp
"averageBuyPriceInUsd": number, // Average buy price in USD
"averageSellPriceInUsd": number, // Average sell price in USD
"unrealizedProfitInUsd": number, // Unrealized profit in USD
"unrealizedProfitRatio": number, // Unrealized profit ratio
"realizedProfitInUsd": number, // Realized profit in USD
"realizedProfitRatio": number, // Realized profit ratio
"totalRealizedProfitInUsd": number, // Total realized profit in USD
"totalRealizedProfitRatio": number // Total realized profit ratio
}
Wallet PnL Data (Wallet Level)
Get real-time wallet overall profit and loss statistics.
Subscription Format
dex-wallet-pnl-list:{chain}_{walletAddress}
Parameters
Blockchain name, e.g., sol
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names for better code readability.
[
{
"a": string, // Wallet address
"bs": number, // Number of buys
"ba": number, // Buy amount
"baiu": number, // Buy amount in USD
"abpiu": number, // Average buy price in USD
"sa": number, // Sell amount
"saiu": number, // Sell amount in USD
"ss": number, // Number of sells
"ws": number, // Number of wins
"wr": number, // Win ratio
"piu": number, // PnL in USD
"apiu": number, // Average PnL in USD
"pr": number, // PnL ratio
"pd": number, // Profitable days
"ld": number, // Losing days
"ts": number, // Number of tokens traded
"r": string // Resolution
}
]
[
{
"walletAddress": string, // Wallet address
"buys": number, // Number of buys
"buyAmount": number, // Buy amount
"buyAmountInUsd": number, // Buy amount in USD
"averageBuyPriceInUsd": number, // Average buy price in USD
"sellAmount": number, // Sell amount
"sellAmountInUsd": number, // Sell amount in USD
"sells": number, // Number of sells
"wins": number, // Number of wins
"winRatio": number, // Win ratio
"pnlInUsd": number, // PnL in USD
"averagePnlInUsd": number, // Average PnL in USD
"pnlRatio": number, // PnL ratio
"profitableDays": number, // Profitable days
"losingDays": number, // Losing days
"tokens": number, // Number of tokens traded
"resolution": string // Resolution
}
]
Trade Series
Token Trade
Get real-time token trading events.
Subscription Format
dex-trade:{chain}_{tokenAddress}
Parameters
Blockchain name, e.g., sol
Token contract address, e.g., 6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN
Optional filter condition using Google Common Expression Language (CEL) syntax. Example: buyAmount > 100
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names to improve code readability.
{
"a": string, // Token address
"t": number, // Timestamp
"k": string, // Trade type
"ba": number, // Buy amount
"baiu": number, // Buy amount in USD
"btma": string, // Buy token address
"btn": string, // Buy token name
"bts": string, // Buy token symbol
"bwa": string, // Buy wallet address
"sa": number, // Sell amount
"saiu": number, // Sell amount in USD
"stma": string, // Sell token address
"stn": string, // Sell token name
"sts": string, // Sell token symbol
"swa": string, // Sell wallet address
"h": string // Transaction hash
}
{
"tokenAddress": string, // Token address
"timestamp": number, // Timestamp
"kind": string, // Trade type
"buyAmount": number, // Buy amount
"buyAmountInUsd": number, // Buy amount in USD
"buyTokenAddress": string, // Buy token address
"buyTokenName": string, // Buy token name
"buyTokenSymbol": string, // Buy token symbol
"buyWalletAddress": string,// Buy wallet address
"sellAmount": number, // Sell amount
"sellAmountInUsd": number,// Sell amount in USD
"sellTokenAddress": string,// Sell token address
"sellTokenName": string, // Sell token name
"sellTokenSymbol": string,// Sell token symbol
"sellWalletAddress": string,// Sell wallet address
"txHash": string // Transaction hash
}
Wallet Trade
Get real-time wallet trading event.
Subscription Format
dex-wallet-trade:{chain}_{walletAddress}
Parameters
Blockchain name, e.g., sol
Token contract address, e.g., GDekof7TtgeBKJtoVpkvzPin5mvhxSDyoUY2c1FK1T3i
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names to improve code readability.
{
"bwa": string, // Maker address
"ba": number, // Base token amount
"sa": number, // Quote token amount
"swa": string, // Quote token address
"bais": number, // USD amount
"t": number, // Timestamp
"k": string, // Event type
"h": string, // Transaction hash
"a": string // Token address
}
{
"maker": string, // Maker address
"baseAmount": number, // Base token amount
"quoteAmount": number, // Quote token amount
"quoteAddress": string, // Quote token address
"amountInUsd": number, // USD amount
"timestamp": number, // Timestamp
"event": string, // Event type
"txHash": string, // Transaction hash
"tokenAddress": string // Token address
}
DexPool Series
DEX Pool Balance
Get real-time DEX pool balance information.
Subscription Format
dex-pool-balance:{chain}_{poolAddress}
Parameters
Blockchain name, e.g., sol
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names for better code readability.
{
"a": string, // Pool address
"taa": string, // Token A address
"taliu": number, // Token A liquidity in USD
"tba": string, // Token B address
"tbliu": number // Token B liquidity in USD
}
{
"poolAddress": string, // Pool address
"tokenAAddress": string, // Token A address
"tokenALiquidityInUsd": number, // Token A liquidity in USD
"tokenBAddress": string, // Token B address
"tokenBLiquidityInUsd": number // Token B liquidity in USD
}
Usage Examples
import { ChainStreamClient } from '@chainstream-io/sdk';
import { Resolution } from '@chainstream-io/sdk/openapi';
const client = new ChainStreamClient('YOUR_ACCESS_TOKEN');
// Just subscribe directly, SDK auto-detects connection status and connects if needed
client.stream.subscribeTokenCandles({
chain: 'sol',
tokenAddress: '6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN',
resolution: Resolution._1m,
callback: (data) => {
console.log('Candle data:', data);
}
});
// Subscribe to wallet balance
client.stream.subscribeWalletBalance({
chain: 'sol',
walletAddress: 'YOUR_WALLET_ADDRESS',
callback: (data) => {
console.log('Wallet balance:', data);
}
});
Reconnection Strategy
Recommended to use exponential backoff for reconnection:
function reconnect(attempt) {
const delay = Math.min(1000 * Math.pow(2, attempt), 10000);
setTimeout(() => {
connect();
}, delay);
}
Usage Limits
| Limit | Value | Description |
|---|
| Maximum Subscriptions | 100/connection | Excess will be rejected |
| Message Size | 100KB | Excess will be truncated |
| Heartbeat Interval | 30 seconds | Regular heartbeat required |
Best Practices
-
Connection Management
- Maintain a single WebSocket connection
- Implement automatic reconnection
- Send regular heartbeats
-
Error Handling
- Implement complete error handling
- Log detailed error information
- Use exponential backoff for reconnection
-
Performance Optimization
- Control subscription quantity
- Implement message queue mechanism
- Clean up unused subscriptions
Complete Example
Using SDK (Recommended)
Native WebSocket
import { ChainStreamClient } from '@chainstream-io/sdk';
import { Resolution } from '@chainstream-io/sdk/openapi';
const client = new ChainStreamClient('YOUR_ACCESS_TOKEN');
// Just subscribe directly, SDK auto-detects connection status and connects if needed
const subscription = client.stream.subscribeTokenCandles({
chain: 'sol',
tokenAddress: '6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN',
resolution: Resolution._1m,
callback: (data) => {
console.log('Candle data:', data);
}
});
// Unsubscribe
subscription.unsubscribe();
When using the SDK, authentication, reconnection, heartbeat, etc. are all handled automatically. Recommended for production environments. class DexWebSocket {
private ws: WebSocket;
private reconnectAttempts = 0;
private maxReconnectAttempts = 5;
private subscriptions = new Set<string>();
constructor(
private baseUrl: string,
private accessToken: string
) {
this.connect();
}
private connect() {
// Append token parameter to URL for authentication
const url = `${this.baseUrl}?token=${this.accessToken}`;
this.ws = new WebSocket(url);
this.ws.onopen = () => {
console.log('WebSocket connection established');
this.reconnectAttempts = 0;
// Resubscribe to previous channels
this.resubscribe();
};
this.ws.onmessage = (event) => {
this.handleMessage(JSON.parse(event.data));
};
this.ws.onclose = () => {
console.log('WebSocket connection closed');
this.reconnect();
};
this.ws.onerror = (error) => {
console.error('WebSocket error:', error);
};
}
private reconnect() {
if (this.reconnectAttempts < this.maxReconnectAttempts) {
const delay = Math.min(1000 * Math.pow(2, this.reconnectAttempts), 10000);
this.reconnectAttempts++;
console.log(`Attempting reconnection in ${delay}ms...`);
setTimeout(() => this.connect(), delay);
}
}
private resubscribe() {
this.subscriptions.forEach(channel => {
this.send({ type: "subscribe", channel });
});
}
private handleMessage(data: any) {
// Handle message
}
private send(data: any) {
if (this.ws.readyState === WebSocket.OPEN) {
this.ws.send(JSON.stringify(data));
}
}
public subscribe(channel: string) {
this.subscriptions.add(channel);
this.send({ type: "subscribe", channel });
}
public unsubscribe(channel: string) {
this.subscriptions.delete(channel);
this.send({ type: "unsubscribe", channel });
}
}
// Usage example
const client = new DexWebSocket(
"wss://realtime-dex.chainstream.io/connection/websocket",
"YOUR_ACCESS_TOKEN"
);