Skip to main content

Base Chain DEX Trades API

In this section we will see how to get Base DEX trades information using our API.

Subscribe to Latest Base Trades​

This subscription will return information about the most recent trades executed on Base's DEX platforms. You can find the query here

subscription MyQuery {
EVM(network: base) {
DEXTrades {
Block {
Time
Number
}
Transaction {
Hash
}
Call {
Signature {
Name
Signature
}
}
Log {
Index
SmartContract
Signature {
Signature
Name
}
}
Trade {
Sender
Buy {
Buyer
AmountInUSD
Amount
Seller
PriceInUSD
Price
Currency {
Name
Symbol
SmartContract
}
}
Dex {
SmartContract
ProtocolName
ProtocolVersion
}
Sell {
Buyer
AmountInUSD
Amount
Seller
PriceInUSD
Price
Currency {
Name
Symbol
SmartContract
}
}
}
}
}
}

Subscribe to Latest Price of a Token in Real-time​

This query provides real-time updates on price of USDC 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 in terms of DAI 0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb, including details about the DEX, market, and order specifics. Find the query here

subscription {
EVM(network: base) {
DEXTrades(
where: {Trade: {Sell: {Currency: {SmartContract: {is: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"}}}, Buy: {Currency: {SmartContract: {is: "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb"}}}}}
) {
Block {
Time
}
Trade {
Buy {
Amount
Buyer
Seller
Price_in_terms_of_sell_currency: Price
Currency {
Name
Symbol
SmartContract
}
}
Sell {
Amount
Buyer
Seller
Price_in_terms_of_buy_currency: Price
Currency {
Symbol
SmartContract
Name
}
}
}
}
}
}



Latest USD Price of a Token​

The below query retrieves the USD price of a token on Base chain by setting SmartContract: {is: "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb"} . Check the field PriceInUSD for the USD value. You can access the query here.

subscription {
EVM(network: base) {
DEXTradeByTokens(
where: {Trade: {Currency: {SmartContract: {is: "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb"}}}}
) {
Transaction {
Hash
}
Trade {
Buyer
AmountInUSD
Amount
Price
PriceInUSD
Seller
Currency {
Name
Symbol
SmartContract
}
Dex {
ProtocolFamily
SmartContract
ProtocolName
}
Side {
Amount
AmountInUSD
Buyer
Seller
Currency {
Name
SmartContract
Symbol
}
}
}
}
}
}


Get Price Change 5min, 1h, 6h and 24h of a specific token​

Use below query to get price change 5min, 1h, 6h and 24h of a specific token. Change the Currency{SmartContract} and Dex{SmartContract} according to your needs. Test the query [here] (https://ide.bitquery.io/Price-change-5min-1hr-6hr-24h-precentage-of-a-specific-token).

query MyQuery {
EVM(dataset: combined network:base) {
DEXTradeByTokens(
where: {Trade: {Currency: {SmartContract: {is: "0x1111111111166b7FE7bd91427724B487980aFc69"}}, Dex: {SmartContract: {is: "0xEdc625B74537eE3a10874f53D170E9c17A906B9c"}}}, TransactionStatus: {Success: true}, Block: {Time: {since_relative: {hours_ago: 24}}}}
){
Trade {
Price_5min_ago: PriceInUSD(minimum:Block_Number if:{Block:{Time:{since_relative:{minutes_ago:5}}}})
Price_1h_ago: PriceInUSD(minimum:Block_Number if:{Block:{Time:{since_relative:{hours_ago:1}}}})
Price_6h_ago: PriceInUSD(minimum: Block_Number if:{Block:{Time:{since_relative:{hours_ago:6}}}})
Price_24h_ago: PriceInUSD(minimum: Block_Number)
CurrentPrice: PriceInUSD(maximum: Block_Number)
}
volume_5min: sum(
of: Trade_Side_AmountInUSD
if: {Block: {Time: {since_relative: {minutes_ago: 5}}}}
)
volume_1h: sum(
of: Trade_Side_AmountInUSD
if: {Block: {Time: {since_relative: {hours_ago: 1}}}}
)
volume_6h: sum(
of: Trade_Side_AmountInUSD
if: {Block: {Time: {since_relative: {hours_ago: 6}}}}
)
volume_24h: sum(
of: Trade_Side_AmountInUSD
)
Price_Change_5min: calculate(expression: "(($Trade_CurrentPrice - $Trade_Price_5min_ago) / $Trade_Price_5min_ago) * 100")
Price_Change_1h: calculate(expression: "(($Trade_CurrentPrice - $Trade_Price_1h_ago) / $Trade_Price_1h_ago) * 100")
Price_Change_6h: calculate(expression: "(($Trade_CurrentPrice - $Trade_Price_6h_ago) / $Trade_Price_6h_ago) * 100")
Price_Change_24h: calculate(expression: "(($Trade_CurrentPrice - $Trade_Price_24h_ago) / $Trade_Price_24h_ago) * 100")
}
}
}

Top 10 Base Tokens by Price Change in last 1h​

Use below query to get top 10 Base Tokens by Price Change in last 1h. Test the query [here] (https://ide.bitquery.io/Top-10-base-tokens-by-price-change-in-last-1-hr).

query MyQuery {
EVM(dataset: combined network:base) {
DEXTradeByTokens(
limit:{count:10}
orderBy:{descendingByField:"Price_Change_1h"}
where: {TransactionStatus: {Success: true}, Block: {Time: {since_relative: {hours_ago: 24}}}}
) {
Trade {
Currency {
Name
Symbol
SmartContract
}
Price_5min_ago: PriceInUSD(
minimum: Block_Number
if: {Block: {Time: {since_relative: {minutes_ago: 5}}}}
)
Price_1h_ago: PriceInUSD(
minimum: Block_Number
if: {Block: {Time: {since_relative: {hours_ago: 1}}}}
)
Price_6h_ago: PriceInUSD(
minimum: Block_Number
if: {Block: {Time: {since_relative: {hours_ago: 6}}}}
)
Price_24h_ago: PriceInUSD(minimum: Block_Number)
CurrentPrice: PriceInUSD(maximum: Block_Number)
Side {
Currency {
Name
Symbol
SmartContract
}
}
Dex{
SmartContract
}
}

volume_5min: sum(
of: Trade_Side_AmountInUSD
if: {Block: {Time: {since_relative: {minutes_ago: 5}}}}
)
volume_1h: sum(
of: Trade_Side_AmountInUSD
if: {Block: {Time: {since_relative: {hours_ago: 1}}}}
)
volume_6h: sum(
of: Trade_Side_AmountInUSD
if: {Block: {Time: {since_relative: {hours_ago: 6}}}}
)
volume_24h: sum(of: Trade_Side_AmountInUSD)
Price_Change_5min: calculate(
expression: "(($Trade_CurrentPrice - $Trade_Price_5min_ago) / $Trade_Price_5min_ago) * 100"
)
Price_Change_1h: calculate(
expression: "(($Trade_CurrentPrice - $Trade_Price_1h_ago) / $Trade_Price_1h_ago) * 100"
)
Price_Change_6h: calculate(
expression: "(($Trade_CurrentPrice - $Trade_Price_6h_ago) / $Trade_Price_6h_ago) * 100"
)
Price_Change_24h: calculate(
expression: "(($Trade_CurrentPrice - $Trade_Price_24h_ago) / $Trade_Price_24h_ago) * 100"
)
}
}
}

Video Tutorial | How to get Base Decentralized Exchange Data with DEX Trades API​