Orders Query¶
Retrieve order information including open orders, filled orders, and order history.
Try It Now¶
curl -s -X POST \
-H "Content-Type: application/json" \
-d '{"query": "{ openOrders(first: 5, where: { market: \"0xd99802ee8f16d6ff929e27546de15d03fdcce4bd\" }, orderBy: createdAt, orderDirection: desc) { id nftId priceIndex price isBid rawAmount status user createdAt } }"}' \
https://api.goldsky.com/api/public/project_cmicv6kkbhyto01u3agb155hg/subgraphs/sera-pro/1.0.9/gn
curl -s -X POST \
-H "Content-Type: application/json" \
-d '{"query": "{ openOrders(first: 10, where: { user: \"0xda6e605db8c3221f4b3706c1da9c4e28195045f5\" }) { id market { id } priceIndex isBid rawAmount status } }"}' \
https://api.goldsky.com/api/public/project_cmicv6kkbhyto01u3agb155hg/subgraphs/sera-pro/1.0.9/gn
import requests
SUBGRAPH_URL = "https://api.goldsky.com/api/public/project_cmicv6kkbhyto01u3agb155hg/subgraphs/sera-pro/1.0.9/gn"
MARKET_ID = "0xd99802ee8f16d6ff929e27546de15d03fdcce4bd"
response = requests.post(SUBGRAPH_URL, json={
"query": """
query GetOrders($market: String!) {
openOrders(
first: 5
where: { market: $market }
orderBy: createdAt
orderDirection: desc
) {
id
priceIndex
isBid
rawAmount
status
user
}
}
""",
"variables": {"market": MARKET_ID}
})
print(response.json())
Schema¶
type OpenOrder {
id: ID! # Unique order identifier
nftId: BigInt! # Order NFT token ID (for cancellation)
market: Market! # Market this order belongs to
user: Bytes! # Order owner address
priceIndex: BigInt! # Price level index
price: BigInt! # Actual price
orderIndex: BigInt! # Position in the queue at this price
isBid: Bool! # true = buy order, false = sell order
rawAmount: BigInt! # Original order amount (raw units)
rawOpenAmount: BigInt! # Remaining unfilled amount
rawFilledAmount: BigInt! # Amount that has been filled
claimableAmount: BigInt! # Amount ready to claim
status: String! # Order status
createdAt: BigInt! # Unix timestamp
updatedAt: BigInt! # Last update timestamp
}
Order Statuses¶
| Status | Description |
|---|---|
open | Order is on the book, waiting to be filled |
partial | Order is partially filled |
filled | Order has been completely filled |
cancelled | Order was cancelled by the owner |
claimed | Proceeds have been claimed |
Example Queries¶
Get Orders by User¶
query GetUserOrders($user: String!) {
openOrders(
where: { user: $user }
orderBy: createdAt
orderDirection: desc
first: 100
) {
id
nftId
market { id }
priceIndex
price
isBid
rawAmount
rawOpenAmount
rawFilledAmount
claimableAmount
status
createdAt
}
}
Get Open Orders Only¶
query GetOpenOrders($user: String!) {
openOrders(
where: { user: $user, status: "open" }
orderBy: createdAt
orderDirection: desc
) {
id
nftId
market { id baseToken { symbol } quoteToken { symbol } }
priceIndex
price
isBid
rawOpenAmount
}
}
Get Orders with Claimable Proceeds¶
query GetClaimableOrders($user: String!) {
openOrders(
where: { user: $user, claimableAmount_gt: "0" }
) {
id
nftId
market { id }
priceIndex
orderIndex
isBid
claimableAmount
status
}
}
Get Orders by Market¶
query GetMarketOrders($market: String!) {
openOrders(
where: { market: $market, status: "open" }
orderBy: priceIndex
orderDirection: desc
first: 100
) {
priceIndex
price
isBid
rawOpenAmount
user
}
}
Response Example¶
{
"data": {
"openOrders": [
{
"id": "0xd99802ee8f16d6ff929e27546de15d03fdcce4bd-1-19500-42",
"nftId": "12345",
"market": { "id": "0xd99802ee8f16d6ff929e27546de15d03fdcce4bd" },
"priceIndex": "19500",
"price": "1950000000000000000000",
"orderIndex": "42",
"isBid": true,
"rawAmount": "1000",
"rawOpenAmount": "500",
"rawFilledAmount": "500",
"claimableAmount": "495000000",
"status": "partial",
"createdAt": "1704067200"
}
]
}
}
Filtering Orders¶
By Status¶
query OrdersByStatus($user: String!, $status: String!) {
openOrders(where: { user: $user, status: $status }) {
id
nftId
status
}
}
By Time Range¶
query RecentOrders($since: BigInt!) {
openOrders(
where: { createdAt_gte: $since }
orderBy: createdAt
orderDirection: desc
) {
id
user
market { id }
createdAt
}
}