How to Get All Data for a Specific Polymarket Market - Complete Guide
Learn how to query all Polymarket market data including prices, trades, metadata, and token holders. This step-by-step guide shows you how to get complete market information using condition ID, question ID, or market ID.
Overview
To get all data for a specific Polymarket market, you'll need to query multiple contracts and events. The data is distributed across:
- Main Polymarket Contract: Market creation, position splits, resolution
- CTF Exchange Contract: Trading activity, token registrations
- UMA Adapter Contract: Market metadata (ancillaryData)
Starting Points
You can start with any of these identifiers:
- Condition ID: Found in
ConditionPreparationandTokenRegisteredevents - Question ID: Found in
ConditionPreparationevents - Market ID: Found in decoded
ancillaryDatafromQuestionInitializedevents
Complete Workflow
Step 1: Get Market Metadata (Question Information)
If you have a Question ID, start here to get the market metadata:
{
EVM(dataset: combined, network: matic) {
Events(
orderBy: {descending: Block_Time}
where: {
Block: {
Time: {
since_relative: {hours_ago: 36}
}
},
Arguments: {
includes: {
Name: {is: "questionID"},
Value: {Bytes: {is: "QUESTION_ID_HERE"}}
}
},
Log: {Signature: {Name: {in: ["QuestionInitialized"]}}},
LogHeader: {Address: {is: "0x65070BE91477460D8A7AeEb94ef92fe056C2f2A7"}}
}
limit: {count: 1}
) {
Block {
Time
Number
Hash
}
Transaction {
Hash
From
To
}
TransactionStatus {
Success
}
Arguments {
Name
Value {
... on EVM_ABI_Integer_Value_Arg {
integer
}
... on EVM_ABI_Address_Value_Arg {
address
}
... on EVM_ABI_String_Value_Arg {
string
}
... on EVM_ABI_BigInt_Value_Arg {
bigInteger
}
... on EVM_ABI_Bytes_Value_Arg {
hex
}
... on EVM_ABI_Boolean_Value_Arg {
bool
}
}
}
}
}
}
What you get:
questionID: The question identifierancillaryData: Hex-encoded market metadata (needs decoding)creator: Market creator addressrequestTimestamp: When the question was createdrewardandproposalBond: Oracle reward parameters
Decode ancillaryData to get:
title: Market question titledescription: Market resolution conditionsmarket_id: Polymarket numeric market IDres_data: Payout mapping (p1, p2, p3)p1,p2,p3: Outcome labelsinitializer: Market creator address
See the CTF Exchange documentation for decoding instructions.
Step 2: Get Condition Information
If you have a Condition ID, get the condition details:
{
EVM(dataset: combined, network: matic) {
Events(
orderBy: {descending: Block_Time}
where: {
Block: {Time: {since_relative: {hours_ago: 36}}},
Arguments: {
includes: {
Name: {is: "conditionId"},
Value: {Bytes: {in: ["CONDITION_ID_HERE"]}}
}
},
Log: {Signature: {Name: {in: ["ConditionPreparation"]}}},
LogHeader: {Address: {is: "0x4d97dcd97ec945f40cf65f87097ace5ea0476045"}}
}
limit: {count: 1}
) {
Block {
Time
Number
Hash
}
Transaction {
Hash
From
To
}
Arguments {
Name
Value {
... on EVM_ABI_Integer_Value_Arg {
integer
}
... on EVM_ABI_Address_Value_Arg {
address
}
... on EVM_ABI_String_Value_Arg {
string
}
... on EVM_ABI_BigInt_Value_Arg {
bigInteger
}
... on EVM_ABI_Bytes_Value_Arg {
hex
}
... on EVM_ABI_Boolean_Value_Arg {
bool
}
}
}
}
}
}
What you get:
conditionId: The condition identifierquestionId: Links to UMA question (use this for Step 1)oracle: Oracle address for resolutionoutcomeSlotCount: Number of possible outcomes
Step 3: Get Trading Pairs (Token0 and Token1)
Get the trading pair information from TokenRegistered events:
{
EVM(dataset: combined, network: matic) {
Events(
orderBy: {descending: Block_Time}
where: {
Block: {Time: {since_relative: {days_ago: 6}}},
Arguments: {
includes: {
Name: {is: "conditionId"},
Value: {Bytes: {is: "CONDITION_ID_HERE"}}
}
},
Log: {Signature: {Name: {in: ["TokenRegistered"]}}},
LogHeader: {
Address: {
in: [
"0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E",
"0xC5d563A36AE78145C45a50134d48A1215220f80a"
]
}
}
}
limit: {count: 10}
) {
Block {
Time
Number
Hash
}
Transaction {
Hash
From
To
}
Arguments {
Name
Value {
... on EVM_ABI_Integer_Value_Arg {
integer
}
... on EVM_ABI_Address_Value_Arg {
address
}
... on EVM_ABI_String_Value_Arg {
string
}
... on EVM_ABI_BigInt_Value_Arg {
bigInteger
}
... on EVM_ABI_Bytes_Value_Arg {
hex
}
... on EVM_ABI_Boolean_Value_Arg {
bool
}
}
}
}
}
}
What you get:
conditionId: Links to the market conditiontoken0: First token in the trading pair (usually YES outcome token)token1: Second token in the trading pair (usually NO outcome token or USDC)
Note: These token addresses are the asset IDs used in trading events. If token0 or token1 is 0x0000000000000000000000000000000000000000, it represents USDC collateral.
Step 4: Get Trading Activity (OrderFilled Events)
Get all trades for this market using the token addresses from Step 3:
{
EVM(dataset: realtime, network: matic) {
Events(
orderBy: {descending: Block_Time}
where: {
Block: {Time: {since_relative: {days_ago: 6}}},
Arguments: {
includes: {
Value: {
Bytes: {
in: ["TOKEN0_ADDRESS", "TOKEN1_ADDRESS"]
}
}
}
},
Log: {Signature: {Name: {in: ["OrderFilled"]}}},
LogHeader: {
Address: {
in: [
"0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E",
"0xC5d563A36AE78145C45a50134d48A1215220f80a"
]
}
}
}
limit: {count: 1000}
) {
Block {
Time
Number
Hash
}
Transaction {
Hash
From
To
}
Arguments {
Name
Value {
... on EVM_ABI_Integer_Value_Arg {
integer
}
... on EVM_ABI_Address_Value_Arg {
address
}
... on EVM_ABI_String_Value_Arg {
string
}
... on EVM_ABI_BigInt_Value_Arg {
bigInteger
}
... on EVM_ABI_Bytes_Value_Arg {
hex
}
... on EVM_ABI_Boolean_Value_Arg {
bool
}
}
}
}
}
}
What you get:
orderHash: Unique order identifiermaker: Address that created the ordertaker: Address that filled the ordermakerAssetId: Asset ID being sold by makertakerAssetId: Asset ID being bought by takermakerAmountFilled: Amount of maker asset filledtakerAmountFilled: Amount of taker asset filledfee: Trading fee
Calculate Prices:
- If
takerAssetIdis USDC (0x0) andmakerAssetIdis YES token: Price (YES) = takerAmountFilled / makerAmountFilled - If
makerAssetIdis USDC (0x0) andtakerAssetIdis YES token: Price (YES) = makerAmountFilled / takerAmountFilled - Price (NO) = 1 - Price(YES)
Step 5: Get Order Matched Events
Get order matching information:
{
EVM(dataset: realtime, network: matic) {
Events(
orderBy: {descending: Block_Time}
where: {
Arguments: {
includes: {
Value: {
Bytes: {
in: ["TOKEN0_ADDRESS", "TOKEN1_ADDRESS"]
}
}
}
},
Log: {Signature: {Name: {in: ["OrdersMatched"]}}},
LogHeader: {
Address: {
in: [
"0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E",
"0xC5d563A36AE78145C45a50134d48A1215220f80a"
]
}
}
}
limit: {count: 1000}
) {
Block {
Time
Number
Hash
}
Transaction {
Hash
From
To
}
Arguments {
Name
Value {
... on EVM_ABI_Integer_Value_Arg {
integer
}
... on EVM_ABI_Address_Value_Arg {
address
}
... on EVM_ABI_String_Value_Arg {
string
}
... on EVM_ABI_BigInt_Value_Arg {
bigInteger
}
... on EVM_ABI_Bytes_Value_Arg {
hex
}
... on EVM_ABI_Boolean_Value_Arg {
bool
}
}
}
}
}
}
Step 6: Get Liquidity Data (PositionSplit Events)
Get information about liquidity provision (when users split positions):
{
EVM(dataset: realtime, network: matic) {
Events(
orderBy: {descending: Block_Time}
where: {
Arguments: {
includes: {
Name: {is: "conditionId"},
Value: {Bytes: {is: "CONDITION_ID_HERE"}}
}
},
Log: {Signature: {Name: {in: ["PositionSplit"]}}},
LogHeader: {Address: {is: "0x4d97dcd97ec945f40cf65f87097ace5ea0476045"}}
}
limit: {count: 1000}
) {
Block {
Time
Number
Hash
}
Transaction {
Hash
From
To
}
Arguments {
Name
Value {
... on EVM_ABI_Integer_Value_Arg {
integer
}
... on EVM_ABI_Address_Value_Arg {
address
}
... on EVM_ABI_String_Value_Arg {
string
}
... on EVM_ABI_BigInt_Value_Arg {
bigInteger
}
... on EVM_ABI_Bytes_Value_Arg {
hex
}
... on EVM_ABI_Boolean_Value_Arg {
bool
}
}
}
}
}
}
What you get:
stakeholder: Address that split the positioncollateralToken: Collateral token address (usually USDC)parentCollectionId: Parent collection identifierconditionId: Market condition identifierpartition: Array defining outcome distributionamount: Amount of collateral split
Step 7: Get Market Resolution Status
Check if the market has been resolved:
{
EVM(dataset: realtime, network: matic) {
Events(
orderBy: {descending: Block_Time}
where: {
Arguments: {
includes: {
Name: {is: "conditionId"},
Value: {Bytes: {is: "CONDITION_ID_HERE"}}
}
},
Log: {Signature: {Name: {in: ["ConditionResolution"]}}},
LogHeader: {Address: {is: "0x4d97dcd97ec945f40cf65f87097ace5ea0476045"}}
}
limit: {count: 1}
) {
Block {
Time
Number
Hash
}
Transaction {
Hash
From
To
}
Arguments {
Name
Value {
... on EVM_ABI_Integer_Value_Arg {
integer
}
... on EVM_ABI_Address_Value_Arg {
address
}
... on EVM_ABI_String_Value_Arg {
string
}
... on EVM_ABI_BigInt_Value_Arg {
bigInteger
}
... on EVM_ABI_Bytes_Value_Arg {
hex
}
... on EVM_ABI_Boolean_Value_Arg {
bool
}
}
}
}
}
}
What you get:
conditionId: Market condition identifieroracle: Oracle address that resolved the marketquestionId: Question identifieroutcomeSlotCount: Number of outcomespayoutNumerators: Array defining payout ratios for each outcome
Resolution Status:
- If this query returns results, the market is resolved
- If no results, the market is open or pending resolution
Step 8: Get Payout Redemptions
If the market is resolved, get information about payouts:
{
EVM(dataset: realtime, network: matic) {
Events(
orderBy: {descending: Block_Time}
where: {
Arguments: {
includes: {
Name: {is: "conditionId"},
Value: {Bytes: {is: "CONDITION_ID_HERE"}}
}
},
Log: {Signature: {Name: {in: ["PayoutRedemption"]}}},
LogHeader: {Address: {is: "0x4d97dcd97ec945f40cf65f87097ace5ea0476045"}}
}
limit: {count: 1000}
) {
Block {
Time
Number
Hash
}
Transaction {
Hash
From
To
}
Arguments {
Name
Value {
... on EVM_ABI_Integer_Value_Arg {
integer
}
... on EVM_ABI_Address_Value_Arg {
address
}
... on EVM_ABI_String_Value_Arg {
string
}
... on EVM_ABI_BigInt_Value_Arg {
bigInteger
}
... on EVM_ABI_Bytes_Value_Arg {
hex
}
... on EVM_ABI_Boolean_Value_Arg {
bool
}
}
}
}
}
}
What you get:
redeemer: Address that redeemed payoutscollateralToken: Collateral token addressparentCollectionId: Collection identifierconditionId: Market condition identifierindexSets: Array of outcome index sets redeemedpayout: Amount of collateral redeemed
Complete Example: Starting from Market ID
If you only have a Market ID (numeric ID from Polymarket UI), follow this workflow:
1. Find Question ID from Market ID
Query QuestionInitialized events and decode ancillaryData to find the market with matching market_id:
{
EVM(dataset: combined, network: matic) {
Events(
orderBy: {descending: Block_Time}
where: {
Block: {Time: {since_relative: {days_ago: 30}}},
Log: {Signature: {Name: {in: ["QuestionInitialized"]}}},
LogHeader: {Address: {is: "0x65070BE91477460D8A7AeEb94ef92fe056C2f2A7"}}
}
limit: {count: 10000}
) {
Arguments {
Name
Value {
... on EVM_ABI_Bytes_Value_Arg {
hex
}
}
}
}
}
}
Decode all ancillaryData fields and search for the one containing market_id: YOUR_MARKET_ID.
2. Get Condition ID from Question ID
Once you have the question ID, query ConditionPreparation events:
{
EVM(dataset: combined, network: matic) {
Events(
orderBy: {descending: Block_Time}
where: {
Arguments: {
includes: {
Name: {is: "questionId"},
Value: {Bytes: {is: "QUESTION_ID_FROM_STEP_1"}}
}
},
Log: {Signature: {Name: {in: ["ConditionPreparation"]}}},
LogHeader: {Address: {is: "0x4d97dcd97ec945f40cf65f87097ace5ea0476045"}}
}
limit: {count: 1}
) {
Arguments {
Name
Value {
... on EVM_ABI_Bytes_Value_Arg {
hex
}
}
}
}
}
}
Extract the conditionId from the results.
3. Continue with Steps 3-8 Above
Use the conditionId to get all remaining market data following Steps 3-8.
Data Relationships
Understanding how the data connects:
QuestionInitialized (UMA Adapter)
↓ questionID
ConditionPreparation (Main Contract)
↓ conditionId
TokenRegistered (CTF Exchange)
↓ token0, token1
OrderFilled (CTF Exchange)
↓ trading activity
PositionSplit (Main Contract)
↓ liquidity data
ConditionResolution (Main Contract)
↓ resolution status
PayoutRedemption (Main Contract)
↓ payout data
Summary: Complete Market Data Checklist
For a complete market view, collect:
- Market Metadata: Title, description, outcomes (from decoded
ancillaryData) - Condition Info: Condition ID, question ID, oracle address
- Trading Pairs: Token0, Token1 addresses
- Trading Activity: All
OrderFilledevents with prices - Order Matching:
OrdersMatchedevents - Liquidity:
PositionSplitevents showing liquidity provision - Resolution Status:
ConditionResolutionevent (if resolved) - Payouts:
PayoutRedemptionevents (if resolved)
Best Practices
- Cache condition IDs: Once you have a condition ID, use it for all subsequent queries
- Decode ancillaryData: Always decode and parse
ancillaryDatato get human-readable market information - Handle both exchanges: Query both legacy (
0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E) and current (0xC5d563A36AE78145C45a50134d48A1215220f80a) exchange contracts - Calculate prices correctly: Use
OrderFilledevents to calculate current market prices - Check resolution status: Always check
ConditionResolutionto determine if market is open or resolved - Use appropriate time ranges: Adjust
since_relativeparameters based on market age