Skip to content

@mostlyrightmd/markets/trades

readonly close: null | number

readonly end_time_utc: null | string

Bucket-end timestamp as ISO 8601 UTC string.

readonly high: null | number

readonly low: null | number

readonly open: null | number

readonly open_interest: null | number

readonly source: "kalshi"

readonly ticker: string

The query identity — a leading column (DX-H4 / CUT-06), consistent with settlement rows.

readonly volume: null | number


readonly fromTime: Date

readonly interval: "1m" | "1h" | "1d"

readonly toTime: Date


readonly optional fetchFn: (input, init?) => Promise<Response>(input, init?) => Promise<Response>

Override fetch for tests. Defaults to global fetch.

MDN Reference

URL | RequestInfo

RequestInit

Promise<Response>

MDN Reference

string | URL | Request

RequestInit

Promise<Response>

readonly optional signal: AbortSignal

AbortSignal for the whole call.

readonly optional sleepBetweenMs: number

Politeness sleep between requests in ms. Default 100 (0.1 s). 0 to skip.

readonly optional timeoutMs: number

Per-attempt timeout. Default 30 000 ms.


readonly count: null | number

readonly no_price: null | number

readonly source: "kalshi"

readonly taker_side: null | "yes" | "no"

readonly trade_id: null | string

readonly ts: null | string

readonly yes_price: null | number


readonly optional maxPages: number

readonly optional since: Date

readonly optional until: Date


readonly optional depth: number


readonly price: null | number

readonly side: "yes" | "no"

readonly size: null | number

readonly source: "kalshi"


readonly optional fetchFn: (input, init?) => Promise<Response>(input, init?) => Promise<Response>

Override fetch for tests.

MDN Reference

URL | RequestInfo

RequestInit

Promise<Response>

MDN Reference

string | URL | Request

RequestInit

Promise<Response>

readonly optional signal: AbortSignal

AbortSignal for the whole call.

readonly optional sleepBetweenMs: number

Politeness sleep between requests in ms. Default 200. 0 to skip.

readonly optional timeoutMs: number

Per-attempt timeout. Default 30_000 ms.


readonly optional fidelityMinutes: number

Bucket size in minutes (default 60).

readonly from: Date

readonly to: Date


readonly price: null | number

Last-traded price in [0, 1] for the requested CLOB token.

readonly source: "polymarket.clob"

History rows live on the CLOB host (architect iter-1 CRITICAL fix).

readonly ts: null | string

readonly volume: null | number


readonly last_price: null | number

readonly liquidity: null | number

readonly market_id: null | string

readonly outcome: string

readonly source: "polymarket.gamma"

readonly volume: null | number


readonly optional end_period_ts: number

readonly optional open_interest: string | number

readonly optional open_interest_fp: string

readonly optional price: object

readonly optional close: string | number

readonly optional close_dollars: string

readonly optional high: string | number

readonly optional high_dollars: string

readonly optional low: string | number

readonly optional low_dollars: string

readonly optional open: string | number

readonly optional open_dollars: string

readonly optional volume: string | number

readonly optional volume_fp: string


readonly optional orderbook: object

readonly optional no: readonly KalshiOrderLevel[]

readonly optional yes: readonly KalshiOrderLevel[]

readonly optional orderbook_fp: object

readonly optional no_dollars: readonly KalshiOrderLevel[]

readonly optional yes_dollars: readonly KalshiOrderLevel[]


readonly optional count: string | number

readonly optional count_fp: string

readonly optional created_time: string | number

readonly optional no_price: string | number

readonly optional no_price_dollars: string

readonly optional taker_outcome_side: "yes" | "no"

readonly optional taker_side: "yes" | "no"

readonly optional trade_id: string

readonly optional yes_price: string | number

readonly optional yes_price_dollars: string


readonly issuer: string

readonly month: number

readonly ticker: string

readonly year: number


readonly optional now: Date


readonly optional now: Date

KalshiInterval: typeof KALSHI_INTERVALS[number]


TradesSource: "kalshi" | "polymarket.gamma" | "polymarket.clob"

Source string carried per row — load-bearing invariant for cross-frame joins.

polymarket.gamma covers /events + /events/{id} (snapshot endpoint); polymarket.clob covers /prices-history (history endpoint, on the CLOB host — distinct from Gamma per architect iter-1 CRITICAL).

const KALSHI_API_BASE: "https://api.elections.kalshi.com/trade-api/v2" = "https://api.elections.kalshi.com/trade-api/v2"


const KALSHI_INTERVALS: readonly ["1m", "1h", "1d"]

Supported candle intervals — exact union mirrors Python INTERVALS.

fetchCandlesticks(ticker, args, opts): Promise<readonly RawKalshiCandle[]>

string

number

number

number

KalshiClientOptions = {}

Promise<readonly RawKalshiCandle[]>


fetchOrderbook(ticker, args, opts): Promise<RawKalshiOrderbook>

string

number

KalshiClientOptions = {}

Promise<RawKalshiOrderbook>


fetchTrades(ticker, args, opts): Promise<readonly RawKalshiTrade[]>

string

FetchTradesArgs = {}

KalshiClientOptions = {}

Promise<readonly RawKalshiTrade[]>


invalidateTradesCache(cache, args): Promise<boolean>

Delete cached entry; returns true when a value existed before.

CacheStore

TradesCacheKey

Promise<boolean>


isCurrentUtcMonth(year, month, now): boolean

number

number

Date = ...

boolean


isFutureUtcMonth(year, month, now): boolean

number

number

Date = ...

boolean


kalshiCandles(ticker, args, opts): Promise<DataResult<KalshiCandleRow>>

string

KalshiCandlesArgs

KalshiClientOptions = {}

Promise<DataResult<KalshiCandleRow>>


kalshiFills(ticker, args, opts): Promise<DataResult<KalshiFillRow>>

string

KalshiFillsArgs = {}

KalshiClientOptions = {}

Promise<DataResult<KalshiFillRow>>


kalshiOrderbook(ticker, args, opts): Promise<DataResult<KalshiOrderbookRow>>

string

KalshiOrderbookArgs = {}

KalshiClientOptions = {}

Promise<DataResult<KalshiOrderbookRow>>


polymarketHistory(tokenId, args, opts): Promise<DataResult<PolymarketHistoryRow>>

string

CLOB token id (ERC-1155 asset id, one per outcome — YES or NO). NOT a Gamma market/condition/event id. Architect iter-1 CRITICAL fix.

PolymarketHistoryArgs

PolymarketClientOptions = {}

Promise<DataResult<PolymarketHistoryRow>>


polymarketSnapshot(eventId, opts): Promise<DataResult<PolymarketSnapshotRow>>

string

PolymarketClientOptions = {}

Promise<DataResult<PolymarketSnapshotRow>>


readTradesCache<Row>(cache, args, opts): Promise<null | readonly Row[]>

Read cached trades rows. Returns null on miss / current-or-future month.

Row

CacheStore

TradesCacheKey

TradesCacheReadOpts = {}

Promise<null | readonly Row[]>


tradesCacheKey(args): string

Build the canonical key string for a (issuer, ticker, year, month).

TradesCacheKey

string


writeTradesCache<Row>(cache, args, rows, opts): Promise<boolean>

Write rows to the cache. Returns false (no-op) when:

  • the (year, month) is the current UTC month (still mutable),
  • the (year, month) is in the future, OR
  • rows is empty.

Row

CacheStore

TradesCacheKey

readonly Row[]

TradesCacheWriteOpts = {}

Promise<boolean>