Markets API

Access prediction market data, prices, and outcome mints

Markets API

The Markets API provides access to prediction market data including prices, volumes, outcome token mints, and batch queries.

Access

const dflow = new DFlowClient();
const markets = dflow.markets;

Methods

getMarket

Get a single market by ticker.

const market = await dflow.markets.getMarket('BTCD-25DEC0313-T92749.99');
 
console.log(`Title: ${market.title}`);
console.log(`YES Ask: ${market.yesAsk}`);
console.log(`NO Ask: ${market.noAsk}`);
console.log(`Volume: ${market.volume}`);

getMarketByMint

Get a market by outcome token mint address.

const market = await dflow.markets.getMarketByMint('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');

getMarkets

List markets with optional filters.

const response = await dflow.markets.getMarkets({
  status: 'active',
  eventTicker: 'BTCD-25DEC0313',
  isInitialized: true,
  sort: 'volume',
  limit: 50,
});
 
for (const market of response.markets) {
  console.log(`${market.ticker}: YES=${market.yesAsk} NO=${market.noAsk}`);
}

Parameters:

NameTypeRequiredDescription
statusMarketStatusNoFilter by status: 'active', 'closed', 'determined', 'finalized'
isInitializedbooleanNoFilter markets that are initialized
sortSortFieldNoSort field: 'volume', 'volume_24h', 'liquidity', 'open_interest'
tickersstringNoFilter by specific market tickers (comma-separated)
eventTickerstringNoFilter by event ticker
seriesTickerstringNoFilter by series ticker
maxCloseTsnumberNoFilter markets closing before this timestamp
minCloseTsnumberNoFilter markets closing after this timestamp
limitnumberNoMaximum number of markets to return
cursornumberNoPagination cursor (number of markets to skip)

getMarketsBatch

Retrieve multiple markets in a single request.

const markets = await dflow.markets.getMarketsBatch({
  tickers: ['market-1', 'market-2', 'market-3'],
  mints: ['mint-address-1', 'mint-address-2'],
});

Maximum 100 items total (tickers + mints) per batch request.


getOutcomeMints

Get all outcome token mint addresses.

// Get all outcome mints
const allMints = await dflow.markets.getOutcomeMints();
console.log(`Total outcome tokens: ${allMints.length}`);
 
// Get outcome mints for markets closing after a specific date
const futureMints = await dflow.markets.getOutcomeMints({
  minCloseTs: Math.floor(Date.now() / 1000),  // Only markets not yet closed
});

Parameters:

NameTypeRequiredDescription
minCloseTsnumberNoMinimum close timestamp (Unix seconds). Only markets with close_time >= minCloseTs will be included.

filterOutcomeMints

Filter a list of addresses to find which ones are outcome token mints.

const walletTokens = ['addr1', 'addr2', 'addr3'];
const predictionTokens = await dflow.markets.filterOutcomeMints(walletTokens);
 
console.log(`Found ${predictionTokens.length} prediction market tokens`);

Maximum 200 addresses per filter request. Use this to identify prediction market tokens in a wallet.


getMarketCandlesticks

Get OHLCV candlestick data for a market.

const candles = await dflow.markets.getMarketCandlesticks('BTCD-25DEC0313-T92749.99', {
  startTs: 1704067200,    // Jan 1, 2024
  endTs: 1704153600,      // Jan 2, 2024
  periodInterval: 60,     // 1 hour candles
});
 
candles.forEach(c => {
  console.log(`${c.timestamp}: O=${c.open} H=${c.high} L=${c.low} C=${c.close}`);
});

Parameters:

NameTypeRequiredDescription
tickerstringYesThe market ticker
params.startTsnumberYesStart timestamp (Unix seconds)
params.endTsnumberYesEnd timestamp (Unix seconds)
params.periodIntervalnumberYesCandle period in minutes (1, 60, or 1440)

getMarketCandlesticksByMint

Get candlestick data by mint address.

const candles = await dflow.markets.getMarketCandlesticksByMint('EPjFWdd5...', {
  startTs: 1704067200,
  endTs: 1704153600,
  periodInterval: 1440,  // Daily candles
});

Market Object

interface Market {
  ticker: string;
  title: string;
  subtitle: string;
  eventTicker: string;
  status: MarketStatus;
  result: MarketResult;
  marketType: string;
  yesSubTitle: string;
  noSubTitle: string;
  canCloseEarly: boolean;
  rulesPrimary: string;
  volume: number;
  liquidity?: number;
  openInterest: number;
  openTime: number;     // Unix timestamp in seconds
  closeTime: number;    // Unix timestamp in seconds
  expirationTime: number;
  accounts: Record<string, MarketAccount>;
  rulesSecondary?: string | null;
  earlyCloseCondition?: string | null;
  yesAsk?: string | null;
  yesBid?: string | null;
  noAsk?: string | null;
  noBid?: string | null;
}
 
type MarketStatus = 
  | 'initialized'
  | 'active'
  | 'inactive'
  | 'closed'
  | 'determined'
  | 'finalized';
 
type MarketResult = 'yes' | 'no' | '';
 
interface MarketAccount {
  yesMint: string;      // YES outcome token mint
  noMint: string;       // NO outcome token mint
  marketLedger: string;
  redemptionStatus: 'open' | 'closed';
  scalarOutcomePct?: number; // For scalar markets
}

Examples

Find Markets by Event

const response = await dflow.markets.getMarkets({
  eventTicker: 'BTCD-25DEC0313',
  status: 'active',
});
 
for (const market of response.markets) {
  console.log(`${market.title}`);
  console.log(`  Ticker: ${market.ticker}`);
  console.log(`  YES Ask: ${market.yesAsk}`);
  console.log(`  Volume: ${market.volume.toLocaleString()}`);
}

Get Initialized Markets Only

const initialized = await dflow.markets.getMarkets({
  isInitialized: true,
  sort: 'volume',
});
 
console.log(`Found ${initialized.markets.length} initialized markets`);

Get Outcome Token Mints

const market = await dflow.markets.getMarket('BTCD-25DEC0313-T92749.99');
 
// Access the outcome token mints
const accountKey = Object.keys(market.accounts)[0]; // Usually 'usdc'
const account = market.accounts[accountKey];
 
console.log(`YES Mint: ${account.yesMint}`);
console.log(`NO Mint: ${account.noMint}`);

Check Wallet for Prediction Market Tokens

import { getTokenBalances } from 'dflow-sdk';
 
// Get all token balances
const balances = await getTokenBalances(connection, walletPublicKey);
const mints = balances.map(b => b.mint);
 
// Filter to find prediction market tokens
const predictionMints = await dflow.markets.filterOutcomeMints(mints);
 
console.log(`Found ${predictionMints.length} prediction market positions`);