WebSocket API
Overview
Connecting
JavaScript/TypeScript
const ws = new WebSocket('wss://turnpike.dev/api/data');
ws.onopen = () => {
console.log('Connected to Turnpike WebSocket');
// Subscribe to trades
ws.send(JSON.stringify({
method: 'subscribe',
keys: ['trades']
}));
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Received:', data);
};
ws.onerror = (error) => {
console.error('WebSocket error:', error);
};
ws.onclose = (event) => {
console.log('Connection closed:', event.code, event.reason);
};Python
Authentication
Subscription Methods
Subscribe to Channels
Subscribe to Specific Token
Unsubscribe
Event Types
Trade Event
New Token Event
Price Update Event
Error Event
Advanced Usage
Reconnection Logic
React Hook Example
Best Practices
Heartbeat/Ping-Pong
Error Codes
Code
Description
Next Steps
Last updated