Latest price of buy currency against sell currency

Returns the latest DEX trade on Ethereum, where sell currency is 0x0645…6fb8 and buy currency is 0xc02a…6cc2: timestamp time, block height, trade index, protocol, full name, buy amount, buy currency symbol and 7 more fields.

By Vishal · saved 13 April 2024 · run 4 times · Bitquery API v1

What it returns

Filters

The query

query ($network: EthereumNetwork!, $sellCurrency: String!, $buyCurrency: String!) {
  ethereum(network: $network) {
    dexTrades(
      options: {desc: ["block.height", "tradeIndex"], limit: 1}
      
      sellCurrency: {is: $sellCurrency}
      buyCurrency: {is: $buyCurrency}
    ) {
      block {
        timestamp {
          time(format: "%Y-%m-%d %H:%M:%S")
        }
        height
      }
      tradeIndex
      protocol
      exchange {
        fullName
      }
      buyAmount
      buyCurrency {
        symbol
        address
        name
      }
      buy_amount_usd: buyAmount(in: USD)
      sellAmount
      sellCurrency {
        symbol
        address
        name
      }
      sell_amount_usd: sellAmount(in: USD)
      priceInUSD: expression(get: "sell_amount_usd / buyAmount")
    }
  }
}

Variables

{"buyCurrency": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "sellCurrency": "0x06450dee7fd2fb8e39061434babcfc05599a6fb8",
"network": "ethereum"}

Similar queries