Skip to main content
During development, you can use the developer endpoints without an API key. For production use, you’ll need an API key to avoid rate limits.
Track market status to know when trading is allowed and when redemption is available. Use the Metadata API to query status and filter by state.

Market Lifecycle Diagram

Use this lifecycle to decide when to trade and when to redeem. A market can move forward through the sequence and can temporarily pause in inactive.
1

Understand Market Statuses

Monitor a fixed lifecycle: initialized → active → inactive → closed → determined → finalized.Trade only when status is active. Redeem only when status is determined or finalized, and redemption is funded.
Markets can move from inactive back to active, or from inactive to closed.
2

Get a Market and Read Status

Fetch a market by mint and read the status and redemptionStatus fields.
const METADATA_API_BASE_URL = "https://dev-prediction-markets-api.dflow.net";
const outcomeMint = "OUTCOME_TOKEN_MINT_ADDRESS";

const market = await fetch(
  `${METADATA_API_BASE_URL}/api/v1/market/by-mint/${outcomeMint}`
).then((x) => x.json());

console.log({
  status: market.status,
  redemptionStatus: market.accounts?.[market.settlementMint]?.redemptionStatus,
});
3

Filter Markets by Status

Filter markets to show only tradable or redeemable markets.
const METADATA_API_BASE_URL = "https://dev-prediction-markets-api.dflow.net";

const response = await fetch(
  `${METADATA_API_BASE_URL}/api/v1/markets?status=active&limit=200`
).then((x) => x.json());

console.log(response.markets?.length ?? 0);
const METADATA_API_BASE_URL = "https://dev-prediction-markets-api.dflow.net";

const response = await fetch(
  `${METADATA_API_BASE_URL}/api/v1/markets?status=determined&limit=200`
).then((x) => x.json());

console.log(response.markets?.length ?? 0);
4

Gate Trading and Redemption

You gate trades to active markets and gate redemption to determined or finalized markets with redemptionStatus = "open".
if (market.status === "active") {
  // Allow trades
} else {
  // Show market status to the user
}
const settlementAccount = market.accounts?.[market.settlementMint];

if (
  (market.status === "determined" || market.status === "finalized") &&
  settlementAccount?.redemptionStatus === "open"
) {
  // Allow redemption
}

API Routes

Cookbook Repository

This recipe, along with many more, is available in the DFlow Cookbook Repo. You can clone it and start coding immediately.