DEX Market Trades API Reference

ยท

This API reference provides detailed information on how to retrieve recent transaction data for a specific token from decentralized exchanges (DEXs). It is designed for developers building applications that require real-time or historical trade data.

API Endpoint

The endpoint for accessing recent trades data is a GET request to the following URL:

https://web3.okx.com/api/v5/dex/market/trades

Required Request Parameters

To successfully call this API, you must include the following parameters in your request.

ParameterTypeRequiredDescription
chainIndexStringYesThe unique identifier for the blockchain network. For example, 1 represents Ethereum.
tokenContractAddressStringYesThe contract address of the token. For EVM-compatible chains, ensure the address is in all lowercase.

Optional Request Parameters

You can use these parameters to refine the data returned by your API call.

ParameterTypeRequiredDescription
afterStringNoUsed for pagination. Returns records that are older than the provided trade ID.
limitStringNoThe number of trade records to return per request. The default is 100, and the maximum allowed is 500.

Understanding the Response

A successful API call returns a list of recent trades with the following data points for each transaction.

ParameterTypeDescription
idStringA unique identifier for the trade.
chainIndexStringThe unique identifier for the blockchain where the trade occurred.
tokenContractAddressStringThe contract address of the token that was traded.
txHashUrlStringA URL to view the on-chain transaction hash for the trade.
userAddressStringThe wallet address that authorized the transaction.
dexNameStringThe name of the decentralized exchange where the trade was executed.
poolLogoUrlStringA URL to the logo image of the liquidity pool involved.
typeStringThe type of trade, either buy or sell.
changedTokenInfoStringInformation about the tokens that were exchanged.
> amountStringThe amount of the token that was exchanged in the trade.
> tokenSymbolStringThe symbol of the token that was exchanged.
> tokenContractAddressStringThe contract address of the token that was exchanged.
priceStringThe price of the token at the time of the trade.
volumeStringThe total USD value of the trade.
timeStringThe timestamp of the trade, in Unix milliseconds.
isFilteredStringIndicates if the trade was filtered for price calculations. 0 for not filtered, 1 for filtered.

How to Make a Request

Construct your API call by appending the required and any optional parameters to the base URL. Ensure all parameters are correctly formatted to avoid errors.

Example API Call Structure:
https://web3.okx.com/api/v5/dex/market/trades?chainIndex=1&tokenContractAddress=0x382bb369d343125bfb2117af9c149795c6c65c50&limit=100

Sample Response

A typical response will be a JSON object containing an array of trade objects, each populated with the data fields described in the response parameters table.

{
  "code": "0",
  "msg": "",
  "data": [
    {
      "id": "12345",
      "chainIndex": "1",
      "tokenContractAddress": "0x382bb369d343125bfb2117af9c149795c6c65c50",
      "txHashUrl": "https://etherscan.io/tx/0x...",
      "userAddress": "0xabcd...1234",
      "dexName": "Uniswap V3",
      "poolLogoUrl": "https://example.com/logo.png",
      "type": "buy",
      "changedTokenInfo": "...",
      "price": "1500.50",
      "volume": "3050.25",
      "time": "1640995200000",
      "isFiltered": "0"
    }
  ]
}

Common Use Cases and Applications

This API is fundamental for developers creating:

For developers looking to integrate real-time market data into their applications, this API provides a reliable stream of on-chain trade information ๐Ÿ‘‰ explore more strategies.

Frequently Asked Questions

What is the chainIndex parameter?
The chainIndex is a unique number that identifies a specific blockchain network. It ensures your API request queries the correct ledger. For instance, a chainIndex of 1 always refers to the Ethereum mainnet.

Why does my request return an error?
Common errors are caused by incorrect parameter formatting. Double-check that the tokenContractAddress is a valid, all-lowercase string and that the chainIndex corresponds to a supported network. Also, ensure you are not exceeding the limit of 500 records.

How does pagination work with the after parameter?
The after parameter is used to retrieve older trades. To paginate, take the id of the last trade from your current response and use it as the after value in your next request to fetch the previous batch of records.

What does isFiltered mean?
A trade marked as filtered (isFiltered=1) is typically excluded from official price and K-line calculations. This often happens with very large or very small trades that could skew the perceived market price, ensuring the data remains representative of typical market activity.

Can I get trades for any token?
Yes, as long as you have the correct contract address for the token and it has been traded on a DEX integrated with this API. You must also use the appropriate chainIndex for the blockchain on which the token resides.

How current is the trade data returned by this API?
The API provides data on recent transactions. The latency is typically very low, offering near real-time insights into market activity as trades are confirmed on the blockchain.