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.
Use the onchain trades endpoints to power activity feeds, trade analytics, and wallet-level history views.

Use Cases

  • Display global “recent fills” across all markets.
  • Display market-specific fills next to orderbook and price data.
  • Display wallet trade history scoped to a market or event.
  • Trigger alerts for large trades using minAmount filters.
1

Set Base URL and Query Helper

Define the metadata API base URL and reusable query/output helpers.
const METADATA_API_BASE_URL = "https://dev-prediction-markets-api.dflow.net";

type QueryValue = string | number | undefined | null;
type OnchainTrade = Record<string, any>;

function toQueryString(params: Record<string, QueryValue>): string {
  const searchParams = new URLSearchParams();

  Object.entries(params).forEach(([key, value]) => {
    if (value !== undefined && value !== null && value !== "") {
      searchParams.set(key, String(value));
    }
  });

  const query = searchParams.toString();
  return query ? `?${query}` : "";
}

function printTrades(trades: OnchainTrade[]) {
  trades.forEach((trade) => {
    console.log({
      id: trade.id,
      createdAt: trade.createdAt,
      marketTicker: trade.marketTicker,
      side: trade.side,
      inputAmount: trade.inputAmount,
      outputAmount: trade.outputAmount,
      wallet: trade.wallet,
      transactionSignature: trade.transactionSignature,
    });
  });
}
2

Get Onchain Trades by Wallet

Scope fills to a single wallet using /api/v1/onchain-trades with the wallet query parameter.
const wallet = "XJfdwGBgXMa1cXdiU4fqceoBLkgtTCr6S863k8xmh9A";

const response = await fetch(
  `${METADATA_API_BASE_URL}/api/v1/onchain-trades?wallet=${wallet}&limit=100&sortBy=createdAt&sortOrder=desc`
);

if (!response.ok) {
  throw new Error("Failed to fetch wallet onchain trades");
}

const data = await response.json();
const trades = data.trades ?? [];
const nextCursor = data.cursor ?? null;

printTrades(trades);

console.log({
  wallet,
  tradeCount: trades.length,
  nextCursor,
});
3

Get Onchain Trades Across All Markets

Scope fills across all markets using /api/v1/onchain-trades.
const query = toQueryString({
  limit: 100,
  cursor: undefined,
  mint: undefined, // optional
  ticker: undefined, // optional
  sortBy: "createdAt",
  sortOrder: "desc",
  minAmount: undefined,
  maxAmount: undefined,
});

const response = await fetch(
  `${METADATA_API_BASE_URL}/api/v1/onchain-trades${query}`
);

if (!response.ok) {
  throw new Error("Failed to fetch onchain trades");
}

const data = await response.json();
const trades = data.trades ?? [];
const nextCursor = data.cursor ?? null;

printTrades(trades);
console.log({ tradeCount: trades.length, nextCursor });
4

Get Onchain Trades by Event

Scope fills to all markets inside a single event using /api/v1/onchain-trades/by-event/{event_ticker}.
const eventTicker = "KXBTCY-27JAN0100";

const query = toQueryString({
  limit: 100,
  sortBy: "createdAt",
  sortOrder: "desc",
  minAmount: undefined,
  maxAmount: undefined,
});

const response = await fetch(
  `${METADATA_API_BASE_URL}/api/v1/onchain-trades/by-event/${eventTicker}${query}`
);

if (!response.ok) {
  throw new Error("Failed to fetch onchain trades by event");
}

const data = await response.json();
const trades = data.trades ?? [];
const nextCursor = data.cursor ?? null;

printTrades(trades);
console.log({
  eventTicker,
  tradeCount: trades.length,
  nextCursor,
});
5

Get Onchain Trades by Market

Scope fills to a single market using /api/v1/onchain-trades/by-market/{market_ticker}.
const marketTicker = "KXBTCY-27JAN0100-B82500";

const query = toQueryString({
  limit: 100,
  sortBy: "createdAt",
  sortOrder: "desc",
  minAmount: undefined,
  maxAmount: undefined,
});

const response = await fetch(
  `${METADATA_API_BASE_URL}/api/v1/onchain-trades/by-market/${marketTicker}${query}`
);

if (!response.ok) {
  throw new Error("Failed to fetch onchain trades by market");
}

const data = await response.json();
const trades = data.trades ?? [];
const nextCursor = data.cursor ?? null;

printTrades(trades);
console.log({
  marketTicker,
  tradeCount: trades.length,
  nextCursor,
});
6

Paginate with Cursor

Scope historical pagination by passing each response cursor into the next /api/v1/onchain-trades request.
async function fetchAllOnchainTrades(limitPerPage = 250) {
  let cursor: string | null = null;
  const allTrades: OnchainTrade[] = [];

  do {
    const query = toQueryString({
      limit: limitPerPage,
      cursor,
      sortBy: "createdAt",
      sortOrder: "desc",
    });

    const response = await fetch(
      `${METADATA_API_BASE_URL}/api/v1/onchain-trades${query}`
    );
    if (!response.ok) throw new Error("Failed to paginate onchain trades");

    const page = await response.json();
    allTrades.push(...(page.trades ?? []));
    cursor = page.cursor ?? null;
  } while (cursor);

  printTrades(allTrades);
  return allTrades;
}

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.