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 / lo > hi. A ContractError subclass (DX-H5): a bad ticker is an invalid local call, not a transport failure — it is raised before any I/O.

  • ContractError

new KalshiTickerError(message): KalshiTickerError

string

KalshiTickerError

ContractError.constructor

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 city: string

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

readonly kind: KalshiStrikeKind

"threshold" (-T<n>) or "range" (-B<lo>-<hi>).

readonly optional lowerStrike: number

Range bounds (present when kind === "range").

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 optional strike: number

Threshold strike (present when kind === "threshold").

readonly optional upperStrike: number


[measure: string]: undefined | string

default: string

optional high: string

optional low: string

KalshiMeasure: "high" | "low"


KalshiSettlement: NHighResolution | NLowResolution


KalshiStrikeKind: "threshold" | "range"

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


const KNOWN_WRONG_STATIONS: ReadonlySet<string>


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


const version: "1.9.9" = "1.9.9"

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/strike + resolve the settlement station via the parity-critical whitelist (with the NY→NYC alias on a raw-suffix miss).

string

ParsedKalshiTicker

malformed ticker, unknown city, or lo > hi.


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

Settle an observed value against a parsed Kalshi ticker’s strike.

INCLUSIVE comparison (documented, see file header + -SUMMARY.md) threshold: value >= strike; range: lo <= value <= hi.

ParsedKalshiTicker

null | number

null | 0 | 1

1 (YES), 0 (NO), or null when observed is null (NaN label → NA outcome, row preserved — mirrors Python).