How to Query Historical Token Prices: A Comprehensive Guide

ยท

Understanding historical token prices is essential for traders, developers, and analysts in the Web3 ecosystem. This guide explains how to retrieve historical price data for native tokens, smart contract-based tokens, and Bitcoin inscription tokens (BRC-20, Runes, etc.) using OKX's Wallet API.


Supported Token Types

The historical price API supports:

  1. Native Tokens: Each blockchain's base currency (e.g., ETH for Ethereum).
  2. Smart Contract Tokens: ERC-20, BEP-20, and other standards.
  3. Bitcoin Inscription Tokens:

    • BRC-20 (e.g., ORDI)
    • Runes (e.g., Bitcoin Runes)
    • ARC-20 and SRC-20
  4. Fractal Bitcoin Chain Tokens: FBRC-20 inscriptions.

API Endpoint and Request Structure

Request Path

GET https://web3.okx.com/api/v5/wallet/token/historical-price

Key Parameters

ParameterTypeRequiredDescription
chainIndexStringYesBlockchain identifier (e.g., "1" for Ethereum)
tokenAddressStringNoContract address or inscription ID format (see below)
limitStringNoResults per page (max: 200)
periodStringNoTime interval (1m, 1h, 1d, etc.)

Token Address Formats:


Practical Examples

Example 1: Querying BRC-20 Token Prices

{
  "chainIndex": "bitcoin",
  "tokenAddress": "btc-brc20-ordi",
  "period": "1d"
}

Example 2: Fetching Ethereum Native Token History

{
  "chainIndex": "1",
  "tokenAddress": "",
  "begin": "1717200000000",
  "end": "1717286400000"
}

Response Format

The API returns:

{
  "prices": [
    {
      "time": "1717257600000",
      "price": "0.000000000000123456"
    }
  ]
}

Prices use 18-decimal precision.


FAQs

How far back can I query historical prices?

Data availability depends on the token and chain. Most major tokens have data from their launch date.

Why is my token address returning no results?

Verify:

  1. Correct chainIndex for the blockchain.
  2. Proper formatting for inscription tokens.
  3. The token exists/has trading history.

Can I get real-time prices with this API?

No, this endpoint retrieves historical data only. For live prices, use the market data API.


Advanced Tips

๐Ÿ‘‰ Maximize your API efficiency with batch requests and caching strategies.


Conclusion

This API provides granular historical price data for Web3 development, portfolio tracking, and market analysis. Always test queries with small date ranges before large historical pulls.