market:dex:trades [ENT]

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

Make sure you're connected.

Request

All pairs:

{"jsonrpc":"2.0","id":1,"method":"subscribe","params":["market:dex:trades"]}

Specific exchange:

{"jsonrpc":"2.0","id":1,"method":"subscribe","params":["market:dex:trades",{"exchangeId":"0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f"}]}

Specific pair:

{"jsonrpc":"2.0","id":1,"method":"subscribe","params":["market:dex:trades",{"pairAddress":"0xa478c2975ab1ea89e8196811f51a7b7ade33eb11"}]}

NOTE: "pairAddress" specifies an address rather than a "base_quote" because DEX pair naming has collisions and data returned might not match expected results. Please use REST: DEX - Trades / Information to get pairAddress by pair name.

Param

Type

Description

pairAddress

string

The asset pair contract address.

exchangeId

string

The exchange contract address for which to retrieve asset pairs. For example Uniswap exchange ID is the contract address of the Factory contract: 0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f

Note: Subscription response will include a field metadata which includes the names of the columns in the order in which they appeared in the event notification response.

Response

"result": [
  [
    "0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac",  // exchange
    "0x795065dcc9f64b5614c407a6efdc400da6221fb0",  // pairAddress
    1607985374000, // timestamp
    0, // timestampNanoseconds
    "0x1887fb9d3186ad1f617c2e61bc82c6d8b2623900ba41184f2d17a483ec8f0d13", // transactionHash
    "232.32695538834162706001", // price
    "123.602985674524116757", // size
    false, // isBuy
    73, // transactionIndex
    277, // logIndex
    "0xd9e1ce17f2641f24ae83637ab66a2cca9c378b9f", // fromAddress
    "0xd9e1ce17f2641f24ae83637ab66a2cca9c378b9f", // toAddress
    "123.602985674524116757", // amountBaseIn
    "0", // amountQuoteIn
    "0", // amountBaseOut
    "0.53202171684261922"  // amountQuoteOut
  ]
]

Field

Type

Description

exchangeId

string

The exchange contract address for which to retrieve asset pairs. For example Uniswap exchange ID is the contract address of the Factory contract: 0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f

timestamp

number

The time at which the trade took place.

timestampNanoseconds

number

The nano second part of the timestampMilliseconds, where applicable.

transactionHash

string

The transaction hash of where an exchange trade was excuted on chain.

price

string

The quote price of the asset pair.

volume

string

The number of assets traded in a specific asset pair within a given period of time.

isBuy

bool

Indicates if it is a buy or sell trade: true for a buy trade and false for a sell.

transactionIndex

'string'

The index of a transaction inside a blockchain block

logIndex

string

The index of a log inside a blockchain transaction

fromAddress

string

The sender of a trade amount

toAddress

string

The receiver of a trade amount

amountBaseIn

string

The raw token amount in asset "base" sent in a trade

amountQuoteIn

string

The raw token amount in asset "quote" sent in a trade

amountBaseOut

string

The raw token amount in asset "base" received in a trade

amountQuoteOut

string

The raw token amount in asset "quote" received in a trade

Example

const WebSocket = require('ws');
const ws = new WebSocket('wss://ws.web3api.io/', {headers: {x-api-key:'<api_key>'}});

ws.on('open', () => {
  ws.send(JSON.stringify({
      jsonrpc: '2.0',
      method: 'subscribe',
      params: ["market:dex:trades",  {"pairAddress": "0xa478c2975ab1ea89e8196811f51a7b7ade33eb11"}], // DAI_WETH
      id: 1,
    }));
});

ws.on('message', data => {
  console.log(JSON.stringify(JSON.parse(data), null, 2));
});