Astralane
  • Welcome to Astralane
  • 🚅Low Latency
    • Quickstart
    • Endpoints and Configs
    • Submit Transactions
  • 🔍Data Pipelines
    • Overview
    • Our Products
      • Authentication
      • Dex Pools API
        • Latest Dex Pools API
      • OHLCV API
      • Websocket - Token price and Volume
      • Trade Data - Dex trades
      • PnL Indexer
      • Historical Token Portfolio
      • Top 100 Token Holders
      • Token Price API
      • Historical Token Price API
      • Profitable Wallets
      • Wallet PnL API
      • Trasaction Indexer
  • Japanese Docs
    • 🌌 Astralane ドキュメント
      • 低遅延 -クイックスタート
      • 🚅 エンドポイントと設定
      • トランザクションの送信
  • Mandarin Docs
    • 🌌 欢迎来到 Astralane
      • 低延迟快速入门
      • 🚅 端点和配置
      • 提交交易
Powered by GitBook
On this page
  • Connection Workflow
  • Available room type
  • Sample code
  • Response
  • Errors
  • 1. Invalid Subscription Format
  • 2. Duplicate Subscription
  • 3. Disconnection
  1. Data Pipelines
  2. Our Products

Websocket - Token price and Volume

token price websocket API

PreviousOHLCV APINextTrade Data - Dex trades

Last updated 1 month ago

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.

  1. Connect to the socket URL utilizing the Socket.IO client.

  2. Subscribe to your preferred room type.

  3. 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);
});

Response

{
    "timestamp": "1741771359",
    "decimals": 9,
    "name": "Wrapped SOL",
    "symbol": "SOL",
    "logoURI": "https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/So11111111111111111111111111111111111111112/logo.png",
    "marketCap": 74104722584.46233,
    "supply": 509384498.1158462,
    "price_in_sol": 1,
    "price_in_usd": 124.3285941413753,
    "token": "So11111111111111111111111111111111111111112"
}

Errors

1. Invalid Subscription Format


{
  "message": "Invalid subscription format. Use {operation}-by-{token|pool}:{identifier}"
}

2. Duplicate Subscription


{
  "message": "Already subscribed to price-by-token:So11111111111111111111111111111111111111112"
}

3. Disconnection

In the event of a disconnection, the client must automatically reconnect and resubscribe to continue receiving uninterrupted real-time updates.

🔍
https://price.astralane.io