CRISP partnersSDK methods

createPolymarketMarketData()

Load and stream a selected outcome’s chart and order book.

Framework-neutral public market-data store. Construction is inert; start the lifecycle, subscribe to immutable snapshots and stop on cleanup. Handles public HTTP snapshots, stream deltas, reconnects, history refresh and stale states without CRISP credentials.

live-market-data workflow · All SDK methods

Import and runtime

@crisp-trade/partner-sdk/market-data — browser-safe public Polymarket HTTP and WebSocket data; no CRISP credentials.

Client setup and shared behavior

Arguments

ArgumentPresenceReleased TypeScript type
optionsRequired
PolymarketMarketDataOptions

Named types are expanded under “Exact released types” below. Parameters are in call order; optional does not imply nullable.

Example

Start in your UI lifecycle and call stop on cleanup. Replace the illustrative outcome token ID.

import { createPolymarketMarketData } from '@crisp-trade/partner-sdk/market-data';
const market = createPolymarketMarketData({
  tokenId: '123',
  history: { interval: '1d', fidelity: 5 },
});
const unsubscribe = market.subscribe(() =>
  console.log(market.getSnapshot()),
);
market.start();
// On cleanup:
unsubscribe();
market.stop();

Returns

The exact return type is shown below; this helper does not use the ordinary HTTP response wrapper.

Return type
{
    start(): void;
    stop: () => void;
    refresh(): void;
    getSnapshot: () => PolymarketMarketDataSnapshot;
    subscribe(listener: () => void): () => void;
}

Errors and lifecycle

Loading, stale state and reconnect behavior. Read failures retain the last display; stop the store on cleanup.

This utility does not directly map to one HTTP request.

Exact released types

Extracted from the shipped SDK 0.13.0, not separately maintained signatures.

Full signature
createPolymarketMarketData(options: PolymarketMarketDataOptions): {
    start(): void;
    stop: () => void;
    refresh(): void;
    getSnapshot: () => PolymarketMarketDataSnapshot;
    subscribe(listener: () => void): () => void;
}
PolymarketMarketDataOptions
export interface PolymarketMarketDataOptions {
    /** One outcome token per store. Create a new store when changing outcome. */
    tokenId: string;
    /** Default: last day, sampled every five minutes. false disables chart reads. */
    history?: Omit<PolymarketPriceHistoryQuery, "tokenId"> | false;
    /** Optional backend loaders when direct browser HTTP reads are unavailable. */
    loadBook?: (tokenId: string, signal: AbortSignal) => Promise<MarketDataReadResult<PolymarketOrderBook>>;
    loadHistory?: (query: PolymarketPriceHistoryQuery, signal: AbortSignal) => Promise<MarketDataReadResult<{
        history: MarketDataPoint[];
    }>>;
    fetch?: typeof fetch;
    createSocket?: (endpoint: string) => MarketDataSocket;
    /** Share transport with catalog subscriptions and other outcome stores. */
    stream?: PolymarketMarketStream;
    signal?: AbortSignal;
    timeoutMs?: number;
    /** Refresh canonical history/REST fallback. Default 60s; minimum 1s. */
    refreshIntervalMs?: number;
    /** Maximum retained historical and provisional chart points. Default 2000. */
    maxPoints?: number;
    /** Coalesce subscriber notifications. Default 50ms. */
    notifyIntervalMs?: number;
    /** Initial retry delay, doubles to 30s with jitter. Default 500ms. */
    reconnectDelayMs?: number;
    /** Default 10s, matching upstream heartbeat requirements. */
    heartbeatMs?: number;
}
PolymarketPriceHistoryQuery
export interface PolymarketPriceHistoryQuery {
    /** Outcome token ID, not the Gamma market ID or condition ID. */
    tokenId: string;
    interval?: "max" | "all" | "1m" | "1w" | "1d" | "6h" | "1h";
    /** Unix seconds. Supply both bounds instead of interval. */
    startTs?: number;
    endTs?: number;
    /** Sampling resolution in minutes. */
    fidelity?: number;
}
MarketDataReadResult
type MarketDataReadResult<T> = {
    data: T;
    fetchedAt: string;
    stale: boolean;
};
PolymarketOrderBook
export interface PolymarketOrderBook {
    conditionId: string;
    tokenId: string;
    timestamp: string;
    hash: string | null;
    bids: Array<{
        price: string;
        size: string;
    }>;
    asks: Array<{
        price: string;
        size: string;
    }>;
    minOrderSize: string | null;
    tickSize: string | null;
    negRisk: boolean | null;
    lastTradePrice: string | null;
}
MarketDataPoint
type MarketDataPoint = {
    timestamp: number;
    price: number;
};
MarketDataSocket
type MarketDataSocket = Pick<WebSocket, "addEventListener" | "removeEventListener" | "send" | "close">;
PolymarketMarketDataSnapshot
export interface PolymarketMarketDataSnapshot {
    readonly tokenId: string;
    readonly connection: "idle" | "connecting" | "synchronizing" | "live" | "reconnecting" | "stopped";
    readonly book: {
        readonly data: PolymarketOrderBook | null;
        readonly source: "rest" | "stream" | null;
        readonly stale: boolean;
        readonly updatedAt: string | null;
        readonly error: string | null;
    };
    readonly chart: {
        readonly points: ReadonlyArray<MarketDataPoint & {
            source: "history" | "live_trade";
        }>;
        readonly stale: boolean;
        readonly refreshing: boolean;
        readonly truncated: boolean;
        readonly updatedAt: string | null;
        readonly error: string | null;
    };
    readonly lastTrade: {
        readonly price: string;
        readonly size: string | null;
        readonly timestamp: number;
    } | null;
    readonly streamError: string | null;
    readonly resolved: boolean;
}
CRISP Partner Documentation