Polygon (MATIC) DEX Trades API
In this section we will see how to get Matic DEX trades information using our API.
Live DEX swap stream (Polygon)
Crypto Trades API: one row per swap, with USD and supply. For Polygon use Pair.Market.Network: Matic. When to use this vs chain DEX APIs.
Run this subscription in the Bitquery IDE.
Click to expand GraphQL query
subscription {
Trading {
Trades(where: { Pair: { Market: { Network: { is: "Matic" } } } }) {
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 Matic Trades
This example uses the chain-specific DEXTrades cube via EVM(network: matic) { DEXTrades } (pool-side Buy/Sell; see DEXTrades cube). USD can be weak on thin pools. 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 {
EVM(network: matic) {
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
}
}
}
}
}
}
Subscribe to Latest Price of a Token in Real-time
This query provides real-time updates on price of AVAX 0x2C89bbc92BD86F8075d1DEcc58C7F4E0107f286b in terms of WMATIC 0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270, including details about the DEX, market, and order specifics. Find the query here
subscription {
EVM(network: matic) {
DEXTrades(
where: {Trade: {Sell: {Currency: {SmartContract: {is: "0x2C89bbc92BD86F8075d1DEcc58C7F4E0107f286b"}}}, Buy: {Currency: {SmartContract: {is: "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270"}}}}}
) {
Block {
Time
}
Trade {
Buy {
Amount
Buyer
Seller
Price_in_terms_of_sell_currency: Price
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 Matic by setting SmartContract: {is: "0xe06bd4f5aac8d0aa337d13ec88db6defc6eaeefe"} . Check the field PriceInUSD for the USD value. You can access the query here.
subscription {
EVM(network: matic) {
DEXTrades(
where: {Trade: {Buy: {Currency: {SmartContract: {is: "0xe06bd4f5aac8d0aa337d13ec88db6defc6eaeefe"}}}}}
) {
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 Top Gainers on Matic Network
This query retrieves information about the top-performing tokens on the Matic network based on trade volume and price appreciation in USD. It aggregates data from DEXs to provide insights into price trends over different time intervals like 10 minutes, 1 hour and 3 hours ago, and the overall trading volume.
We use any filter ( OR condition) to exclude $wmatic, $weth, $usdc, $usdt, $usdcpos, the smart contract addresses for common tokens on the Matic network from top tokens list.
You can run this query here
query pairs($min_count: String, $network: evm_network, $time_10min_ago: DateTime, $time_1h_ago: DateTime, $time_3h_ago: DateTime, $time_ago: DateTime, $wmatic: String!, $weth: String!, $usdc: String!, $usdt: String!, $usdcpos: String!) {
EVM(network: $network) {
DEXTradeByTokens(
where: {Block: {Time: {since: $time_ago}}, any: [{Trade: {Side: {Currency: {SmartContract: {is: $usdt}}}}}, {Trade: {Side: {Currency: {SmartContract: {is: $usdc}}}, Currency: {SmartContract: {notIn: [$usdt]}}}}, {Trade: {Side: {Currency: {SmartContract: {is: $usdcpos}}}, Currency: {SmartContract: {notIn: [$usdt, $usdc]}}}}, {Trade: {Side: {Currency: {SmartContract: {is: $weth}}}, Currency: {SmartContract: {notIn: [$usdc, $usdt, $usdcpos]}}}}, {Trade: {Side: {Currency: {SmartContract: {is: $wmatic}}}, Currency: {SmartContract: {notIn: [$weth, $usdc, $usdt, $usdcpos]}}}}, {Trade: {Side: {Currency: {SmartContract: {notIn: [$usdc, $usdt, $weth, $wmatic]}}}, Currency: {SmartContract: {notIn: [$usdc, $usdt, $weth, $wmatic, $usdcpos]}}}}]}
orderBy: {descendingByField: "usd"}
limit: {count: 100}
) {
Trade {
Currency {
Symbol
Name
SmartContract
ProtocolName
}
Side {
Currency {
Symbol
Name
SmartContract
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(
maximum: Block_Number
if: {Block: {Time: {before: $time_3h_ago}}}
)
}
dexes: uniq(of: Trade_Dex_OwnerAddress)
amount: sum(of: Trade_Side_Amount)
usd: sum(of: Trade_Side_AmountInUSD)
sellers: uniq(of: Trade_Seller)
buyers: uniq(of: Trade_Buyer)
count(selectWhere: {ge: $min_count})
}
}
}
{
"network": "matic",
"time_10min_ago": "2024-11-13T03:49:19Z",
"time_1h_ago": "2024-11-13T02:59:19Z",
"time_3h_ago": "2024-11-13T00:59:19Z",
"usdc": "0x3c499c542cef5e3811e1192ce70d8cc03d5c3359",
"usdcpos": "0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
"usdt": "0xc2132d05d31c914a87c6611c10748aeb04b58e8f",
"weth": "0x7ceb23fd6bc0add59e62ac25578270cff1b9f619",
"wmatic": "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270",
"min_count": "100"
}
This query is available as a heatmap on https://dexrabbit.com/matic

Top Traders of a Token
This query retrieves data on the top traders of a specific token on the Matic network. It aggregates trade volumes and categorizes them into bought and sold amounts, along with the total trading volume in both native and USD terms.
You can run the query here
query topTraders($network: evm_network, $time_ago: DateTime, $token: String) {
EVM(network: $network) {
DEXTradeByTokens(
orderBy: {descendingByField: "volumeUsd"}
limit: {count: 100}
where: {Trade: {Currency: {SmartContract: {is: $token}}}, Block: {Time: {since: $time_ago}}}
) {
Trade {
Buyer
Dex {
ProtocolFamily
}
}
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": "matic",
"token": "0x4dba7eb38ab96987b2b9c267f9d399da367194e0",
"time_ago": "2024-11-10T05:00:02Z"
}
This query is available as a chart and table on https://dexrabbit.com/matic

More examples
Trading API query below; for a full-network swap stream see above.
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: "0x5757371414417b8c6caad45baef941abc7d3ab32" }
}
}
}
) {
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" } })
}
}
}