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.

Live DEX swap stream (Base)

Crypto Trades API: one row per swap, with USD and supply. Filter Pair.Market.Network: Base. When to use this vs chain DEX APIs.

Run this subscription in the Bitquery IDE.

subscription {
Trading {
Trades(where: { Pair: { Market: { Network: { is: "Base" } } } }) {
Side
Supply {
MaxSupply
TotalSupply
FullyDilutedValuationUsd
CirculatingSupply
MarketCap
}
Trader {
Address
}
TransactionHeader {
Fee
FeePayer
Sender
To
Hash
Index
}
Amounts {
Base
Quote
}
AmountsInUsd {
Base
Quote
}
Block {
Date
Time
Timestamp
}
Pair {
Currency {
Id
Name
Symbol
}
Market {
Address
Program
Network
}
QuoteCurrency {
Id
Name
Symbol
}
Token {
Address
Id
IsNative
Symbol
TokenId
Network
}
QuoteToken {
Address
Id
IsNative
Symbol
TokenId
Network
}
}
Price
PriceInUsd
}
}
}

Subscribe to Latest Base Trades

This example uses the chain-specific DEXTrades cube via EVM(network: base) { DEXTrades } (pool-side Buy/Sell; see DEXTrades cube). USD can be weak on small tokens. For trader + USD swap rows, use the stream at the top.

Read DEXTrades vs DEXTradeByTokens vs Trades cube to get a better understanding on when to use which cube. 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 First 500 Buyers of a specific token

Below API gets you the first 500 buyers of a specific Base chain token, here as example we have taken this token 0x58538e6A46E07434d7E7375Bc268D3cb839C0133. Try the API here.

query MyQuery {
EVM(network: base, dataset: combined) {
DEXTrades(
limit: { count: 500 }
orderBy: { ascending: Block_Time }
limitBy: { count: 1, by: Trade_Sell_Buyer }
where: {
Trade: {
Sell: {
Currency: {
SmartContract: {
is: "0x58538e6A46E07434d7E7375Bc268D3cb839C0133"
}
}
}
}
}
) {
Block {
Time
}
Trade {
Sell {
Buyer
}
}
Transaction {
From
Hash
}
}
}
}

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"
)
}
}
}

Aggregated Token Data (Volume & Price, Last 24h)

Get up to 100 tokens with aggregated USD volume and average price over the last 24 hours, plus volume and price for 1h, 4h, and 24h via conditional metrics (Trading API; includes Base and other chains).

▶️ Aggregated Token Data

{
Trading {
Tokens(
limit: { count: 100 }
limitBy: { count: 1, by: Token_Id }
where: { Block: { Time: { since_relative: { hours_ago: 24 } } } }
) {
Token {
Address
Id
IsNative
Name
Network
Symbol
TokenId
}
Volume {
Usd
H1VAgo: Usd(if: { Block: { Time: { since_relative: { hours_ago: 1 } } } })
H4VAgo: Usd(if: { Block: { Time: { since_relative: { hours_ago: 4 } } } })
H24VAgo: Usd(if: { Block: { Time: { since_relative: { hours_ago: 24 } } } })
}
Price {
Average {
currentPrice: Mean(maximum: Block_Time)
H1Ago: Mean(
minimum: Block_Time
if: { Block: { Time: { since_relative: { hours_ago: 1 } } } }
)
H4Ago: Mean(
minimum: Block_Time
if: { Block: { Time: { since_relative: { hours_ago: 4 } } } }
)
H24Ago: Mean(
minimum: Block_Time
if: { Block: { Time: { since_relative: { hours_ago: 24 } } } }
)
}
}
}
}
}

Trader-Focused Trade APIs (with USD Price, Market Cap & Supply)

The queries below use the Trades cube (Trading { Trades }) which is trader-focused and provides reliable USD prices including for all tokens. See DEXTrades vs DEXTradeByTokens vs Trades cube for when to use which.

Get All DEX Trades on Base With Price, Market Cap, and Supply

Stream all Base DEX trades in real time with USD price, market cap, FDV, circulating supply, and transaction fee data. Filter by Pair.Market.Network: Base to capture every swap across all Base DEXs in a single subscription.

You can run this subscription in the Bitquery IDE.

Click to expand GraphQL query
subscription {
Trading {
Trades(where: { Pair: { Market: { Network: { is: "Base" } } } }) {
Side
Supply {
MaxSupply
TotalSupply
FullyDilutedValuationUsd
CirculatingSupply
MarketCap
}
Trader {
Address
}
TransactionHeader {
Fee
FeePayer
Sender
To
Hash
Index
}
Amounts {
Base
Quote
}
AmountsInUsd {
Base
Quote
}
Block {
Date
Time
Timestamp
}
Pair {
Currency {
Id
Name
Symbol
}
Market {
Address
Program
Network
}
QuoteCurrency {
Id
Name
Symbol
}
Token {
Address
Id
IsNative
Symbol
TokenId
Network
}
QuoteToken {
Address
Id
IsNative
Symbol
TokenId
Network
}
}
Price
PriceInUsd
}
}
}

Top Traders by PnL for a Specific Pool (Last 30 Minutes)

Rank traders by PnL on one pool: filter Pair.Market.Address, last 30 minutes, limit: 10, and orderBy PnL descending. Useful for leaderboards, smart-money screens, and pool-specific trader analytics.

You can run this query in the Bitquery IDE.

Click to expand GraphQL query
{
Trading {
Trades(
limit: { count: 10 }
orderBy: { descendingByField: "PnL" }
where: {
Block: { Time: { since_relative: { minutes_ago: 30 } } }
Pair: {
Market: {
Address: { is: "0x0bfbcf9fa4f9c56b0f40a671ad40e0805a091865" }
}
}
}
) {
Trader {
Address
}
Amount_Bought: sum(of: AmountsInUsd_Base, if: { Side: { is: "Buy" } })
Amount_Sold: sum(of: AmountsInUsd_Base, if: { Side: { is: "Sell" } })
Amount_Bought_native: sum(of: Amounts_Base, if: { Side: { is: "Buy" } })
Amount_Sold_native: sum(of: Amounts_Base, if: { Side: { is: "Sell" } })
PnL: calculate(expression: "$Amount_Sold - $Amount_Bought")
buys: count(if: { Side: { is: "Buy" } })
sells: count(if: { Side: { is: "Sell" } })
}
}
}

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