WebSocket API

Subscribe to real-time price updates via WebSocket. Get live price feeds for any supported token with automatic VWAP calculations.

Connecting

Connect to the WebSocket endpoint with your API key. The key can be provided via query parameter, Authorization header, or socket auth token.

wss://api.predikt.fun/api/v1/ws

Authentication Methods

MethodExample
Query Parameter?api_key=pk_live_xxx
Authorization HeaderBearer pk_live_xxx
Socket Auth Token{ auth: { token: 'pk_live_xxx' } }

JavaScript Example

JavaScript
import { io } from 'socket.io-client';
const socket = io('wss://api.predikt.fun/api/v1/ws', {
auth: { token: 'pk_live_your_api_key' }
});
socket.on('connect', () => {
console.log('Connected!');
});
socket.on('message', (data) => {
console.log('Received:', data);
});
socket.on('disconnect', (reason) => {
console.log('Disconnected:', reason);
});

Connection Response

Upon successful connection, you'll receive a connected message.

Response
{
"type": "connected",
"accountId": "acc_abc123",
"connectionId": "conn_xyz789",
"timestamp": "2026-01-17T12:00:00.000Z"
}

Subscribe to Price Updates

Subscribe to real-time price updates for one or more symbols.

Request

Client → Server
// Using socket.emit
socket.emit('subscribe', {
channel: 'price',
symbols: ['SOL', 'BTC', 'ETH']
});
// Or using the 'message' event
socket.emit('message', {
action: 'subscribe',
channel: 'price',
symbols: ['SOL', 'BTC', 'ETH']
});

Response

Response
{
"type": "subscribed",
"channel": "price",
"symbols": ["SOL", "BTC", "ETH"],
"timestamp": "2026-01-17T12:00:01.000Z"
}

Receiving Price Updates

Once subscribed, you'll receive price updates every 5 seconds for each subscribed symbol.

Response
{
"type": "price_update",
"symbol": "SOL",
"price": 185.42,
"source": "vwap",
"timestamp": "2026-01-17T12:00:05.000Z"
}

Handling Price Updates

JavaScript
socket.on('message', (data) => {
if (data.type === 'price_update') {
console.log(`${data.symbol}: $${data.price}`);
// Update your UI or trigger logic
}
});

Unsubscribe from Price Updates

Unsubscribe from specific symbols to stop receiving their price updates.

Request

Client → Server
socket.emit('unsubscribe', {
channel: 'price',
symbols: ['BTC']
});

Response

Response
{
"type": "unsubscribed",
"channel": "price",
"symbols": ["BTC"],
"timestamp": "2026-01-17T12:01:00.000Z"
}

Keep-Alive (Ping/Pong)

Send periodic ping messages to keep the connection alive. Connections without activity for 60 seconds may be closed.

Client → Server
socket.emit('ping');
Response
{
"type": "pong",
"timestamp": "..."
}

Billing Notifications

WebSocket connections are billed hourly. You'll receive a notification each time you're charged.

Response
{
"type": "billing",
"message": "Hourly subscription fee charged",
"amountUsd": "0.10",
"remainingBalanceUsd": "45.90",
"timestamp": "2026-01-17T13:00:00.000Z"
}

Insufficient Balance: If your balance falls below the hourly fee, you'll receive a disconnecting message before being disconnected.

Connection Limits

Connection and subscription limits vary by tier.

TierMax ConnectionsMax Symbols/Connection
STANDARD210
PRO550
ENTERPRISE20200

Error Messages

Errors are sent as messages with type: "error".

Response (429)
{
"type": "error",
"code": "RATE_LIMIT_EXCEEDED",
"message": "Maximum symbols (10) would be exceeded for STANDARD tier",
"timestamp": "2026-01-17T12:00:00.000Z"
}

Error Codes

CodeDescription
INVALID_API_KEYMissing or invalid API key
PERMISSION_DENIEDAPI key lacks websocket permission
INSUFFICIENT_BALANCENot enough balance for connection
RATE_LIMIT_EXCEEDEDConnection or symbol limit reached
INVALID_SYMBOLNo valid symbols provided
ACCOUNT_NOT_FOUNDAccount does not exist

Message Types Summary

Client → Server

ActionDescription
subscribeSubscribe to price channel
unsubscribeUnsubscribe from price channel
pingKeep-alive ping

Server → Client

TypeDescription
connectedConnection established
subscribedSubscription confirmed
unsubscribedUnsubscription confirmed
price_updateReal-time price data
billingHourly billing notification
pongPing response
errorError message
disconnectingWarning before disconnect

Related