Documentation index

WebSocket API

Real-time WebSocket API for live market data, bot updates, and transaction notifications.

Endpoint

Text
wss://api.allenhark.com/v1/ws

Connection

TypeScript
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

TypeScript
// 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

TypeScript
// 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

TypeScript
// 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

TypeScript
ws.send(JSON.stringify({
  type: 'unsubscribe',
  channel: 'bot',
  botId: 'bot_abc123',
}));

Heartbeat

TypeScript
// 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

TypeScript
ws.onerror = (error) => {
  console.error('WebSocket error:', error);
};

ws.onclose = (event) => {
  console.log('Connection closed:', event.code, event.reason);
  // Implement reconnection logic
};

Message Types

TypeDescription
authAuthentication message
subscribeSubscribe to channel
unsubscribeUnsubscribe from channel
pingHeartbeat ping
pongHeartbeat response
bot_updateBot event notification
price_updatePrice change notification
transaction_confirmedTransaction confirmation
errorError message