Market API

Trades Channel#

Retrieve the recent trades data. Data will be pushed whenever there is a trades.

Request URL

Please contact us dexapi@okx.com.

Request Parameters#

ParameterTypeRequiredDescription
opStringYesOperation, subscribe unsubscribe
argsArrayYesList of subscribed channels
channelStringYesChannel name,trades
chainIndexStringYesUnique identifier for the chain. (e.g., 1 for Ethereum. See ChainIndex)
tokenContractAddressStringYesToken contract address (e.g., 0x382bb369d343125bfb2117af9c149795c6c65c50)

Response Parameters#

ParameterTypeDescription
eventStringEvent, subscribe unsubscribe error
argObjectToken contract address
channelStringChannel name
chainIndexStringUnique identifier for the chain. (e.g., 1 for Ethereum. See ChainIndex)
tokenContractAddressStringToken contract address (e.g., 0x382bb369d343125bfb2117af9c149795c6c65c50)
codeStringError code
msgStringError message

Push Data Parameters#

ParameterTypeDescription
argObjectSuccessfully subscribed channel
> channelStringChannel name
> chainIndexStringUnique identifier for the chain. (e.g., 1 for Ethereum. See ChainIndex)
> tokenContractAddressStringToken contract address (e.g., 0x382bb369d343125bfb2117af9c149795c6c65c50)
dataArraySubscribed data
> idStringUnique trade id
> txHashUrlStringOn-chain txhash of the transaction
> userAddressStringAuthorizer of the transaction
> dexNameStringName of the dex where the trade occured
> poolLogoUrlStringPool logo url
> typeStringTrade Type buy sell
> amountExchangedStringAmount exchanged in this pair
>> amountStringToken exchanged amount in this trade
>> tokenSymbolStringToken symbol
>> tokenContractAddressStringToken contract address
> priceStringLatest token price
> volumeStringUSD value of this trade
> timeStringTimestamp of the trade, Unix timestamp format in milliseconds
> isFilteredStringIf the trade is filtered for price and k-line calculation.
0: not filtered 1: filtered

Request Example#

shell
{
  "op": "subscribe",
  "args": [
    {
      "channel": "trades",
      "chainIndex": "501",
      "tokenContractAddress": "HeLp6NuQkmYB4pYWo2zYs22mESHXPQYzXbB8n4V98jwC"
    }
  ]
}

Response Example#

200

Successful response example

{
  "event": "subscribe",
  "arg": {
    "channel": "trades",
    "chainIndex": "501",
    "tokenContractAddress": "HeLp6NuQkmYB4pYWo2zYs22mESHXPQYzXbB8n4V98jwC"
  },
  "connId": "a4d3ae55"
}

Failure response example

{
  "event": "error",
  "code": "60012",
  "msg": "Invalid request: {\"op\": \"subscribe\", \"argss\":[{ \"channel\" : \"trades\", \"chainIndex\" : \"501\", \"tokenContractAddress\" : \"HeLp6NuQkmYB4pYWo2zYs22mESHXPQYzXbB8n4V98jwC\"}]}",
  "connId": "a4d3ae55"
}

Push data example

{
  "arg": {
    "channel": "trades",
    "chainIndex": "501"
    "tokenContractAddress":"HeLp6NuQkmYB4pYWo2zYs22mESHXPQYzXbB8n4V98jwC"
  },
    "data":[
    {
    "id":"1739439633000!@#120!@#14731892839",
    "chainIndex": "501",
    "tokenContractAddress": "HeLp6NuQkmYB4pYWo2zYs22mESHXPQYzXbB8n4V98jwC",
    "txHashUrl": "https://solscan.io/tx/zgDzoiVG4XuDgQcoEg9vhpRyfyk5thNUQuTeTCeF289Qec5iraeCrUzPLyiE2UCviox2ebbTcsagGvzYF7M5uqs",
    "userAddress": "2kCm1RHGJjeCKL4SA3ZJCLyXqUD7nEJ7GMtVaP7c6jQ8",
    "dexName": "Orca Whirlpools",
    "poolLogoUrl": "https://static.okx.com/cdn/wallet/logo/dex_orcaswap.png",
    "type": "sell",
    "changedTokenInfo": [
    {
    "amount":"100.396595878",
    "tokenSymbol":"ai16z",
    "tokenContractAddress": "HeLp6NuQkmYB4pYWo2zYs22mESHXPQYzXbB8n4V98jwC"
    },
    {
    "amount":"2.482831",
    "tokenSymbol":"SOL",
    "tokenContractAddress": "So11111111111111111111111111111111111111112"
    }
    ]
    "price": "26.458143090226812",
    "volume": "519.788163",
    "time": "1739439633000",
    "isFiltered": "0"
    }
    ]
}