markets/src/trades
Mostlyright TypeScript SDK / markets/src/trades
markets/src/trades
Section titled “markets/src/trades”Interfaces
Section titled “Interfaces”KalshiCandleRow
Section titled “KalshiCandleRow”Defined in: packages-ts/markets/src/trades/types.ts:16
Properties
Section titled “Properties”
readonlyclose:null|number
Defined in: packages-ts/markets/src/trades/types.ts:22
readonlyhigh:null|number
Defined in: packages-ts/markets/src/trades/types.ts:20
readonlylow:null|number
Defined in: packages-ts/markets/src/trades/types.ts:21
readonlyopen:null|number
Defined in: packages-ts/markets/src/trades/types.ts:19
openInterest
Section titled “openInterest”
readonlyopenInterest:null|number
Defined in: packages-ts/markets/src/trades/types.ts:24
source
Section titled “source”
readonlysource:"kalshi"
Defined in: packages-ts/markets/src/trades/types.ts:25
readonlyts:null|string
Defined in: packages-ts/markets/src/trades/types.ts:18
Bucket-end timestamp as ISO 8601 UTC string.
volume
Section titled “volume”
readonlyvolume:null|number
Defined in: packages-ts/markets/src/trades/types.ts:23
KalshiCandlesArgs
Section titled “KalshiCandlesArgs”Defined in: packages-ts/markets/src/trades/kalshi.ts:34
Properties
Section titled “Properties”
readonlyfrom:Date
Defined in: packages-ts/markets/src/trades/kalshi.ts:36
interval
Section titled “interval”
readonlyinterval:"1m"|"1h"|"1d"
Defined in: packages-ts/markets/src/trades/kalshi.ts:35
readonlyto:Date
Defined in: packages-ts/markets/src/trades/kalshi.ts:37
KalshiClientOptions
Section titled “KalshiClientOptions”Defined in: packages-ts/markets/src/trades/kalshi-client.ts:19
Properties
Section titled “Properties”fetchFn()?
Section titled “fetchFn()?”
readonlyoptionalfetchFn: (input,init?) =>Promise<Response>(input,init?) =>Promise<Response>
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:25
Override fetch for tests. Defaults to global fetch.
Parameters
Section titled “Parameters”URL | RequestInfo
RequestInit
Returns
Section titled “Returns”Promise<Response>
Parameters
Section titled “Parameters”string | URL | Request
RequestInit
Returns
Section titled “Returns”Promise<Response>
signal?
Section titled “signal?”
readonlyoptionalsignal:AbortSignal
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:23
AbortSignal for the whole call.
sleepBetweenMs?
Section titled “sleepBetweenMs?”
readonlyoptionalsleepBetweenMs:number
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:21
Politeness sleep between requests in ms. Default 100 (0.1 s). 0 to skip.
timeoutMs?
Section titled “timeoutMs?”
readonlyoptionaltimeoutMs:number
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:27
Per-attempt timeout. Default 30 000 ms.
KalshiFillRow
Section titled “KalshiFillRow”Defined in: packages-ts/markets/src/trades/types.ts:28
Properties
Section titled “Properties”
readonlycount:null|number
Defined in: packages-ts/markets/src/trades/types.ts:33
noPrice
Section titled “noPrice”
readonlynoPrice:null|number
Defined in: packages-ts/markets/src/trades/types.ts:32
source
Section titled “source”
readonlysource:"kalshi"
Defined in: packages-ts/markets/src/trades/types.ts:35
takerSide
Section titled “takerSide”
readonlytakerSide:null|"yes"|"no"
Defined in: packages-ts/markets/src/trades/types.ts:34
tradeId
Section titled “tradeId”
readonlytradeId:null|string
Defined in: packages-ts/markets/src/trades/types.ts:29
readonlyts:null|string
Defined in: packages-ts/markets/src/trades/types.ts:30
yesPrice
Section titled “yesPrice”
readonlyyesPrice:null|number
Defined in: packages-ts/markets/src/trades/types.ts:31
KalshiFillsArgs
Section titled “KalshiFillsArgs”Defined in: packages-ts/markets/src/trades/kalshi.ts:40
Properties
Section titled “Properties”maxPages?
Section titled “maxPages?”
readonlyoptionalmaxPages:number
Defined in: packages-ts/markets/src/trades/kalshi.ts:43
since?
Section titled “since?”
readonlyoptionalsince:Date
Defined in: packages-ts/markets/src/trades/kalshi.ts:41
until?
Section titled “until?”
readonlyoptionaluntil:Date
Defined in: packages-ts/markets/src/trades/kalshi.ts:42
KalshiOrderbookArgs
Section titled “KalshiOrderbookArgs”Defined in: packages-ts/markets/src/trades/kalshi.ts:46
Properties
Section titled “Properties”depth?
Section titled “depth?”
readonlyoptionaldepth:number
Defined in: packages-ts/markets/src/trades/kalshi.ts:47
KalshiOrderbookRow
Section titled “KalshiOrderbookRow”Defined in: packages-ts/markets/src/trades/types.ts:38
Properties
Section titled “Properties”
readonlyprice:null|number
Defined in: packages-ts/markets/src/trades/types.ts:40
readonlyside:"yes"|"no"
Defined in: packages-ts/markets/src/trades/types.ts:39
readonlysize:null|number
Defined in: packages-ts/markets/src/trades/types.ts:41
source
Section titled “source”
readonlysource:"kalshi"
Defined in: packages-ts/markets/src/trades/types.ts:42
PolymarketClientOptions
Section titled “PolymarketClientOptions”Defined in: packages-ts/markets/src/trades/polymarket.ts:23
Properties
Section titled “Properties”fetchFn()?
Section titled “fetchFn()?”
readonlyoptionalfetchFn: (input,init?) =>Promise<Response>(input,init?) =>Promise<Response>
Defined in: packages-ts/markets/src/trades/polymarket.ts:29
Override fetch for tests.
Parameters
Section titled “Parameters”URL | RequestInfo
RequestInit
Returns
Section titled “Returns”Promise<Response>
Parameters
Section titled “Parameters”string | URL | Request
RequestInit
Returns
Section titled “Returns”Promise<Response>
signal?
Section titled “signal?”
readonlyoptionalsignal:AbortSignal
Defined in: packages-ts/markets/src/trades/polymarket.ts:27
AbortSignal for the whole call.
sleepBetweenMs?
Section titled “sleepBetweenMs?”
readonlyoptionalsleepBetweenMs:number
Defined in: packages-ts/markets/src/trades/polymarket.ts:25
Politeness sleep between requests in ms. Default 200. 0 to skip.
timeoutMs?
Section titled “timeoutMs?”
readonlyoptionaltimeoutMs:number
Defined in: packages-ts/markets/src/trades/polymarket.ts:31
Per-attempt timeout. Default 30_000 ms.
PolymarketHistoryArgs
Section titled “PolymarketHistoryArgs”Defined in: packages-ts/markets/src/trades/polymarket.ts:34
Properties
Section titled “Properties”fidelityMinutes?
Section titled “fidelityMinutes?”
readonlyoptionalfidelityMinutes:number
Defined in: packages-ts/markets/src/trades/polymarket.ts:38
Bucket size in minutes (default 60).
readonlyfrom:Date
Defined in: packages-ts/markets/src/trades/polymarket.ts:35
readonlyto:Date
Defined in: packages-ts/markets/src/trades/polymarket.ts:36
PolymarketHistoryRow
Section titled “PolymarketHistoryRow”Defined in: packages-ts/markets/src/trades/types.ts:45
Properties
Section titled “Properties”
readonlyprice:null|number
Defined in: packages-ts/markets/src/trades/types.ts:48
Last-traded price in [0, 1] for the requested CLOB token.
source
Section titled “source”
readonlysource:"polymarket.clob"
Defined in: packages-ts/markets/src/trades/types.ts:51
History rows live on the CLOB host (architect iter-1 CRITICAL fix).
readonlyts:null|string
Defined in: packages-ts/markets/src/trades/types.ts:46
volume
Section titled “volume”
readonlyvolume:null|number
Defined in: packages-ts/markets/src/trades/types.ts:49
PolymarketSnapshotRow
Section titled “PolymarketSnapshotRow”Defined in: packages-ts/markets/src/trades/types.ts:54
Properties
Section titled “Properties”lastPrice
Section titled “lastPrice”
readonlylastPrice:null|number
Defined in: packages-ts/markets/src/trades/types.ts:57
liquidity
Section titled “liquidity”
readonlyliquidity:null|number
Defined in: packages-ts/markets/src/trades/types.ts:59
marketId
Section titled “marketId”
readonlymarketId:null|string
Defined in: packages-ts/markets/src/trades/types.ts:55
outcome
Section titled “outcome”
readonlyoutcome:string
Defined in: packages-ts/markets/src/trades/types.ts:56
source
Section titled “source”
readonlysource:"polymarket.gamma"
Defined in: packages-ts/markets/src/trades/types.ts:60
volume
Section titled “volume”
readonlyvolume:null|number
Defined in: packages-ts/markets/src/trades/types.ts:58
RawKalshiCandle
Section titled “RawKalshiCandle”Defined in: packages-ts/markets/src/trades/kalshi-client.ts:114
Properties
Section titled “Properties”end_period_ts?
Section titled “end_period_ts?”
readonlyoptionalend_period_ts:number
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:115
open_interest?
Section titled “open_interest?”
readonlyoptionalopen_interest:string|number
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:133
open_interest_fp?
Section titled “open_interest_fp?”
readonlyoptionalopen_interest_fp:string
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:130
price?
Section titled “price?”
readonlyoptionalprice:object
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:116
close?
Section titled “close?”
readonlyoptionalclose:string|number
close_dollars?
Section titled “close_dollars?”
readonlyoptionalclose_dollars:string
readonlyoptionalhigh:string|number
high_dollars?
Section titled “high_dollars?”
readonlyoptionalhigh_dollars:string
readonlyoptionallow:string|number
low_dollars?
Section titled “low_dollars?”
readonlyoptionallow_dollars:string
readonlyoptionalopen:string|number
open_dollars?
Section titled “open_dollars?”
readonlyoptionalopen_dollars:string
volume?
Section titled “volume?”
readonlyoptionalvolume:string|number
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:132
volume_fp?
Section titled “volume_fp?”
readonlyoptionalvolume_fp:string
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:129
RawKalshiOrderbook
Section titled “RawKalshiOrderbook”Defined in: packages-ts/markets/src/trades/kalshi-client.ts:162
Properties
Section titled “Properties”orderbook?
Section titled “orderbook?”
readonlyoptionalorderbook:object
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:169
readonlyoptionalno: readonlyKalshiOrderLevel[]
readonlyoptionalyes: readonlyKalshiOrderLevel[]
orderbook_fp?
Section titled “orderbook_fp?”
readonlyoptionalorderbook_fp:object
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:164
no_dollars?
Section titled “no_dollars?”
readonlyoptionalno_dollars: readonlyKalshiOrderLevel[]
yes_dollars?
Section titled “yes_dollars?”
readonlyoptionalyes_dollars: readonlyKalshiOrderLevel[]
RawKalshiTrade
Section titled “RawKalshiTrade”Defined in: packages-ts/markets/src/trades/kalshi-client.ts:136
Properties
Section titled “Properties”count?
Section titled “count?”
readonlyoptionalcount:string|number
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:147
count_fp?
Section titled “count_fp?”
readonlyoptionalcount_fp:string
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:142
created_time?
Section titled “created_time?”
readonlyoptionalcreated_time:string|number
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:138
no_price?
Section titled “no_price?”
readonlyoptionalno_price:string|number
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:146
no_price_dollars?
Section titled “no_price_dollars?”
readonlyoptionalno_price_dollars:string
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:141
taker_outcome_side?
Section titled “taker_outcome_side?”
readonlyoptionaltaker_outcome_side:"yes"|"no"
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:143
taker_side?
Section titled “taker_side?”
readonlyoptionaltaker_side:"yes"|"no"
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:148
trade_id?
Section titled “trade_id?”
readonlyoptionaltrade_id:string
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:137
yes_price?
Section titled “yes_price?”
readonlyoptionalyes_price:string|number
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:145
yes_price_dollars?
Section titled “yes_price_dollars?”
readonlyoptionalyes_price_dollars:string
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:140
TradesCacheKey
Section titled “TradesCacheKey”Defined in: packages-ts/markets/src/trades/cache.ts:22
Properties
Section titled “Properties”issuer
Section titled “issuer”
readonlyissuer:string
Defined in: packages-ts/markets/src/trades/cache.ts:23
readonlymonth:number
Defined in: packages-ts/markets/src/trades/cache.ts:26
ticker
Section titled “ticker”
readonlyticker:string
Defined in: packages-ts/markets/src/trades/cache.ts:24
readonlyyear:number
Defined in: packages-ts/markets/src/trades/cache.ts:25
TradesCacheReadOpts
Section titled “TradesCacheReadOpts”Defined in: packages-ts/markets/src/trades/cache.ts:61
Properties
Section titled “Properties”
readonlyoptionalnow:Date
Defined in: packages-ts/markets/src/trades/cache.ts:62
TradesCacheWriteOpts
Section titled “TradesCacheWriteOpts”Defined in: packages-ts/markets/src/trades/cache.ts:65
Properties
Section titled “Properties”
readonlyoptionalnow:Date
Defined in: packages-ts/markets/src/trades/cache.ts:66
TradesResult<Row>
Section titled “TradesResult<Row>”Defined in: packages-ts/markets/src/trades/types.ts:64
Envelope returned by every trades function — rows + metadata.
Type Parameters
Section titled “Type Parameters”• Row
Properties
Section titled “Properties”eventId?
Section titled “eventId?”
readonlyoptionaleventId:string
Defined in: packages-ts/markets/src/trades/types.ts:73
fidelityMinutes?
Section titled “fidelityMinutes?”
readonlyoptionalfidelityMinutes:number
Defined in: packages-ts/markets/src/trades/types.ts:75
interval?
Section titled “interval?”
readonlyoptionalinterval:string
Defined in: packages-ts/markets/src/trades/types.ts:74
marketId?
Section titled “marketId?”
readonlyoptionalmarketId:string
Defined in: packages-ts/markets/src/trades/types.ts:72
retrievedAt
Section titled “retrievedAt”
readonlyretrievedAt:string
Defined in: packages-ts/markets/src/trades/types.ts:67
readonlyrows: readonlyRow[]
Defined in: packages-ts/markets/src/trades/types.ts:65
snapshotAt?
Section titled “snapshotAt?”
readonlyoptionalsnapshotAt:string
Defined in: packages-ts/markets/src/trades/types.ts:69
Snapshot-style results may carry a snapshotAt distinct from retrievedAt.
source
Section titled “source”
readonlysource:TradesSource
Defined in: packages-ts/markets/src/trades/types.ts:66
ticker?
Section titled “ticker?”
readonlyoptionalticker:string
Defined in: packages-ts/markets/src/trades/types.ts:71
Echo of the input ticker / market-id for downstream attribution.
tokenId?
Section titled “tokenId?”
readonlyoptionaltokenId:string
Defined in: packages-ts/markets/src/trades/types.ts:77
CLOB token id for polymarketHistory results (architect iter-1 fix).
Type Aliases
Section titled “Type Aliases”KalshiInterval
Section titled “KalshiInterval”KalshiInterval: typeof
KALSHI_INTERVALS[number]
Defined in: packages-ts/markets/src/trades/types.ts:82
TradesSource
Section titled “TradesSource”TradesSource:
"kalshi"|"polymarket.gamma"|"polymarket.clob"
Defined in: packages-ts/markets/src/trades/types.ts:14
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).
Variables
Section titled “Variables”KALSHI_API_BASE
Section titled “KALSHI_API_BASE”
constKALSHI_API_BASE:"https://api.elections.kalshi.com/trade-api/v2"="https://api.elections.kalshi.com/trade-api/v2"
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:11
KALSHI_INTERVALS
Section titled “KALSHI_INTERVALS”
constKALSHI_INTERVALS: readonly ["1m","1h","1d"]
Defined in: packages-ts/markets/src/trades/types.ts:81
Supported candle intervals — exact union mirrors Python INTERVALS.
Functions
Section titled “Functions”fetchCandlesticks()
Section titled “fetchCandlesticks()”fetchCandlesticks(
ticker,args,opts):Promise<readonlyRawKalshiCandle[]>
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:175
Parameters
Section titled “Parameters”ticker
Section titled “ticker”string
number
periodIntervalMinutes
Section titled “periodIntervalMinutes”number
startTs
Section titled “startTs”number
KalshiClientOptions = {}
Returns
Section titled “Returns”Promise<readonly RawKalshiCandle[]>
fetchOrderbook()
Section titled “fetchOrderbook()”fetchOrderbook(
ticker,args,opts):Promise<RawKalshiOrderbook>
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:246
Parameters
Section titled “Parameters”ticker
Section titled “ticker”string
depth?
Section titled “depth?”number
KalshiClientOptions = {}
Returns
Section titled “Returns”Promise<RawKalshiOrderbook>
fetchTrades()
Section titled “fetchTrades()”fetchTrades(
ticker,args,opts):Promise<readonlyRawKalshiTrade[]>
Defined in: packages-ts/markets/src/trades/kalshi-client.ts:210
Parameters
Section titled “Parameters”ticker
Section titled “ticker”string
FetchTradesArgs = {}
KalshiClientOptions = {}
Returns
Section titled “Returns”Promise<readonly RawKalshiTrade[]>
invalidateTradesCache()
Section titled “invalidateTradesCache()”invalidateTradesCache(
cache,args):Promise<boolean>
Defined in: packages-ts/markets/src/trades/cache.ts:111
Delete cached entry; returns true when a value existed before.
Parameters
Section titled “Parameters”CacheStore
Returns
Section titled “Returns”Promise<boolean>
isCurrentUtcMonth()
Section titled “isCurrentUtcMonth()”isCurrentUtcMonth(
year,month,now):boolean
Defined in: packages-ts/markets/src/trades/cache.ts:51
Parameters
Section titled “Parameters”number
number
Date = ...
Returns
Section titled “Returns”boolean
isFutureUtcMonth()
Section titled “isFutureUtcMonth()”isFutureUtcMonth(
year,month,now):boolean
Defined in: packages-ts/markets/src/trades/cache.ts:55
Parameters
Section titled “Parameters”number
number
Date = ...
Returns
Section titled “Returns”boolean
kalshiCandles()
Section titled “kalshiCandles()”kalshiCandles(
ticker,args,opts):Promise<TradesResult<KalshiCandleRow>>
Defined in: packages-ts/markets/src/trades/kalshi.ts:137
Parameters
Section titled “Parameters”ticker
Section titled “ticker”string
KalshiClientOptions = {}
Returns
Section titled “Returns”Promise<TradesResult<KalshiCandleRow>>
kalshiFills()
Section titled “kalshiFills()”kalshiFills(
ticker,args,opts):Promise<TradesResult<KalshiFillRow>>
Defined in: packages-ts/markets/src/trades/kalshi.ts:190
Parameters
Section titled “Parameters”ticker
Section titled “ticker”string
KalshiFillsArgs = {}
KalshiClientOptions = {}
Returns
Section titled “Returns”Promise<TradesResult<KalshiFillRow>>
kalshiOrderbook()
Section titled “kalshiOrderbook()”kalshiOrderbook(
ticker,args,opts):Promise<TradesResult<KalshiOrderbookRow>>
Defined in: packages-ts/markets/src/trades/kalshi.ts:237
Parameters
Section titled “Parameters”ticker
Section titled “ticker”string
KalshiOrderbookArgs = {}
KalshiClientOptions = {}
Returns
Section titled “Returns”Promise<TradesResult<KalshiOrderbookRow>>
polymarketHistory()
Section titled “polymarketHistory()”polymarketHistory(
tokenId,args,opts):Promise<TradesResult<PolymarketHistoryRow>>
Defined in: packages-ts/markets/src/trades/polymarket.ts:166
Parameters
Section titled “Parameters”tokenId
Section titled “tokenId”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.
Returns
Section titled “Returns”Promise<TradesResult<PolymarketHistoryRow>>
polymarketSnapshot()
Section titled “polymarketSnapshot()”polymarketSnapshot(
eventId,opts):Promise<TradesResult<PolymarketSnapshotRow>>
Defined in: packages-ts/markets/src/trades/polymarket.ts:230
Parameters
Section titled “Parameters”eventId
Section titled “eventId”string
Returns
Section titled “Returns”Promise<TradesResult<PolymarketSnapshotRow>>
readTradesCache()
Section titled “readTradesCache()”readTradesCache<
Row>(cache,args,opts):Promise<null| readonlyRow[]>
Defined in: packages-ts/markets/src/trades/cache.ts:70
Read cached trades rows. Returns null on miss / current-or-future month.
Type Parameters
Section titled “Type Parameters”• Row
Parameters
Section titled “Parameters”CacheStore
TradesCacheReadOpts = {}
Returns
Section titled “Returns”Promise<null | readonly Row[]>
tradesCacheKey()
Section titled “tradesCacheKey()”tradesCacheKey(
args):string
Defined in: packages-ts/markets/src/trades/cache.ts:30
Build the canonical key string for a (issuer, ticker, year, month).
Parameters
Section titled “Parameters”Returns
Section titled “Returns”string
writeTradesCache()
Section titled “writeTradesCache()”writeTradesCache<
Row>(cache,args,rows,opts):Promise<boolean>
Defined in: packages-ts/markets/src/trades/cache.ts:92
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.
Type Parameters
Section titled “Type Parameters”• Row
Parameters
Section titled “Parameters”CacheStore
readonly Row[]
TradesCacheWriteOpts = {}
Returns
Section titled “Returns”Promise<boolean>