📡 Forex WebSocket API
Get real-time forex data through WebSocket, supports subscription and real-time data streaming
🔗 Connection Information
| Item | Value |
|---|---|
| Connection URL | wss://api.dataapi.io/v1/forex |
| 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 Forex Data 📊
Subscription Request
{
"action": "subscribe",
"params": {
"ticker": "EUR/USD"
}
}Subscription Response
{
"code": 200,
"status": "success",
"message": "subscribed to forex: EUR/USD"
}Step 3: Receive Real-Time Data 📈
Real-Time Data Stream
{
"code": 200,
"data": {
"time": 1753287588000,
"ticker": "EUR/USD",
"open": 215,
"close": 213.565,
"high": 213.565,
"low": 213.565,
"volume": 156,
"quoteVolume": 21653656,
"quote": 213.565
}
}📊 Data Field Description
| Field | Type | Description | Example |
|---|---|---|---|
time | number | Data timestamp | 1753287588000 |
ticker | string | Forex pair symbol | EUR/USD |
open | number | Opening price | 215 |
close | number | Closing price | 213.565 |
high | number | Highest price | 213.565 |
low | number | Lowest price | 213.565 |
volume | number | Trading volume | 156 |
quoteVolume | number | Trading amount | 21653656 |
quote | number | Quote price | 213.565 |
🚀 Quick Start
JavaScript Example
// Establish WebSocket connection
const ws = new WebSocket('wss://api.dataapi.io/v1/forex');
// 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 forex after successful authorization
ws.send(JSON.stringify({
action: "subscribe",
params: {
ticker: "EUR/USD"
}
}));
} else if (data.data) {
// Step 3: Handle real-time data
console.log('Real-time forex data:', data.data);
}
};
// Connection closed
ws.onclose = function() {
console.log('WebSocket connection closed');
};