UNPKG

kalshi-sdk

Version:

A public TypeScript SDK for Kalshi (https://kalshi.com/)

298 lines (291 loc) 8.76 kB
import crypto, { KeyObject } from 'crypto'; type KalshiMarket = { ticker: string; event_ticker: string; market_type: "binary" | string; title: string; subtitle: string; yes_sub_title: string; no_sub_title: string; open_time: string; close_time: string; expected_expiration_time: string; expiration_time: string; latest_expiration_time: string; settlement_timer_seconds: number; status: "active" | "inactive" | string; response_price_units: "usd_cent" | string; notional_value: number; tick_size: number; yes_bid: number; yes_ask: number; no_bid: number; no_ask: number; last_price: number; previous_yes_bid: number; previous_yes_ask: number; previous_price: number; volume: number; volume_24h: number; liquidity: number; open_interest: number; result: string; can_close_early: boolean; expiration_value: string; category: string; risk_limit_cents: number; strike_type: "less" | "greater" | "custom" | string; cap_strike: number; rules_primary: string; rules_secondary: string; custom_strike?: { [key: string]: string; }; }; type KalshiEventInfo = { event_ticker: string; series_ticker: string; sub_title: string; title: string; mutually_exclusive: boolean; category: string; strike_date: string; }; type KalshiEvent = { markets: KalshiMarket[]; event: KalshiEventInfo; }; type KalshiOrderBook = { orderbook: { no: number[][]; yes: number[][]; }; }; type KalshiOrderRequest = { action: string; client_order_id: string; count: number; side: "yes" | "no"; ticker: string; type: "market" | "limit"; expiration_ts?: number; buy_max_cost?: number; no_price?: number; sell_position_floor?: number; yes_price?: number; }; type KalshiOrderResponse = { order: { action: "buy" | "sell" | "OrderActionUnknown"; client_order_id: string; created_time: string; expiration_time: string; no_price: number; order_id: string; side: "yes" | "no" | "SIDE_UNSET"; status: "resting" | "canceled" | "executed" | "pending"; ticker: string; type: "market" | "limit" | "OrderTypeUnknown"; user_id?: string; yes_price: number; }; }; type KalshiCancelResponse = { order: KalshiOrderResponse["order"]; reduced_by: number; }; type KalshiMarketsRequest = { limit?: number; cursor?: string; event_ticker?: string; series_ticker?: string; max_close_ts?: number; min_close_ts?: number; status?: string; tickers?: string; }; type KalshiEventsRequest = { limit?: number; cursor?: string; status?: "unopened" | "open" | "closed" | "settled"; series_ticker?: string; with_nested_markets?: boolean; }; type KalshiTradesRequest = { cursor?: string; limit?: number; ticker?: string; min_ts?: number; max_ts?: number; }; type KalshiTrade = { count: number; created_time: string; no_price: number; taker_side: "yes" | "no" | "SIDE_UNSET"; ticker: string; trade_id: string; yes_price: number; }; type KalshiSeries = { category: string; contract_url: string; frequency: string; settlement_sources: { name: string; url: string; }[]; tags: string[]; ticker: string; title: string; }; type KalshiCandlestick = { candlesticks: { end_period_ts: number; open_interest: number; price: { close: number; high: number; low: number; open: number; previous: number; }; volume: number; yes_ask: { close: number; high: number; low: number; open: number; previous: number; }; yes_bid: { close: number; high: number; low: number; open: number; previous: number; }; ticker: string; }[]; }; type KalshiCandlestickRequest = { strart_ts: number; end_ts: number; period_interval: number; }; type KalshiExchangeAnnouncement = { delivery_time: string; message: string; status: "info" | "warning" | "error"; type: "info" | "warning" | "error"; }; type KalshiExchangeSchedule = { schedule: { [day: string]: { close_time: string; open_time: string; }[]; }; }; type KalshiExchangeStatus = { exchange_active: boolean; exchange_estimated_resume_time: string; trading_active: boolean; }; type KalshiEventMarket = { event_ticker: string; market_ticker: string; }; type KalshiMultivariateEventCollection = { cursor: string; multivariate_contracts: Array<{ associated_event_tickers: string[]; close_date: Date; collection_ticker: string; description: string; functional_description: string; is_all_yes: boolean; is_ordered: boolean; is_single_market_per_event: boolean; open_date: Date; series_ticker: string; size_max: number; size_min: number; title: string; }>; }; type KalshiLookupPoint = { event_ticker: string; last_queried_ts: string; market_ticker: string; selected_markets: Array<{ event_ticker: string; market_ticker: string; side: string; }>; }; type KalshiSelectedMarket = { event_ticker: string; market_ticker: string; side: string; }; type KalshiMultivariateEventCollectionsRequest = { status: string; associated_event_ticker: string; series_ticker: string; limit: number; cursor: string; }; interface KalshiMarketsClient { getEvents(eventsRequest?: KalshiEventsRequest): Promise<KalshiEvent[]>; getEvent(eventTicker: string, with_nested_markets: boolean): Promise<KalshiEvent>; getMarkets(marketsRequest?: KalshiMarketsRequest): Promise<KalshiMarket[]>; getMarket(marketTicker: string): Promise<KalshiMarket>; getTrades(tradeRequest?: KalshiTradesRequest): Promise<KalshiTrade[]>; getMarketOrderBook(marketTicker: string): Promise<KalshiOrderBook>; getSeries(seriesTicker: string): Promise<KalshiSeries>; getMarketCandlesticks(ticker: string, seriesTicker: string, candleStickRequest: KalshiCandlestickRequest): Promise<KalshiCandlestick[]>; createKalshiOrder(orderRequest: KalshiOrderRequest): Promise<KalshiOrderResponse>; cancelKalshiOrder(orderId: string): Promise<KalshiCancelResponse>; } declare class KalshiMarketsClient { private client; constructor(client: KalshiClient); } interface KalshiExchangeClient { getExchangeAnnouncment(): Promise<KalshiExchangeAnnouncement[]>; getExchangeSchedule(): Promise<KalshiExchangeSchedule>; getExchangeStatus(): Promise<KalshiExchangeStatus>; } declare class KalshiExchangeClient { private client; constructor(client: KalshiClient); } interface KalshiCollectionsClient { getMultivariateEventCollections(params?: KalshiMultivariateEventCollectionsRequest): Promise<KalshiMultivariateEventCollection[]>; getMultivariateEventCollection(collectionTicker: string): Promise<KalshiMultivariateEventCollection>; createMarketInMultivariateEventCollection(collectionTicker: string, selectedMarkets: KalshiSelectedMarket[]): Promise<KalshiEventMarket>; getMultivariateEventCollectionLookupHistory(collectionTicker: string, lookbackSeconds?: number): Promise<KalshiLookupPoint[]>; lookupTickersForMarketInMultivariateEventCollection(collectionTicker: string, selectedMarkets: KalshiSelectedMarket[]): Promise<KalshiEventMarket>; } declare class KalshiCollectionsClient { private client; constructor(client: KalshiClient); } declare class KalshiClient { private privateKey; private kalshiAPIId; markets: KalshiMarketsClient; exchange: KalshiExchangeClient; collections: KalshiCollectionsClient; apiUrl: string; constructor(key: KeyObject, kalshiAPIid: string, apiUrl?: string); static fromFile(filePath: string, kalshiAPIId: string, apiUrl?: string): KalshiClient; static fromKey(key: KeyObject, kalshiAPIId: string, apiUrl?: string): KalshiClient; protected signPssText(privateKey: crypto.KeyObject, text: string): string; protected generateRequestHeaders(path: string, method: "POST" | "GET" | "DELETE" | "PUT"): Record<string, string>; sendWriteRequest<T>(url: string, method: "POST" | "PUT" | "DELETE", body?: any): Promise<T>; sendGetRequest<T>(url: string, params?: any): Promise<T>; private sendWithRetries; } export { KalshiClient };