This guide covers common query patterns, optimization techniques, and best practices for retrieving data from the Panda Protocol subgraph.
Basic Queries
Pool Data
# Get basic pool information
{
pandaPool(id: "0x123...") {
id
price
volumeUSD
swapsCount
graduated
}
}
# List active pools with high volume
{
pandaPools(
where: {
volumeUSD_gt: "100000",
graduated: false
}
orderBy: volumeUSD
orderDirection: desc
first: 10
) {
id
price
volumeUSD
}
}
Trading Activity
# Recent swaps for a pool
{
pandaPoolSwaps(
where: { pool: "0x123..." }
orderBy: timestamp
orderDirection: desc
first: 100
) {
timestamp
amountPandaIn
amountPandaOut
volumeUSD
averagePrice
}
}
Advanced Queries
Time-Based Queries
# Get pools with recent activity
{
pandaPools(
where: {
lastSwapTimestamp_gt: "1634567890"
}
) {
id
price
lastSwapTimestamp
}
}
# Get hourly price data
{
priceSnapshots(
where: {
pool: "0x123...",
timeframe: HOUR,
timestamp_gt: "1634567890"
}
orderBy: timestamp
orderDirection: asc
) {
timestamp
open
high
low
close
}
}
Market Analysis
# Top pools by volume
{
pandaPools(
orderBy: volumeUSD
orderDirection: desc
first: 5
) {
id
volumeUSD
marketCapUSD
swapsCount
}
}
# Token holder distribution
{
token(id: "0x123...") {
symbol
holdersCount
holders(
orderBy: balance
orderDirection: desc
first: 10
) {
address
balance
sharePercentage
}
}
}
Query Optimization
Pagination
# Using skip/first for pagination
{
pandaPoolSwaps(
skip: 100 # Skip first 100 results
first: 50 # Get next 50 results
orderBy: timestamp
orderDirection: desc
) {
id
timestamp
}
}