Skip to main content

DEX API

Before you start: Not sure when to use DexTrades vs DexTradesByTokens vs Events vs Calls? Read our Mental Model guide to understand which primitive to use for your use case.

We have two main APIs to get DEX trading data.

  • DEXTrades
  • DEXTradeByTokens

To learn the difference between two APIs, please check this doc.

Get all the DEXs info on a Ethereum network

This query will fetch you all the DEXs info for the selected network. You can test the query here.

query DexMarkets($network: evm_network) {
EVM(network: $network) {
DEXTradeByTokens {
Trade {
Dex {
ProtocolFamily
}
}
buyers: uniq(of: Trade_Buyer)
sellers: uniq(of: Trade_Sender)
count(if: {Trade: {Side: {Type: {is: buy}}}})
}
}
}
{
"network": "eth"
}

image

You can check the data here on DEXrabbit.

Get a specific DEX statistics

This query will fetch you a specific DEX stats for the selected network. You can test the query here.

query DexMarkets($network: evm_network, $market: String) {
EVM(network: $network) {
DEXTradeByTokens(
orderBy: {ascendingByField: "Block_Time"}
where: {Trade: {Dex: {ProtocolFamily: {is: $market}}}}
) {
Block {
Time(interval: {count: 1, in: hours})
}
trades: count
buyers: uniq(of: Trade_Buyer)
sellers: uniq(of: Trade_Sender)
tokens: uniq(of: Trade_Currency_SmartContract)
}
}
}
{
"market": "Uniswap",
"network": "eth"
}

image

You can check the data here on DEXrabbit.

Get All Trading Pairs on a particular DEX

This query will fetch you all trading pairs on a particular DEX for the selected network. You can test the query here.

query DexMarkets($network: evm_network, $market: String, $time_10min_ago: DateTime, $time_1h_ago: DateTime, $time_3h_ago: DateTime) {
EVM(network: $network) {
DEXTradeByTokens(
orderBy: {descendingByField: "usd"}
where: {Trade: {Dex: {ProtocolFamily: {is: $market}}}, Block: {Time: {after: $time_3h_ago}}}
limit: {count: 200}
) {
Trade {
Currency {
Symbol
Name
SmartContract
Fungible
}
Side {
Currency {
Symbol
Name
SmartContract
}
}
price_usd: PriceInUSD(maximum: Block_Number)
price_last: Price(maximum: Block_Number)
price_10min_ago: Price(
maximum: Block_Number
if: {Block: {Time: {before: $time_10min_ago}}}
)
price_1h_ago: Price(
maximum: Block_Number
if: {Block: {Time: {before: $time_1h_ago}}}
)
price_3h_ago: PriceInUSD(minimum: Block_Number)
}
usd: sum(of: Trade_AmountInUSD)
count
}
}
}
{
"market": "Uniswap",
"network": "eth",
"time_10min_ago": "2024-09-22T13:21:39Z",
"time_1h_ago": "2024-09-22T12:31:39Z",
"time_3h_ago": "2024-09-22T10:31:39Z"
}

image

You can check the data here on DEXrabbit.

Top Traders on a DEX

This query will fetch you Top Traders on a particular DEX for the selected network. You can test the query here.

query DexMarkets($network: evm_network, $market: String) {
EVM(network: $network) {
DEXTradeByTokens(
orderBy: {descendingByField: "volumeUsd"}
limit: {count: 100}
where: {Trade: {Dex: {ProtocolFamily: {is: $market}}}}
) {
Trade {
Buyer
Dex {
OwnerAddress
ProtocolFamily
ProtocolName
}
Currency {
SmartContract
Symbol
Name
}
Side {
Currency {
SmartContract
Symbol
Name
}
}
}
volumeUsd: sum(of: Trade_Side_AmountInUSD)
}
}
}
{
"market": "Uniswap",
"network": "eth"
}

image

You can check the data here on DEXrabbit.

Latest Trades on a DEX

This query will fetch you latest trades on a particular DEX for the selected network. You can test the query here.

query LatestTrades($network: evm_network, $market: String) {
EVM(network: $network) {
DEXTradeByTokens(
orderBy: {descending: Block_Time}
limit: {count: 50}
where: {Trade: {Dex: {ProtocolFamily: {is: $market}}}}
) {
Block {
Time
}
Transaction {
Hash
}
Trade {
Dex {
OwnerAddress
ProtocolFamily
ProtocolName
}
AmountInUSD
Price
Amount
Side {
Type
Currency {
Symbol
SmartContract
Name
}
AmountInUSD
Amount
}
Currency {
Symbol
SmartContract
Name
}
}
}
}
}
{
"market": "Uniswap",
"network": "eth"
}

image

You can check the data here on DEXrabbit.