Skip to content

@mostlyrightmd/markets

Custom error type for contract-id parsing / validation failures.

Mirrors the Python ValueError/TypeError distinction: in TS we use a named subclass so callers can instanceof-check rather than parse error messages.

  • ContractError

new ContractIdError(message): ContractIdError

string

ContractIdError

ContractError.constructor


Raised on a malformed ticker / unknown city, or on absent/unsupported settlement metadata. A ContractError subclass: an invalid local call, not a transport failure — raised before any I/O.

  • ContractError

new KalshiTickerError(message): KalshiTickerError

string

KalshiTickerError

ContractError.constructor

The Kalshi GetMarket object shape (snake_case wire form) — the settlement metadata the caller supplies. Fetch it via fetchMarket(ticker) (./trades) and pass it to settleKalshiOutcome.

readonly optional cap_strike: null | string | number

readonly optional floor_strike: null | string | number

readonly optional result: string

readonly optional strike_type: string


citation: string

station: string


readonly cityTicker: string

readonly contractDate: string

readonly settlementSource: "cli.archive"

readonly settlementStation: string


readonly cityTicker: string

readonly contractDate: string

readonly settlementSource: "cli.archive"

readonly settlementStation: string


readonly optional capStrike: number

readonly city: string

The 3-letter catalog city key (e.g. NYC) — alias-resolved.

readonly optional floorStrike: number

Numeric settlement bounds from the market payload, else undefined.

readonly measure: KalshiMeasure

"high" (KXHIGH*) or "low" (KXLOW*).

readonly series: string

The full series token (e.g. KXHIGHNY).

readonly station: string

The resolved settlement station ICAO (e.g. KNYC).

readonly strikeToken: string

The raw strike token, captured verbatim (T86, B81.5, …) — opaque, never classified.

readonly optional strikeType: KalshiStrikeType

The Kalshi strike_type enum — populated only from a supplied market payload, never inferred from the token.


[measure: string]: undefined | string

default: string

optional high: string

optional low: string

KalshiMeasure: "high" | "low"


KalshiSettlement: NHighResolution | NLowResolution


KalshiStrikeType: "greater" | "greater_or_equal" | "less" | "less_or_equal" | "between"

The Kalshi strike_type values the settle path maps. functional/custom/ structured are out of scope for weather markets and are refused.

const KALSHI_SETTLEMENT_STATIONS: Readonly<Record<string, KalshiStation>>


const KNOWN_WRONG_STATIONS: ReadonlySet<string>


const POLYMARKET_CITY_STATIONS: Readonly<Record<string, PolymarketCityStation>>


const version: "4.1.0" = "4.1.0"

Public package version; kept in lockstep with package.json.

kalshiNhighResolve(ticker, settlementDate): NHighResolution

Resolve a Kalshi NHIGH contract to its settlement source + station.

The contract id format is KHIGH<CITY> (case-insensitive), where <CITY> is a city ticker present in KALSHI_SETTLEMENT_STATIONS.

string

Kalshi market identifier. Case-insensitive.

Calendar date the market settles for. Either a UTC date-only Date (H/M/S/ms == 0) or a YYYY-MM-DD string.

string | Date

NHighResolution

A frozen NHighResolution.

The contract id doesn’t follow KHIGH<CITY>, the city is unknown, or the settlement date is invalid.


kalshiNlowResolve(ticker, settlementDate): NLowResolution

Resolve a Kalshi NLOW contract to its settlement source + station.

The contract id format is KLOW<CITY> (case-insensitive), where <CITY> is a city ticker present in KALSHI_SETTLEMENT_STATIONS.

string

Kalshi market identifier. Case-insensitive.

Calendar date the market settles for. Either a UTC date-only Date (H/M/S/ms == 0) or a YYYY-MM-DD string.

string | Date

NLowResolution

A frozen NLowResolution.

The contract id doesn’t follow KLOW<CITY>, the city is unknown, or the settlement date is invalid.


kalshiSettlementFor(ticker, date): KalshiSettlement

Resolve a Kalshi NHIGH or NLOW contract id to its settlement metadata.

KHIGH* prefixes dispatch to the NHIGH resolver; KLOW* prefixes dispatch to NLOW. Anything else raises ContractIdError.

string

string

KalshiSettlement

kalshiSettlementFor("KHIGHNYC", "2025-01-06")
// → { settlementSource: "cli.archive", settlementStation: "KNYC",
// cityTicker: "NYC", contractDate: "2025-01-06" }

parseTicker(ticker): ParsedKalshiTicker

Parse a full Kalshi market ticker into series/measure/city + the resolved settlement station, capturing the strike token verbatim. The parse is station-only: it never classifies the strike shape or infers a direction, so a B<midpoint> between ticker (KXHIGHNY-26JUL24-B81.5) parses without crashing. Settlement semantics come from the market payload (settleKalshiOutcome(parsed, observed, market)), never this token.

string

ParsedKalshiTicker

malformed anatomy, non-HIGH/LOW series, unknown city, or an empty strike token.


settleKalshiOutcome(parsed, observed, market): null | 0 | 1

Settle an observed value against the market’s strike_type metadata.

Dispatch is on the Kalshi GetMarket strike_type enum, never on the ticker suffix. Strict open-ends: greater -> value > floor_strike; less -> value < cap_strike; between -> floor_strike <= value <= cap_strike.

ParsedKalshiTicker

The parsed ticker (station/measure identity).

The observed settlement value (°F). nullnull outcome (NaN label → NA outcome, row preserved — mirrors Python).

null | number

The Kalshi GetMarket object, supplied by the caller.

undefined | null | KalshiMarketMetadata

null | 0 | 1

market metadata absent or strike_type unsupported.