WebSocket API

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

Endpoint

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

Connection

1const ws = new WebSocket('wss://api.allenhark.com/v1/ws');
2
3// Authenticate
4ws.onopen = () => {
5  ws.send(JSON.stringify({
6    type: 'auth',
7    apiKey: 'your_api_key',
8  }));
9};
10
11ws.onmessage = (event) => {
12  const message = JSON.parse(event.data);
13  console.log('Received:', message);
14};

Subscriptions

Bot Updates

1// Subscribe to bot updates
2ws.send(JSON.stringify({
3  type: 'subscribe',
4  channel: 'bot',
5  botId: 'bot_abc123',
6}));
7
8// Receive updates
9{
10  "type": "bot_update",
11  "botId": "bot_abc123",
12  "event": "trade_executed",
13  "data": {
14    "signature": "5VERv8...",
15    "profit": 0.15,
16    "timestamp": "2024-01-15T10:30:00Z"
17  }
18}

Market Data

1// Subscribe to token price updates
2ws.send(JSON.stringify({
3  type: 'subscribe',
4  channel: 'price',
5  mint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
6}));
7
8// Receive price updates
9{
10  "type": "price_update",
11  "mint": "EPjFWdd5...",
12  "price": 1.0001,
13  "volume": 1000000,
14  "timestamp": "2024-01-15T10:30:00Z"
15}

Transaction Notifications

1// Subscribe to transaction confirmations
2ws.send(JSON.stringify({
3  type: 'subscribe',
4  channel: 'transactions',
5  wallet: 'your_wallet_address',
6}));
7
8// Receive notifications
9{
10  "type": "transaction_confirmed",
11  "signature": "5VERv8...",
12  "status": "confirmed",
13  "slot": 250123456
14}

Unsubscribe

1ws.send(JSON.stringify({
2  type: 'unsubscribe',
3  channel: 'bot',
4  botId: 'bot_abc123',
5}));

Heartbeat

1// Send ping every 30 seconds
2setInterval(() => {
3  ws.send(JSON.stringify({ type: 'ping' }));
4}, 30000);
5
6// Receive pong
7{
8  "type": "pong",
9  "timestamp": "2024-01-15T10:30:00Z"
10}

Error Handling

1ws.onerror = (error) => {
2  console.error('WebSocket error:', error);
3};
4
5ws.onclose = (event) => {
6  console.log('Connection closed:', event.code, event.reason);
7  // Implement reconnection logic
8};

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 |