Markets Query
Retrieve information about trading markets including token pairs, fees, and price parameters.Try It Now
Copy
curl -s -X POST \
-H "Content-Type: application/json" \
-d '{"query": "{ markets(first: 5) { id quoteToken { symbol } baseToken { symbol } latestPrice latestPriceIndex } }"}' \
https://api.goldsky.com/api/public/project_cmicv6kkbhyto01u3agb155hg/subgraphs/sera-pro/1.0.9/gn
Schema
Copy
type Market {
id: ID! # Market (OrderBook) address
orderToken: Bytes! # OrderNFT contract address
quoteToken: Token! # Quote token details
baseToken: Token! # Base token details
quoteUnit: BigInt! # Raw amount to quote token conversion
makerFee: BigInt! # Maker fee (negative = rebate)
takerFee: BigInt! # Taker fee
minPrice: BigInt! # Minimum supported price
tickSpace: BigInt! # Price increment per index
latestPriceIndex: BigInt! # Most recent trade price index
latestPrice: BigInt! # Most recent trade price
maxPriceIndex: BigInt! # Maximum price index (65535)
priceUpperBound: BigInt! # Maximum supported price
depths: [Depth!]! # Order book depth data
openOrders: [OpenOrder!]! # All orders in this market
}
Example Queries
List All Markets
Copy
query GetAllMarkets {
markets(first: 100, orderBy: id) {
id
quoteToken {
symbol
decimals
}
baseToken {
symbol
decimals
}
latestPrice
latestPriceIndex
}
}
Get Market by Address
Copy
query GetMarket($id: ID!) {
market(id: $id) {
id
quoteToken {
id
symbol
name
decimals
}
baseToken {
id
symbol
name
decimals
}
quoteUnit
makerFee
takerFee
minPrice
tickSpace
latestPrice
latestPriceIndex
maxPriceIndex
priceUpperBound
}
}
Copy
{
"id": "0xd99802ee8f16d6ff929e27546de15d03fdcce4bd"
}
Get Markets by Token
Copy
query GetMarketsByQuoteToken($quoteTokenId: String!) {
markets(where: { quoteToken: $quoteTokenId }) {
id
baseToken {
symbol
}
latestPrice
}
}
Get Market with Depth
Copy
query GetMarketWithDepth($id: ID!) {
market(id: $id) {
id
quoteToken { symbol decimals }
baseToken { symbol decimals }
minPrice
tickSpace
depths(
first: 100
orderBy: priceIndex
where: { rawAmount_gt: "0" }
) {
priceIndex
price
isBid
rawAmount
baseAmount
}
}
}
Response Example
Copy
{
"data": {
"market": {
"id": "0xd99802ee8f16d6ff929e27546de15d03fdcce4bd",
"quoteToken": {
"id": "0x4fcb0d963cb4dc4e60af0f78a859524087eccda9",
"symbol": "USDC",
"name": "USD Coin",
"decimals": "6"
},
"baseToken": {
"id": "0xd4dd725e3ae95bef81563e0a9e1cfbb19377fe37",
"symbol": "EURC",
"name": "Euro Coin",
"decimals": "6"
},
"quoteUnit": "1000000",
"makerFee": "-50",
"takerFee": "100",
"minPrice": "1000000000000000000000",
"tickSpace": "1000000000000000000",
"latestPrice": "2500000000000000000000",
"latestPriceIndex": "1500",
"maxPriceIndex": "65535",
"priceUpperBound": "66535000000000000000000"
}
}
}
Understanding Market Parameters
Price Calculation
UseminPrice and tickSpace to calculate actual prices:
Copy
function indexToPrice(market, priceIndex) {
const minPrice = BigInt(market.minPrice);
const tickSpace = BigInt(market.tickSpace);
return minPrice + tickSpace * BigInt(priceIndex);
}
function priceToIndex(market, price) {
const minPrice = BigInt(market.minPrice);
const tickSpace = BigInt(market.tickSpace);
return Number((BigInt(price) - minPrice) / tickSpace);
}
Fee Interpretation
Fees are in basis points × 100:Copy
function interpretFee(feeValue) {
const bps = Number(feeValue) / 100;
const percentage = bps / 100;
return {
basisPoints: bps,
percentage: percentage,
isRebate: feeValue < 0
};
}
// Example: makerFee = -50
// basisPoints: -0.5, percentage: -0.005, isRebate: true
Quote Unit
Convert between raw amounts and token amounts:Copy
function rawToQuote(rawAmount, quoteUnit) {
return BigInt(rawAmount) * BigInt(quoteUnit);
}
function quoteToRaw(quoteAmount, quoteUnit) {
return BigInt(quoteAmount) / BigInt(quoteUnit);
}
Filtering Markets
By Activity
Copy
query ActiveMarkets {
markets(
where: { latestPriceIndex_gt: "0" }
orderBy: latestPriceIndex
orderDirection: desc
) {
id
baseToken { symbol }
quoteToken { symbol }
latestPrice
}
}
By Token Symbol
Copy
query USDCMarkets {
markets(
where: { quoteToken_: { symbol: "USDC" } }
) {
id
baseToken { symbol }
latestPrice
}
}
