WebSocket API
Real-time WebSocket API for live market data, bot updates, and transaction notifications.
Endpoint
wss://api.allenhark.com/v1/wsConnection
const ws = new WebSocket('wss://api.allenhark.com/v1/ws');
// Authenticate
ws.onopen = () => {
ws.send(JSON.stringify({
type: 'auth',
apiKey: 'your_api_key',
}));
};
ws.onmessage = (event) => {
const message = JSON.parse(event.data);
console.log('Received:', message);
};Subscriptions
Bot Updates
// Subscribe to bot updates
ws.send(JSON.stringify({
type: 'subscribe',
channel: 'bot',
botId: 'bot_abc123',
}));
// Receive updates
{
"type": "bot_update",
"botId": "bot_abc123",
"event": "trade_executed",
"data": {
"signature": "5VERv8...",
"profit": 0.15,
"timestamp": "2024-01-15T10:30:00Z"
}
}Market Data
// Subscribe to token price updates
ws.send(JSON.stringify({
type: 'subscribe',
channel: 'price',
mint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
}));
// Receive price updates
{
"type": "price_update",
"mint": "EPjFWdd5...",
"price": 1.0001,
"volume": 1000000,
"timestamp": "2024-01-15T10:30:00Z"
}Transaction Notifications
// Subscribe to transaction confirmations
ws.send(JSON.stringify({
type: 'subscribe',
channel: 'transactions',
wallet: 'your_wallet_address',
}));
// Receive notifications
{
"type": "transaction_confirmed",
"signature": "5VERv8...",
"status": "confirmed",
"slot": 250123456
}Unsubscribe
ws.send(JSON.stringify({
type: 'unsubscribe',
channel: 'bot',
botId: 'bot_abc123',
}));Heartbeat
// Send ping every 30 seconds
setInterval(() => {
ws.send(JSON.stringify({ type: 'ping' }));
}, 30000);
// Receive pong
{
"type": "pong",
"timestamp": "2024-01-15T10:30:00Z"
}Error Handling
ws.onerror = (error) => {
console.error('WebSocket error:', error);
};
ws.onclose = (event) => {
console.log('Connection closed:', event.code, event.reason);
// Implement reconnection logic
};Message Types
| Type | Description |
|---|---|
auth | Authentication message |
subscribe | Subscribe to channel |
unsubscribe | Unsubscribe from channel |
ping | Heartbeat ping |
pong | Heartbeat response |
bot_update | Bot event notification |
price_update | Price change notification |
transaction_confirmed | Transaction confirmation |
error | Error message |
