Skip to main content

BSC DEX Trades API

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

Subscribe to Latest BSC Trades

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

subscription {
EVM(network: bsc) {
DEXTrades {
Block {
Time
}
Trade {
Dex {
ProtocolName
ProtocolFamily
SmartContract
}
Buy {
Amount
Buyer
Seller
Currency {
Decimals
Fungible
HasURI
Name
ProtocolName
SmartContract
Symbol
}
OrderId
}
Sell {
Buyer
Seller
Currency {
Decimals
Fungible
HasURI
Name
ProtocolName
SmartContract
Symbol
}
}
}
}
}
}


Latest Trades of a Token

This query will fetch you latest trades for a token for the BSC network. You can test the query here.

query LatestTrades($network: evm_network, $token: String) {
EVM(network: $network) {
DEXTradeByTokens(
orderBy: {descending: Block_Time}
limit: {count: 50}
where: {Trade: {Currency: {SmartContract: {is: $token}}, Price: {gt: 0}}}
) {
Block {
allTime: Time
}
Trade {
Dex {
OwnerAddress
ProtocolFamily
ProtocolName
}
AmountInUSD
Buyer
Seller
Side {
Type
Buyer
Seller
}
Price
Amount
Side {
Currency {
Symbol
SmartContract
Name
}
AmountInUSD
Amount
}
}
}
}
}
{
"network": "bsc",
"token": "0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c"
}

image

You can check the data here on DEXrabbit.

Top Traders of a token

This query will fetch you top traders of a token for the BSC network. You can test the query here.

query topTraders($network: evm_network, $token: String) {
EVM(network: $network) {
DEXTradeByTokens(
orderBy: {descendingByField: "volumeUsd"}
limit: {count: 100}
where: {Trade: {Currency: {SmartContract: {is: $token}}}}
) {
Trade {
Dex {
OwnerAddress
ProtocolFamily
ProtocolName
}
}
bought: sum(of: Trade_Amount, if: {Trade: {Side: {Type: {is: buy}}}})
sold: sum(of: Trade_Amount, if: {Trade: {Side: {Type: {is: sell}}}})
volume: sum(of: Trade_Amount)
volumeUsd: sum(of: Trade_Side_AmountInUSD)
}
}
}
{
"network": "bsc",
"token": "0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c"
}

image

You can check the data here on DEXrabbit.

Get all Trading Pairs data of a specific token

This query will fetch you all the trading pairs of a token for the BSC network. You can test the query here.

query tokenTrades($network: evm_network, $token: String, $time_10min_ago: DateTime, $time_1h_ago: DateTime, $time_3h_ago: DateTime) {
EVM(network: $network) {
DEXTradeByTokens(
orderBy: {descendingByField: "usd"}
where: {Trade: {Currency: {SmartContract: {is: $token}}}, 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
}
}
}
{
"network": "bsc",
"token": "0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c",
"time_10min_ago": "2024-09-22T14:36:55Z",
"time_1h_ago": "2024-09-22T13:46:55Z",
"time_3h_ago": "2024-09-22T11:46:55Z"
}

image

You can check the data here on DEXrabbit.

Get all DEXs where a specific token is listed

This query will fetch you all the DEXs where a token is listed for the BSC network. You can test the query here.

query tokenDexMarkets($network: evm_network, $token: String) {
EVM(network: $network) {
DEXTradeByTokens(
orderBy: {descendingByField: "amount"}
where: {Trade: {Currency: {SmartContract: {is: $token}}}}
) {
Trade {
Dex {
ProtocolFamily
ProtocolName
}
}
amount: sum(of: Trade_Amount)
pairs: uniq(of: Trade_Side_Currency_SmartContract)
trades: count
}
}
}
{
"network": "bsc",
"token": "0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c"
}

image

You can check the data here on DEXrabbit.

Get OHLC data of a token

This query will fetch you the OHLC of a token for the BSC network. You can test the query here.

query tradingView($network: evm_network, $token: String) {
EVM(network: $network) {
DEXTradeByTokens(
orderBy: {ascendingByField: "Block_Time"}
where: {Trade: {Currency: {SmartContract: {is: $token}}}}
) {
Block {
Time(interval: {count: 5, in: minutes})
}
Trade {
open: PriceInUSD(minimum: Block_Number)
close: PriceInUSD(maximum: Block_Number)
max: PriceInUSD(maximum: Trade_PriceInUSD)
min: PriceInUSD(minimum: Trade_PriceInUSD)
}
volume: sum(of: Trade_Side_AmountInUSD, selectWhere: {gt: "0"})
}
}
}
{
"network": "bsc",
"token": "0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c"
}

image

You can check the data here on DEXrabbit.

Latest Trades of a Token pair

This query will fetch you latest trades for a token pair for the BSC network. You can test the query here.

query LatestTrades($network: evm_network, $token: String, $base: String) {
EVM(network: $network) {
DEXTradeByTokens(
orderBy: {descending: Block_Time}
limit: {count: 50}
where: {Trade: {Side: {Amount: {gt: "0"}, Currency: {SmartContract: {is: $base}}}, Currency: {SmartContract: {is: $token}}, Price: {gt: 0}}}
) {
Block {
allTime: Time
}
Trade {
Dex {
OwnerAddress
ProtocolFamily
ProtocolName
}
Currency {
Symbol
SmartContract
Name
}
Price
AmountInUSD
Amount
Side {
Type
Currency {
Symbol
SmartContract
Name
}
AmountInUSD
Amount
}
}
}
}
}
{
"network": "bsc",
"token": "0x711bfe972465a1e9182766ad67aff3c80a0cf308",
"base": "0x55d398326f99059ff775485246999027b3197955"
}

image

You can check the data here on DEXrabbit.

Get OHLC data for a particular token pair

This query will fetch you the OHLC of a token pair for the BSC network. You can test the query here.

query tradingViewPairs($network: evm_network, $token: String, $base: String) {
EVM(network: $network) {
DEXTradeByTokens(
orderBy: {ascendingByField: "Block_Time"}
where: {Trade: {Side: {Amount: {gt: "0"}, Currency: {SmartContract: {is: $base}}}, Currency: {SmartContract: {is: $token}}}}
) {
Block {
Time(interval: {count: 5, in: minutes})
}
Trade {
open: PriceInUSD(minimum: Block_Number)
close: PriceInUSD(maximum: Block_Number)
max: PriceInUSD(maximum: Trade_PriceInUSD)
min: PriceInUSD(minimum: Trade_PriceInUSD)
}
volume: sum(of: Trade_Side_Amount)
}
}
}
{
"network": "bsc",
"token": "0x711bfe972465a1e9182766ad67aff3c80a0cf308",
"base": "0x55d398326f99059ff775485246999027b3197955"
}

image

You can check the data here on DEXrabbit.

Top Traders of a token pair

This query will fetch you top traders of a token pair for the BSC network. You can test the query here.

query pairTopTraders($network: evm_network, $token: String, $base: String) {
EVM(network: $network) {
DEXTradeByTokens(
orderBy: {descendingByField: "volumeUsd"}
limit: {count: 100}
where: {Trade: {Currency: {SmartContract: {is: $token}}, Side: {Amount: {gt: "0"}, Currency: {SmartContract: {is: $base}}}}}
) {
Trade {
Dex {
OwnerAddress
ProtocolFamily
ProtocolName
}
}
bought: sum(of: Trade_Amount, if: {Trade: {Side: {Type: {is: buy}}}})
sold: sum(of: Trade_Amount, if: {Trade: {Side: {Type: {is: sell}}}})
volume: sum(of: Trade_Amount)
volumeUsd: sum(of: Trade_Side_AmountInUSD)
}
}
}
{
"network": "bsc",
"token": "0x711bfe972465a1e9182766ad67aff3c80a0cf308",
"base": "0x55d398326f99059ff775485246999027b3197955"
}

image

You can check the data here on DEXrabbit.

Get all DEXs where a specific token pair is listed

This query will fetch you all the DEXs where a token pair is listed for the BSC network. You can test the query here.

query pairDexList($network: evm_network, $token: String, $base: String, $time_10min_ago: DateTime, $time_1h_ago: DateTime, $time_3h_ago: DateTime) {
EVM(network: $network) {
DEXTradeByTokens(
orderBy: {descendingByField: "amount"}
where: {Trade: {Currency: {SmartContract: {is: $token}}, Side: {Amount: {gt: "0"}, Currency: {SmartContract: {is: $base}}}}, Block: {Time: {after: $time_3h_ago}}}
) {
Trade {
Dex {
ProtocolFamily
ProtocolName
}
price_last: PriceInUSD(maximum: Block_Number)
price_10min_ago: PriceInUSD(
maximum: Block_Number
if: {Block: {Time: {before: $time_10min_ago}}}
)
price_1h_ago: PriceInUSD(
maximum: Block_Number
if: {Block: {Time: {before: $time_1h_ago}}}
)
price_3h_ago: PriceInUSD(minimum: Block_Number)
}
amount: sum(of: Trade_Side_Amount)
pairs: uniq(of: Trade_Side_Currency_SmartContract)
trades: count
}
}
}
{
"network": "bsc",
"token": "0x711bfe972465a1e9182766ad67aff3c80a0cf308",
"base": "0x55d398326f99059ff775485246999027b3197955",
"time_10min_ago": "2024-09-22T14:55:14Z",
"time_1h_ago": "2024-09-22T14:05:14Z",
"time_3h_ago": "2024-09-22T12:05:14Z"
}

image

You can check the data here on DEXrabbit.

Top Gainers

This query will fetch you top gainers for the BSC network. You can test the query here.

query ($network: evm_network) {
EVM(network: $network) {
DEXTradeByTokens(orderBy: {descendingByField: "usd"}, limit: {count: 100}) {
Trade {
Currency {
Symbol
Name
SmartContract
}
Side {
Currency {
Symbol
Name
SmartContract
}
}
price_last: PriceInUSD(maximum: Block_Number)
price_1h_ago: PriceInUSD(minimum: Block_Number)
}
dexes: uniq(of: Trade_Dex_OwnerAddress)
amount: sum(of: Trade_Side_Amount)
usd: sum(of: Trade_Side_AmountInUSD)
buyers: uniq(of: Trade_Buyer)
sellers: uniq(of: Trade_Seller)
count(selectWhere: {ge: "100"})
}
}
}
{
"network": "bsc"
}

image

You can check the data here on DEXrabbit.

Top Bought tokens

This query will fetch you top bought tokens for the BSC network. Arranged in descending order of bought - sold. You can test the query here.

query timeDiagram($network: evm_network) {
EVM(network: $network) {
DEXTradeByTokens(orderBy: {descendingByField: "buy"}, limit: {count: 100}) {
Trade {
Currency {
Symbol
Name
SmartContract
}
}
buy: sum(of: Trade_Side_AmountInUSD, if: {Trade: {Side: {Type: {is: buy}}}})
sell: sum(of: Trade_Side_AmountInUSD, if: {Trade: {Side: {Type: {is: sell}}}})
}
}
}
{
"network": "bsc"
}

image

You can check the data here on DEXrabbit.

Top Sold tokens

This query will fetch you top sold tokens for the BSC network. Arranged in descending order of sold - bought. You can test the query here.

query timeDiagram($network: evm_network) {
EVM(network: $network) {
DEXTradeByTokens(orderBy: {descendingByField: "sell"}, limit: {count: 100}) {
Trade {
Currency {
Symbol
Name
SmartContract
}
}
buy: sum(of: Trade_Side_AmountInUSD, if: {Trade: {Side: {Type: {is: buy}}}})
sell: sum(of: Trade_Side_AmountInUSD, if: {Trade: {Side: {Type: {is: sell}}}})
}
}
}
{
"network": "bsc"
}

image

You can check the data here on DEXrabbit.

Get all DEXs on BSC Network

This query retrieves all the DEXes operating on BSC network and gives info such as ProtocolName , ProtocolVersion and ProtocolFamily. Find the query here.

query MyQuery {
EVM(network: bsc, dataset: realtime) {
DEXTrades {
Trade {
Dex {
ProtocolName
ProtocolVersion
ProtocolFamily
}
}
count
}
}
}

Subscribe to Latest Price of a Token in Real-time on BSC

This query provides real-time updates on price of ETH 0x2170Ed0880ac9A755fd29B2688956BD959F933F8 in terms of WBNB 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c, including details about the DEX, market, and order specifics. Find the query here

subscription {
EVM(network: bsc) {
DEXTrades(
where: {Trade: {Sell: {Currency: {SmartContract: {is: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"}}}, Buy: {Currency: {SmartContract: {is: "0x2170Ed0880ac9A755fd29B2688956BD959F933F8"}}}}}
) {
Block {
Time
}
Trade {
Buy {
Amount
AmountInUSD
Buyer
Seller
Price_in_terms_of_sell_currency: Price
PriceInUSD
Currency {
Name
Symbol
SmartContract
}
OrderId
}
Sell {
Amount
Buyer
Seller
Price_in_terms_of_buy_currency: Price
Currency {
Symbol
SmartContract
Name
}
OrderId
}
Dex {
ProtocolFamily
ProtocolName
SmartContract
ProtocolVersion
}
}
}
}
}

Latest USD Price of a Token

The below query retrieves the USD price of a token on BSC by setting {Trade: {Buy: {Currency: {SmartContract: {is: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"}}}}} . Check the field PriceInUSD for the USD value. You can access the query here.

subscription {
EVM(network: bsc) {
DEXTrades(
where: {Trade: {Buy: {Currency: {SmartContract: {is: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"}}}}}
) {
Block {
Number
Time
}
Transaction {
From
To
Hash
}
Trade {
Buy {
Amount
Buyer
Currency {
Name
Symbol
SmartContract
}
Seller
Price
PriceInUSD
}
Sell {
Amount
Buyer
Currency {
Name
SmartContract
Symbol
}
Seller
Price
}
PriceAsymmetry(selectWhere: {lt: 1})
}
}
}
}

Get all the DEXs on BSC network

This query will fetch you all the DEXs info for the BSC 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": "bsc"
}

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 BSC 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": "bsc"
}

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 BSC 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": "bsc",
"time_10min_ago": "2024-09-22T15:11:25Z",
"time_1h_ago": "2024-09-22T14:21:25Z",
"time_3h_ago": "2024-09-22T12:21:25Z"
}

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 BSC 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 {
Dex {
OwnerAddress
ProtocolFamily
ProtocolName
}
Currency {
SmartContract
Symbol
Name
}
Side {
Currency {
SmartContract
Symbol
Name
}
}
}
volumeUsd: sum(of: Trade_Side_AmountInUSD)
}
}
}
{
"market": "Uniswap",
"network": "bsc"
}

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 BSC 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": "bsc"
}

image

You can check the data here on DEXrabbit.

Video Tutorial on BSC DEXTrades API | How to get BSC Decentralized Exchange Data with DEX Trades API