GraphQL API Overview
Sera provides a GraphQL API powered by Goldsky for querying market data, orders, and trading history.
Endpoint
https://api.goldsky.com/api/public/project_cmicv6kkbhyto01u3agb155hg/subgraphs/sera-pro/1.0.9/gn
Try It Now
Copy and paste this command in your terminal to test the API:
curl -s -X POST \
-H "Content-Type: application/json" \
-d '{"query": "{ markets(first: 3) { id quoteToken { symbol } baseToken { symbol } latestPrice } }"}' \
https://api.goldsky.com/api/public/project_cmicv6kkbhyto01u3agb155hg/subgraphs/sera-pro/1.0.9/gn
Making Requests
cURL
curl -X POST \
-H "Content-Type: application/json" \
-d '{"query": "{ markets(first: 5) { id quoteToken { symbol } baseToken { symbol } } }"}' \
https://api.goldsky.com/api/public/project_cmicv6kkbhyto01u3agb155hg/subgraphs/sera-pro/1.0.9/gn
JavaScript
const SUBGRAPH_URL = "https://api.goldsky.com/api/public/project_cmicv6kkbhyto01u3agb155hg/subgraphs/sera-pro/1.0.9/gn";
async function querySubgraph(query, variables = {}) {
const response = await fetch(SUBGRAPH_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query, variables })
});
const { data, errors } = await response.json();
if (errors) throw new Error(errors[0].message);
return data;
}
// Example usage
const data = await querySubgraph(`
query GetMarkets($first: Int!) {
markets(first: $first) {
id
quoteToken { symbol }
baseToken { symbol }
}
}
`, { first: 10 });
Python
import requests
SUBGRAPH_URL = "https://api.goldsky.com/api/public/project_cmicv6kkbhyto01u3agb155hg/subgraphs/sera-pro/1.0.9/gn"
def query_subgraph(query: str, variables: dict = None):
response = requests.post(
SUBGRAPH_URL,
json={"query": query, "variables": variables or {}}
)
result = response.json()
if "errors" in result:
raise Exception(result["errors"][0]["message"])
return result["data"]
# Example usage
data = query_subgraph("""
query GetMarkets($first: Int!) {
markets(first: $first) {
id
quoteToken { symbol }
baseToken { symbol }
}
}
""", {"first": 10})
Available Entities
| Entity | Description |
|---|
| Market | Trading pairs with price parameters |
| OpenOrder | Active and historical orders |
| Depth | Order book depth at each price level |
| ChartLog | OHLCV candlestick data |
| Token | ERC-20 token metadata |
Common Query Patterns
Use first, skip, and orderBy for pagination:
query PaginatedOrders($first: Int!, $skip: Int!) {
openOrders(
first: $first
skip: $skip
orderBy: createdAt
orderDirection: desc
) {
id
nftId
}
}
Filtering
Use where to filter results:
query FilteredOrders($user: String!, $status: String!) {
openOrders(
where: {
user: $user
status: $status
}
) {
id
rawAmount
}
}
Time-based Queries
Filter by timestamp:
query RecentOrders($since: BigInt!) {
openOrders(
where: { createdAt_gte: $since }
orderBy: createdAt
orderDirection: desc
) {
id
createdAt
}
}
Rate Limits
The Goldsky API has the following limits:
| Limit | Value |
|---|
| Max query complexity | 1000 |
| Max results per query | 1000 |
| Query limit | 50 queries every 10s |
For high-frequency data needs, consider subscribing to on-chain events directly via RPC.
Error Handling
async function safeQuery(query, variables, retries = 3) {
for (let i = 0; i < retries; i++) {
try {
return await querySubgraph(query, variables);
} catch (error) {
if (i === retries - 1) throw error;
await new Promise(r => setTimeout(r, 1000 * (i + 1)));
}
}
}
Next Steps