From a8f35a008cd298943e4fc9a97cda710c891f314a Mon Sep 17 00:00:00 2001 From: Gaurav Agarwal Date: Tue, 8 Sep 2026 09:38:37 +0530 Subject: [PATCH 1/2] docs: fix the stablecoin trades page: working depeg filters, live wallet, Tron stream Rewrites the stablecoin trades page so its examples run: the contradictory depeg filter becomes an any list with a USD floor and major counter tokens, the wallet example is a live USDC swapper, and the Tron stream uses the symbol filter that streams honour. Co-Authored-By: Claude Fable 5.1 --- docs/stablecoin-APIs/stablecoin-trades-api.md | 501 ++++++++++-------- 1 file changed, 279 insertions(+), 222 deletions(-) diff --git a/docs/stablecoin-APIs/stablecoin-trades-api.md b/docs/stablecoin-APIs/stablecoin-trades-api.md index 6c6f8e716..629d86747 100644 --- a/docs/stablecoin-APIs/stablecoin-trades-api.md +++ b/docs/stablecoin-APIs/stablecoin-trades-api.md @@ -1,90 +1,100 @@ --- -title: "Stablecoin Trades API" -description: "Stablecoin Trades API using Bitquery stablecoin APIs for prices, transfers, payments, and cross-chain monitoring workflows." +title: "Stablecoin Trades API: USDT and USDC DEX Trades, Depeg Checks and Wallet Flows" +sidebar_label: "Stablecoin Trades API" +description: "Stablecoin DEX trades on Ethereum, Solana and Tron via Bitquery GraphQL: live USDT streams, off-peg trade checks with a USD floor, a wallet's stablecoin flows." +keywords: + - stablecoin trades API + - USDT trades API + - USDC depeg API + - stablecoin price feed + - Tron USDT DEX trades --- -# Stablecoin Trades API -The Stablecoin API by Bitquery provides you the comprehensive set of APIs which can provide you realtime transfers, realtime trades, realtime price, holder distribution of stablecoins across chains with a single API call. +import FAQ from "@site/src/components/FAQ"; -We are going to particularly deep-dive into how to get Stablecoin Trades data in this section. +# Stablecoin Trades API: USDT and USDC DEX Trades, Depeg Checks and Wallet Flows -## Live USDT Trades Across All Chains (Trading API — recommended) +Stablecoins are the quote side of most DEX volume, so a stablecoin trade feed is close to a feed of everything. This page filters Bitquery's trade cubes down to one stablecoin at a time on Ethereum, Solana and Tron: the live trades, the trades that printed away from one dollar, and what one wallet did with its USDC. Every example runs in the [IDE](https://ide.bitquery.io) on a free account. Solana queries go to the `eap` endpoint, Ethereum and Tron to `graphql`. The [Trading cube](/docs/trading/crypto-trades-api/trades-api) gives the same trades across nine chains with USD on every row for the last month, which is the first section; the chain cubes below add history and per-pool detail. -For real-time trades (and anything in the last ~30 days), one [`Trading.Trades`](/docs/trading/crypto-trades-api/trades-api) subscription covers **9 chains** with **USD amounts on every row**, MEV-filtered — no separate query per chain. Run it [in the IDE](https://ide.bitquery.io/Trading-API-USDT-Trades-All-Chains); swap the `Currency` symbol for USDC or any other stablecoin. The chain-level `DEXTrades` / `DEXTradeByTokens` queries below remain the right tool for **history older than ~30 days** or call/event context. +## Live USDT trades across all chains + +One subscription, every chain, filtered on the symbol. ```graphql subscription { Trading { - Trades(where: {Pair: {Currency: {Symbol: {is: "USDT"}}}}) { - Block { Time } + Trades(where: { Pair: { Currency: { Symbol: { is: "USDT" } } } }) { + Block { + Time + } Price PriceInUsd - AmountsInUsd { Base Quote } + AmountsInUsd { + Base + Quote + } Pair { - Currency { Id Symbol } - Token { Symbol Network } - QuoteToken { Symbol } - Market { Network Protocol } + Currency { + Id + Symbol + } + Token { + Symbol + Network + } + QuoteToken { + Symbol + } + Market { + Network + Protocol + } } } } } ``` -For pre-built stablecoin dashboards (top tokens, flows, market activity), browse [DEXrabbit's Stablecoins category](https://dexrabbit.bitquery.io/categories/stablecoins). +For ready-made stablecoin dashboards, browse [DEXrabbit's Stablecoins category](https://dexrabbit.bitquery.io/categories/stablecoins). ## Ethereum -### Stablecoin trades for Ethereum +### USDT trades on Ethereum, live -Below stream will give you realtime **USDT** DEX trades on Ethereum. Test the stream [here](https://ide.bitquery.io/Stablecoin-trades-for-etheruem). +`DEXTradeByTokens` gives one row per trade with USDT under `Trade.Currency`, whichever side it was on. Saved stream [here](https://ide.bitquery.io/Stablecoin-trades-for-etheruem). ```graphql subscription { - EVM { - DEXTrades( - where: {any: [{Trade: {Buy: {Currency: {SmartContract: {is: "0xdAC17F958D2ee523a2206206994597C13D831ec7"}}}}}, {Trade: {Sell: {Currency: {SmartContract: {is: "0xdAC17F958D2ee523a2206206994597C13D831ec7"}}}}}]} + EVM(network: eth) { + DEXTradeByTokens( + where: { + Trade: { Currency: { SmartContract: { is: "0xdac17f958d2ee523a2206206994597c13d831ec7" } } } + } ) { Block { Time } Transaction { Hash - Index + From } Trade { - Index - Dex { - SmartContract - ProtocolFamily - ProtocolName - } - Buy { + Amount + AmountInUSD + Price + PriceInUSD + Side { + Type Amount - Buyer - Seller + AmountInUSD Currency { - Decimals - Fungible Symbol SmartContract - Name } - Price - PriceInUSD } - Sell { - Buyer - Seller - Currency { - Decimals - Fungible - Symbol - SmartContract - Name - } - Price - PriceInUSD + Dex { + ProtocolName + SmartContract } } } @@ -92,43 +102,57 @@ subscription { } ``` -### Stablecoin Depeg tracking Stream for EVM +### USDT trades away from the peg on Ethereum {#stablecoin-depeg-tracking-stream-for-evm} -Below stream tracks **USDT** on Ethereum when **PriceInUSD** is outside **0.95–1.05** (depeg-style band). Test the query [here](https://ide.bitquery.io/Stablecoin-Depeg-tracking-Stream-for-evm). +A depeg check has to ignore dust and thin pairs, or it fires all day. This query keeps trades against WETH or USDC worth over a thousand dollars whose USDT price printed more than half a percent from one dollar, over the last day. Two ranges on one field need `any`; a single `PriceInUSD: {lt, gt}` block is an AND and matches nothing. Widen the band or shorten the window for alerts, or run it as a subscription without the `Block` filter. Saved query [here](https://ide.bitquery.io/Stablecoin-Depeg-tracking-Stream-for-evm). ```graphql -subscription { - EVM { +{ + EVM(network: eth) { DEXTradeByTokens( - where: {Trade: {Currency: {SmartContract: {is: "0xdAC17F958D2ee523a2206206994597C13D831ec7"}}, PriceInUSD: {lt:0.95 gt: 1.05}}} + where: { + Trade: { + Currency: { SmartContract: { is: "0xdac17f958d2ee523a2206206994597c13d831ec7" } } + Side: { + AmountInUSD: { gt: "1000" } + Currency: { + SmartContract: { + in: [ + "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" + "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" + ] + } + } + } + } + any: [ + { Trade: { PriceInUSD: { lt: 0.995 } } } + { Trade: { PriceInUSD: { gt: 1.005 } } } + ] + Block: { Time: { since_relative: { hours_ago: 24 } } } + } + limit: { count: 50 } + orderBy: { descending: Block_Time } ) { + Block { + Time + } Transaction { Hash } Trade { - AmountInUSD - Amount - Buyer - Seller - Currency { - SmartContract - Name - } - Dex { - SmartContract - ProtocolName - } - Price PriceInUSD + Amount + AmountInUSD Side { - Buyer - Seller - AmountInUSD - Amount Currency { - Name - SmartContract + Symbol } + AmountInUSD + } + Dex { + ProtocolName + SmartContract } } } @@ -138,77 +162,61 @@ subscription { ## Solana -### Stablecoin trades +### USDT trades on Solana, live -Below stream will give you realtime trades of `USDT` on Solana. Test the stream [here](https://ide.bitquery.io/solana-trades-subscription_10_1). +Both sides of each swap, with the accounts and the market. Saved stream [here](https://ide.bitquery.io/solana-trades-subscription_10_1). ```graphql subscription { Solana { - DEXTrades (where:{any:[{Trade:{Buy:{Currency:{MintAddress:{is:"Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"}}}}},{Trade:{Sell:{Currency:{MintAddress:{is:"Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"}}}}}]}){ - Block{ + DEXTrades( + where: { + any: [ + { Trade: { Buy: { Currency: { MintAddress: { is: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB" } } } } } + { Trade: { Sell: { Currency: { MintAddress: { is: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB" } } } } } + ] + Transaction: { Result: { Success: true } } + } + ) { + Block { Time Slot } - Transaction{ + Transaction { Signature - Index - Result{ - Success - } + Signer } Trade { - Index Dex { ProgramAddress - ProtocolFamily ProtocolName } + Market { + MarketAddress + } Buy { Amount - Account { - Address - } - Currency { - MetadataAddress - Key - MintAddress - IsMutable - EditionNonce - Decimals - CollectionAddress - Fungible - Symbol - Native - Name - } + AmountInUSD Price PriceInUSD - Order { - LimitPrice - LimitAmount - OrderId + Currency { + Symbol + MintAddress } - - } - Market { - MarketAddress - } - Sell { Account { Address } + } + Sell { + Amount + AmountInUSD Currency { - IsMutable - Decimals - CollectionAddress - Fungible Symbol - Native - Name + MintAddress + } + Account { + Address } - Price - PriceInUSD } } } @@ -216,96 +224,148 @@ subscription { } ``` -### Real Time Stablecoin portfolio +### One wallet's stablecoin flows on Solana -Below stream will provide you the realtime portfolio updates for a particular address for a specific Stablecoin. In this query example, we are tracking portfolio updates for the address `3i51cKbLbaKAqvRJdCUaq9hsnvf9kqCfMujNgFj7nRKt` and for stablecoin `USDC`. -Test the query [here](https://ide.bitquery.io/real-time-stablecoin-portfolio_2). +Filter the transaction signer and the stablecoin mints. The example wallet swaps USDC many times an hour; the totals split what it bought from what it sold. Saved query [here](https://ide.bitquery.io/real-time-stablecoin-portfolio_2). ```graphql -subscription MyQuery { +{ Solana { DEXTradeByTokens( - where: {Transaction: {Result: {Success: true}}, Trade: {Currency: {MintAddress: {is: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"}}}, any: [{Trade: {Account: {Address: {is: "3i51cKbLbaKAqvRJdCUaq9hsnvf9kqCfMujNgFj7nRKt"}}}}, {Trade: {Account: {Owner: {is: "3i51cKbLbaKAqvRJdCUaq9hsnvf9kqCfMujNgFj7nRKt"}}}}, {Transaction:{Signer:{is: "3i51cKbLbaKAqvRJdCUaq9hsnvf9kqCfMujNgFj7nRKt"}}}]} + where: { + Transaction: { + Signer: { is: "3i51cKbLbaKAqvRJdCUaq9hsnvf9kqCfMujNgFj7nRKt" } + Result: { Success: true } + } + Trade: { + Currency: { + MintAddress: { + in: [ + "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" + "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB" + ] + } + } + } + Block: { Time: { since_relative: { hours_ago: 24 } } } + } + ) { + Trade { + Currency { + Symbol + MintAddress + } + } + trades: count + bought: sum(of: Trade_Amount, if: { Trade: { Side: { Type: { is: sell } } } }) + sold: sum(of: Trade_Amount, if: { Trade: { Side: { Type: { is: buy } } } }) + } + } +} +``` + +Drop the aggregates and the `Block` filter and subscribe to the same `where` for each swap as it happens: + +```graphql +subscription { + Solana { + DEXTradeByTokens( + where: { + Transaction: { + Signer: { is: "3i51cKbLbaKAqvRJdCUaq9hsnvf9kqCfMujNgFj7nRKt" } + Result: { Success: true } + } + Trade: { + Currency: { + MintAddress: { + in: [ + "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" + "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB" + ] + } + } + } + } ) { Block { Time } Trade { - Account { - Address - Token { - Owner - } - } - Amount - AmountInUSD Currency { - Name - MintAddress Symbol } - Dex { - ProtocolName - ProtocolFamily - ProgramAddress - } - Price - PriceInUSD + Amount + AmountInUSD Side { - Account { - Address - Token { - Owner - } + Type + Amount + Currency { + Symbol } } } Transaction { Signature - Signer } } } } ``` -### Stablecoin Depeg tracking Stream +### USDT trades away from the peg on Solana -Below stream will be able to track specific Stablecoin depeg. In this query example, we are tracking depeg for the stablecoin `EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v` which has a symbol `USDC`. -Test the query [here](https://ide.bitquery.io/stablecoin-depeg-tracking-stream-for-USDC). +Same band and floor as the Ethereum check, against USDC or WSOL so that thin memecoin pairs do not set off the alarm. Saved query [here](https://ide.bitquery.io/stablecoin-depeg-tracking-stream-for-USDC). ```graphql -subscription { +{ Solana { DEXTradeByTokens( - where: {Trade: {Currency: {MintAddress: {is: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"}}, PriceInUSD: {lt:0.95 gt: 1.05}}} + where: { + Trade: { + Currency: { MintAddress: { is: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB" } } + Side: { + AmountInUSD: { gt: "1000" } + Currency: { + MintAddress: { + in: [ + "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" + "So11111111111111111111111111111111111111112" + ] + } + } + } + } + any: [ + { Trade: { PriceInUSD: { lt: 0.995 } } } + { Trade: { PriceInUSD: { gt: 1.005 } } } + ] + Transaction: { Result: { Success: true } } + Block: { Time: { since_relative: { hours_ago: 24 } } } + } + limit: { count: 50 } + orderBy: { descending: Block_Time } ) { + Block { + Time + } Transaction { Signature } Trade { - AmountInUSD + PriceInUSD Amount - Currency { - MintAddress - Name + AmountInUSD + Side { + Currency { + Symbol + } + AmountInUSD } Dex { - ProgramAddress ProtocolName } - Price - PriceInUSD - Side { - Account { - Address - } - AmountInUSD - Amount - Currency { - Name - MintAddress - } + Market { + MarketAddress } } } @@ -315,56 +375,33 @@ subscription { ## Tron -### Stablecoin trades for Tron +### USDT trades on Tron, live -Below stream will give you realtime **USDT** DEX trades on Tron. Test the stream [here](https://ide.bitquery.io/Stablecoin-trades-for-tron). +Most Tron DEX volume is USDT against TRX on SunSwap. Streams on Tron match currencies by symbol; use the contract address, `TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t`, in queries. Saved stream [here](https://ide.bitquery.io/Stablecoin-trades-for-tron). ```graphql subscription { Tron { - DEXTrades( - where: {any: [{Trade: {Buy: {Currency: {SmartContract: {is: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"}}}}}, {Trade: {Sell: {Currency: {SmartContract: {is: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"}}}}}]} - ) { + DEXTradeByTokens(where: { Trade: { Currency: { Symbol: { is: "USDT" } } } }) { Block { Time } Transaction { Hash - Index } Trade { - Index - Dex { - SmartContract - ProtocolFamily - ProtocolName - } - Buy { + Amount + AmountInUSD + PriceInUSD + Side { + Type Amount - Buyer - Seller Currency { - Decimals - Fungible Symbol - SmartContract - Name } - Price - PriceInUSD } - Sell { - Buyer - Seller - Currency { - Decimals - Fungible - Symbol - SmartContract - Name - } - Price - PriceInUSD + Dex { + ProtocolName } } } @@ -372,46 +409,66 @@ subscription { } ``` -### Stablecoin Depeg tracking Stream for Tron +### USDT trades away from the peg on Tron -Below stream tracks **USDT** on Tron when **PriceInUSD** is outside **0.95–1.05** (depeg-style band). Test the query [here](https://ide.bitquery.io/Stablecoin-Depeg-tracking-Stream-for-tron). +The band check for Tron, with the USD floor and no counter-token list, since almost everything on Tron is quoted in TRX. Saved query [here](https://ide.bitquery.io/Stablecoin-Depeg-tracking-Stream-for-tron). ```graphql -subscription { +{ Tron { DEXTradeByTokens( - where: {Trade: {Currency: {SmartContract: {is: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"}}, PriceInUSD: {lt:0.95 gt: 1.05}}} + where: { + Trade: { + Currency: { SmartContract: { is: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t" } } + Side: { AmountInUSD: { gt: "1000" } } + } + any: [ + { Trade: { PriceInUSD: { lt: 0.995 } } } + { Trade: { PriceInUSD: { gt: 1.005 } } } + ] + Block: { Time: { since_relative: { hours_ago: 24 } } } + } + limit: { count: 50 } + orderBy: { descending: Block_Time } ) { + Block { + Time + } Transaction { Hash } Trade { - AmountInUSD - Amount - Buyer - Seller - Currency { - SmartContract - Name - } - Dex { - SmartContract - ProtocolName - } - Price PriceInUSD + Amount + AmountInUSD Side { - Buyer - Seller - AmountInUSD - Amount Currency { - Name - SmartContract + Symbol } + AmountInUSD + } + Dex { + ProtocolName } } } } } ``` + + + +## Related pages + +- [Crypto Trades API](/docs/trading/crypto-trades-api/trades-api) +- [Ethereum DEX trades API](/docs/blockchain/Ethereum/dextrades/dex-api) +- [Solana DEX trades API](/docs/blockchain/Solana/solana-dextrades) +- [Tron DEX trades API](/docs/blockchain/Tron/tron-dextrades) From 43a05a71ba6484eda6f9dc360e710b322bb4d646 Mon Sep 17 00:00:00 2001 From: Gaurav Agarwal Date: Tue, 8 Sep 2026 09:43:29 +0530 Subject: [PATCH 2/2] docs: audit fixes (stablecoin-trades) Co-Authored-By: Claude Fable 5.1 --- docs/stablecoin-APIs/stablecoin-trades-api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/stablecoin-APIs/stablecoin-trades-api.md b/docs/stablecoin-APIs/stablecoin-trades-api.md index 629d86747..8eba9abcc 100644 --- a/docs/stablecoin-APIs/stablecoin-trades-api.md +++ b/docs/stablecoin-APIs/stablecoin-trades-api.md @@ -226,7 +226,7 @@ subscription { ### One wallet's stablecoin flows on Solana -Filter the transaction signer and the stablecoin mints. The example wallet swaps USDC many times an hour; the totals split what it bought from what it sold. Saved query [here](https://ide.bitquery.io/real-time-stablecoin-portfolio_2). +Filter the transaction signer and the stablecoin mints. The example wallet swaps USDC around the clock at the time of writing; the totals split what it bought from what it sold. Saved query [here](https://ide.bitquery.io/real-time-stablecoin-portfolio_2). ```graphql {