The WebSocket Token Price API provides real-time updates for token prices by token and by pool using Socket.IO. Clients can subscribe to specific tokens or pools and receive live price updat
Base URL
Connection Workflow
Establish a connection to the Socket.IO client library.
Connect to the socket URL utilizing the Socket.IO client.
Subscribe to your preferred room type.
Listen for events corresponding to the subscribed room type to receive real-time price updates.
Available room type
Room Name: price-by-token:{token-address}
Sample code
const { io } = require('socket.io-client');
const token = 'So11111111111111111111111111111111111111112'
const roomType = `price-by-token:${token}`
// Connect to the WebSocket server at the specified URL.
const socket = io('https://price.astralane.io/', {
extraHeaders: {
'x-api-key': 'YOUR_API_KEY_HERE'
}
});
// Listen for the connection event.
socket.on('connect', () => {
console.log('Connected to server');
// Once connected, subscribe to a specific price feed.
// The subscription message includes a type that specifies the feed.
socket.emit('subscribe', { type: roomType });
});
// Listen for disconnection.
socket.on('disconnect', () => {
console.log('Disconnected from server');
});
// Optionally, listen for a custom event (e.g., "price-by-token:token") to receive real-time price updates.
socket.on(`${roomType}`, (data) => {
console.log('Price update received:', data);
});