WebSocket API
Real-time cryptocurrency price streaming via WebSocket.
Stream real-time cryptocurrency price updates via WebSocket using Socket.IO. Available to Pro users only.
#Connection
Connect to the /api-ws namespace using Socket.IO:
javascript
import { io } from "socket.io-client";
const socket = io("https://chartinspect.com/api-ws", {
auth: { apiKey: "YOUR_API_KEY" },
transports: ["websocket"],
});#Python Example
python
import socketio
sio = socketio.Client()
sio.connect(
"https://chartinspect.com",
namespaces=["/api-ws"],
auth={"apiKey": "YOUR_API_KEY"},
transports=["websocket"]
)
@sio.on("price-update", namespace="/api-ws")
def on_price(data):
print(f"{data['symbol']}: ${data['price']}")#Authentication
Pass your API key in the auth object during connection. The key must:
- Be a valid, active API key (format:
ci_live_xxxorci_test_xxx) - Belong to a user with an active Pro subscription
#Events
#Receiving
| Event | Description | Payload |
|---|---|---|
initial-prices | Sent on connect with latest prices for all symbols | MarketUpdate[] |
price-update | Real-time price update for a single symbol | MarketUpdate |
#Sending
| Event | Description | Payload |
|---|---|---|
subscribe | Subscribe to specific symbols | { symbols: string[] } |
unsubscribe | Unsubscribe from symbols | { symbols: string[] } |
#MarketUpdate Format
json
{
"symbol": "BTC",
"price": 87250.50,
"volume": 12500000000,
"timestamp": 1775001600,
"change": 1250.30,
"changePercent": 1.45
}#Supported Symbols
20 cryptocurrencies are available for real-time streaming:
BTC, ETH, LTC, XRP, BCH, ADA, DOT, LINK, BNB, DOGE, UNI, SOL, MATIC, AVAX, ATOM, XLM, ALGO, VET, ICP, FIL
#Limits
- Maximum 2 concurrent connections per user
- Requires Pro subscription
#Connection Example (Full)
javascript
import { io } from "socket.io-client";
const socket = io("https://chartinspect.com/api-ws", {
auth: { apiKey: "YOUR_API_KEY" },
transports: ["websocket"],
reconnection: true,
reconnectionDelay: 1000,
});
// Receive all current prices on connect
socket.on("initial-prices", (prices) => {
console.log(`Received ${prices.length} initial prices`);
prices.forEach((p) => console.log(`${p.symbol}: $${p.price}`));
});
// Subscribe to specific symbols only
socket.emit("subscribe", { symbols: ["BTC", "ETH", "SOL"] });
// Receive real-time updates
socket.on("price-update", (update) => {
console.log(`${update.symbol}: $${update.price} (${update.changePercent > 0 ? "+" : ""}${update.changePercent}%)`);
});
socket.on("connect_error", (err) => {
console.error("Connection failed:", err.message);
});#Error Handling
| Error | Cause |
|---|---|
Authentication failed | Invalid or missing API key |
Pro subscription required | API key belongs to a free-tier user |
Connection limit exceeded | More than 2 active connections for this user |
Was this page helpful?