Skip to main content
This page explains how to parse prediction market trades onchain using the Prediction Markets program IDL. The program account is: pReDicTmksnPfkfiz33ndSdbe2dY43KYPg4U2dbvHvb. Use this approach when you need:
  • Real-time fill detection: detect order fills with minimal latency by watching onchain events directly instead of polling the REST API.
  • Onchain analytics: compute volume, fees, and fill rates from raw program events.
If you only need user-facing trade history, use the Trades API.

Event Format

Events are emitted via the EmitEvent instruction. The discriminator is 0xF0, zero-padded to 8 bytes: 0xf000000000000000. The first byte after the discriminator (byte 8) is the EventType, which tells you what kind of event was emitted:
ValueEventTypeDescription
0x01MarketMarket-level event
0x02UserOrderUser order lifecycle event
0x03UserRedeemUser redemption event
The remaining bytes after EventType are the event-specific data.
Decode the UserOrderEvent and UserRedeemEvent to determine order related info. Do not rely on raw instruction data, instruction formats can change without notice, but the event schema is stable.

Order Lifecycle

When a user places an order, the program emits a UserOrderEvent (EventType = 0x02). The next byte (byte 9) is the userOrderEventType field, which tracks the order lifecycle:
ValueTypeDescription
0x01OpenOrder placed and pending fill
0x02FillOrder (partially or fully) filled
0x03CancelOrder cancelled (e.g., FOK/IOC not filled)
0x04RevertOrder reverted (e.g., slippage exceeded)
The first event for a new order is always Open. Subsequent events (Fill, Cancel, or Revert) are emitted in later block slots. When a user redeems an outcome token, the program emits a UserRedeemEvent (EventType = 0x03) instead.

Byte Layout Summary

Byte(s)FieldDescription
0–7Instruction discriminator0xf000000000000000
8EventType0x01=Market, 0x02=UserOrder, 0x03=UserRedeem
9userOrderEventTypeUserOrderEvent only: 0x01=Open, 0x02=Fill, 0x03=Cancel, 0x04=Revert
10+Event fieldsRemaining event-specific data

Detecting Order Fills

To detect whether a specific order has been filled, follow this flow:
  1. Parse the Open event from the transaction the user signed and submitted. Extract the userOrder field, which is the onchain address of the order.
  2. Watch for subsequent transactions that reference the same userOrder address and emit a UserOrderEvent with userOrderEventType = 0x02 (Fill).
  3. Handle terminal states: if you see userOrderEventType = 0x03 (Cancel) or 0x04 (Revert), the order did not fill.
As long as you output to the user’s wallet (rather than using the destinationWallet parameter), the fill transaction will appear in the user’s transaction history. You can subscribe to a transaction stream for the user’s address and parse each transaction to detect fills in near real-time.

Matching Opens to Fills

Use the userOrder field in UserOrderEvent to link related events.
  • The Open event and its Fill event(s) share the same userOrder value.
  • A single Open can have multiple Fill events (partial fills).

Volume Calculation

In UserOrderEvent, use:
  • inputMint / inputAmount
  • outputMint / outputAmount
One of the mints will be a settlement mint (USDC or CASH), so you can sum the corresponding amounts across Fill events to compute volume.

Fee Calculation

UserOrderEvent includes:
  • feeMint
  • feeAmount
Fees are paid in the settlement mint, so summing feeAmount across Fill events gives total fees.

Relevant IDL Fields

From the IDL: UserOrderEvent
FieldDescription
userOrderEventTypeLifecycle stage (0x01=Open, 0x02=Fill, 0x03=Cancel, 0x04=Revert)
userOrderOnchain address of the order (links Open to Fill events)
inputMintMint of the token the user sent
inputAmountAmount of input token
outputMintMint of the token the user received
outputAmountAmount of output token
feeMintMint used for fees (settlement mint)
feeAmountFee amount in the fee mint
FillInstructionParams
FieldDescription
consumedInputAmountInput consumed in this fill
producedOutputAmountOutput produced in this fill
platformFeeAmountPlatform fee taken in this fill