market:dex:trades

Subscribes/Unsubscribes to DEX (decentralized exchange) trade data.

👍

Blockchains Supported

This subscription only supports data on ethereum-mainnet.

🚧

Subscription Namespace

Please ensure that you are connected to ws.web3api.io/defi/dex.

📘

Subscription Data

This websocket subscription returns latest trades instead of the historical trades as seen in the REST endpoint DEX Trades Historical.

Getting Started

Make sure you're connected.

Request

Parameters

Parameter NameTypeDescription
exchangestringThe exchange contract address.
poolstringThe token pair contract address.

Examples

All trades for a specific exchange

{
  "jsonrpc": "2.0",
  "id":1,
  "method": "subscribe",
  "params":[
    "market:dex:trades",
    {
      "exchange": "0x1f98431c8ad98523631ae4a59f267346ea31f984"
    }
  ]
}
wscat -c 'wss://ws.web3api.io/defi/dex?x-api-key=<YOUR KEY HERE>' -x '{ "jsonrpc": "2.0", "id": 1234, "method": "subscribe", "params": ["market:dex:trades", { "exchange": "0x1f98431c8ad98523631ae4a59f267346ea31f984" }] }' -w 30

🚧

Filtering by exchange

This subscription also uses the parameter exchange as seen in DEX Trades Historical.

However, the subscription ONLY accepts the address for the value of exchange. There is currently no support for human-readable exchange names.

You can get the address for each exchange from DEX Exchanges Information.

All trades for a specific pool (token pair)

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "subscribe",
  "params": [
    "market:dex:trades",
    {
      "pool": "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640"
    }
  ]
}
wscat -c 'wss://ws.web3api.io/defi/dex?x-api-key=<YOUR KEY HERE>' -x '{ "jsonrpc": "2.0", "id": 1234, "method": "subscribe", "params": ["market:dex:trades", { "pool": "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640" }] }' -w 30

🚧

Filtering by pool (token pair)

This subscription also uses the parameter pool as seen in DEX Trades Historical.

However, the subscription ONLY accepts the address for the value of pool. There is currently no support for human-readable pool names.

You can get the address for each pool from DEX Trades Information. Set the query parameter includeMetadata=true and extract the value of address at the path payload.{exchange}.{pair}.address.

Example payload.sushiswap.SEC_WETH.address

All trades for a specific exchange and specific pool

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "subscribe",
  "params": [
    "market:dex:trades",
    {
      "exchange": "0x1f98431c8ad98523631ae4a59f267346ea31f984", //uniswapv3
      "pool": "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640" //USDC-ETH
    }
  ]
}
wscat -c 'wss://ws.web3api.io/defi/dex?x-api-key=<YOUR KEY HERE>' -x '{ "jsonrpc": "2.0", "id": 1234, "method": "subscribe", "params": ["market:dex:trades", { "pool": "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640", "exchange": "0x1f98431c8ad98523631ae4a59f267346ea31f984" }] }' -w 30

Response

{
  "jsonrpc": "2.0",
  "method": "subscription",
  "params": {
    "subscription": "gmj9wgfy5kxyxpab8061ok1cdgcb6xyqmy7qmsmlkdmccwxpjdsmvqnhdhu07oav",
    "result": {
      "exchange": "0x1f98431c8ad98523631ae4a59f267346ea31f984",
      "timestamp": 1677879275000,
      "timestampNanoseconds": 0,
      "isBuy": true,
      "price": "1561.515167728236326947758801608499",
      "volume": "0.607253562819717329",
      "tradeId": "0x29978e6d6bc0c17bb008b89fe46a16bf8e9556c641512793aece292a75658786",
      "logIndex": 12,
      "pairAddress": "0x4e68ccd3e89f51c3074ca5072bbac773960dfa36",
      "amountInBase": "0",
      "amountInQuote": "948.235649",
      "amountOutBase": "0.607253562819717329",
      "amountOutQuote": "0",
      "fromAddress": "0xe592427a0aece92de3edee1f18e0157c05861564",
      "toAddress": "0x767af52d988d1241a346851a1b39ccd11357376e"
    }
  }
}

For information about each property in the response, please refer to DEX Trades Historical