📡 Index WebSocket API
Get real-time index data through WebSocket, supports subscription and real-time data streaming
🔗 Connection Information
| Item | Value |
|---|---|
| Connection URL | wss://api.dataapi.io/v1/indices |
| Protocol Type | WebSocket |
| Data Format | JSON |
📋 Usage Flow
Step 1: Establish Connection and Authorization 🔐
Authorization Request
{
"action": "auth",
"params": {
"token": "36ee75a7ea32961d619f5e6a6427fd3e"
}
}Authorization Response
Success Response
{
"code": 200,
"status": "success",
"message": "authenticated"
}Error Response
{
"code": 500,
"status": "error",
"message": "Token validation failed: Invalid API token"
}Step 2: Subscribe to Index Data 📊
Subscription Request
{
"action": "subscribe",
"params": {
"ticker": "SPX"
}
}Subscription Response
{
"code": 200,
"status": "success",
"message": "subscribed to indices: SPX"
}Step 3: Receive Real-Time Data 📈
Real-Time Data Stream
{
"code": 200,
"data": {
"time": 1753287588000,
"ticker": "SPX",
"open": 6388.65,
"close": 6388.65,
"high": 6388.65,
"low": 6388.65,
"volume": 8000000,
"quoteVolume": 51109200000,
"quote": 6388.65
}
}📊 Data Field Description
| Field | Type | Description | Example |
|---|---|---|---|
time | number | Data timestamp | 1753287588000 |
ticker | string | Index symbol | SPX |
open | number | Opening price | 6388.65 |
close | number | Closing price | 6388.65 |
high | number | Highest price | 6388.65 |
low | number | Lowest price | 6388.65 |
volume | number | Trading volume | 8000000 |
quoteVolume | number | Trading amount | 51109200000 |
quote | number | Quote price | 6388.65 |
🚀 Quick Start
JavaScript Example
// Establish WebSocket connection
const ws = new WebSocket('wss://api.dataapi.io/v1/indices');
// Connection opened
ws.onopen = function() {
// Step 1: Send authorization
ws.send(JSON.stringify({
action: "auth",
params: {
token: "your_api_token"
}
}));
};
// Receive messages
ws.onmessage = function(event) {
const data = JSON.parse(event.data);
if (data.message === "authenticated") {
// Step 2: Subscribe to index after successful authorization
ws.send(JSON.stringify({
action: "subscribe",
params: {
ticker: "SPX"
}
}));
} else if (data.data) {
// Step 3: Handle real-time data
console.log('Real-time index data:', data.data);
}
};
// Connection closed
ws.onclose = function() {
console.log('WebSocket connection closed');
};