Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,70 @@

All notable changes to kalshi-sdk will be documented in this file.

## 22.15.0 — 2026-11-19

Adds on-request flight disruption markets (#586) against OpenAPI v3.37.0
and reconciles weather-window, perps schedule, and perps candlestick/WS
drift. Additive only. No breaking changes.

### Added

- **`markets.create_flight_disruption_market(...)`** (sync and async) —
`POST /flight_disruption_markets`, 200 `CreateFlightDisruptionMarketResponse`.
Authenticated. Returns the flight disruption market for a flight, cover
and optional delay, creating it if it does not exist. `created` is false
when a market for the same request already existed. Required: `carrier`,
`flight_number`, `departure_airport`, `arrival_airport`, `scheduled_date`
(YYYY-MM-DD), `cover` (`FlightCoverLiteral`: `"cancelled"` / `"delayed"` /
`"either"`). Optional: `delay_basis` (`FlightDelayBasisLiteral`:
`"departure"` / `"arrival"`), `delay_minutes`. Accepts
`request=CreateFlightDisruptionMarketRequest(...)` or keyword fields.
POST is never retried.
- **`markets.flight_disruption_availability()`** (sync and async) —
`GET /flight_disruption_markets/availability`, 200
`GetFlightDisruptionAvailabilityResponse`. Public. These three endpoints
are marked `x-excluded` in the spec; they may not be launched yet.
- **`markets.list_flights(*, carrier, flight_number, date)`** (sync and
async) — `GET /flight_disruption_markets/flights`, 200 `GetFlightsResponse`.
Authenticated. Looks up a flight number on a departure date. (Closes #586).
- Optional **`end_date`** (`str | None`) on
`CreateWeatherPointMarketRequest` and both sync and async
`create_weather_point_market` overloads. Omitted when unset; existing
callers are unchanged. The spec marks this field optional.
- Perps **`MarginMarketScheduleDetails.kalshi_trading_schedule`** optional
`MarginTradingCronSchedule` (`timezone` is `"America/New_York"`;
`open_crons` / `close_crons` lists).
- Perps WS optional **`subaccount_type`** on `MarginOrderbookDeltaPayload`,
`MarginFillPayload`, and `MarginUserOrderPayload`, typed with REST
`SubaccountTypeLiteral` (also accepts `"auto_rebalance"`).

### Changed

- **`GetWeatherPointAvailabilityResponse.max_window_days`** /
**`max_window_hours`** are optional (`int | None`). Spec 3.37.0 marks
both required; the SDK keeps them optional so payloads that omit the
keys still parse (`server_omits_despite_required`).
- Perps **`MarginMarketCandlestick.ask`** is now
`MarginAskDistributionHistorical`: required keys, JSON-nullable
`open` / `low` / `high` / `close` (`DollarDecimal | None`,
`AliasChoices(foo_dollars, foo)`), so candlesticks from periods with no
asks parse instead of failing validation. Bid OHLC stays non-null
`BidAskDistributionHistorical`. Strict-mypy code doing arithmetic on ask
values may need a `None` check.

### Docs

- Weather point: coordinates rounded to three decimals; `end_date` can
cross midnight (at most 24 hours) when `max_window_days == 2`.
- Concert `enabled` lists concerts; it does not promise that create will
succeed.
- Perps market schedules include recurring trading hours, not only
holiday closures.
- Perps `managed_isolated` uses the same subaccount number as the
market's isolated subaccount.
- AsyncAPI orderbook snapshot `market_id` may now be `""` (already accepted
as `str`). Snapshot parsing is unchanged and still requires both book sides.

## 22.14.0 — 2026-11-13

Adds on-request concert cancellation markets (#582) against OpenAPI v3.36.0
Expand Down
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ tests/

## API Reference

- OpenAPI spec: https://docs.kalshi.com/openapi.yaml (v3.36.0, 142 operations; 141 mapped in the core SDK — `POST /portfolio/intra_exchange_instance_transfer` is implemented on `PerpsClient.transfers.transfer_instance` and left unimplemented on the core client)
- OpenAPI spec: https://docs.kalshi.com/openapi.yaml (v3.37.0, 145 operations; 144 mapped in the core SDK — `POST /portfolio/intra_exchange_instance_transfer` is implemented on `PerpsClient.transfers.transfer_instance` and left unimplemented on the core client)
- AsyncAPI spec: https://docs.kalshi.com/asyncapi.yaml (16 WebSocket channels; 13 typed `subscribe_*` + escape-hatch)
- Base URL: https://api.elections.kalshi.com/trade-api/v2
- Demo URL: https://demo-api.kalshi.co/trade-api/v2
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A professional, spec-first Python SDK for the [Kalshi](https://kalshi.com) predi
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![Type checked: mypy strict](https://img.shields.io/badge/mypy-strict-blue.svg)](https://mypy.readthedocs.io/)

- **Full coverage** of the Kalshi REST API (141 mapped of 142 operations across 19 resources, OpenAPI v3.36.0) and WebSocket API (13 typed `subscribe_*` channels + escape-hatch).
- **Full coverage** of the Kalshi REST API (144 mapped of 145 operations across 19 resources, OpenAPI v3.37.0) and WebSocket API (13 typed `subscribe_*` channels + escape-hatch).
- **Perps (margin) API**: standalone `PerpsClient` / `AsyncPerpsClient` + `PerpsWebSocket` for the perpetual-futures exchange (54 REST operations, 6 WS channels), plus a `KlearClient` for the Self-Clearing-Member "Klear" settlement API (26 of 27 operations). See [Perps (margin) trading](#perps-margin-trading).
- **FIX protocol**: an async-first FIX engine (FIXT.1.1 / FIX50SP2) for both products — order-entry, drop-copy, market-data, post-trade (prediction), and RFQ (prediction) sessions (plus order-group management over the order-entry session) with typed message models, sequence recovery, and order-book / settlement reassembly. `from kalshi import FixClient` / `MarginFixClient`. See [FIX protocol](#fix-protocol-low-latency-trading).
- **V2 event-market orders**: `create_v2` / `amend_v2` / `decrease_v2` / `cancel_v2` / `cancel_all_v2` plus batched variants on `/portfolio/events/orders/*` — the only order-write surface.
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
A professional, spec-first Python SDK for the [Kalshi](https://kalshi.com) prediction
markets API.

- **Full REST coverage** — 141 mapped of 142 operations across 19 resources
(OpenAPI v3.36.0), every kwarg drift-tested against the spec.
- **Full REST coverage** — 144 mapped of 145 operations across 19 resources
(OpenAPI v3.37.0), every kwarg drift-tested against the spec.
- **V2 event-market orders** — new `create_v2` / `amend_v2` / `decrease_v2` /
`cancel_v2` / `cancel_all_v2` family on `/portfolio/events/orders/*`. Legacy `/portfolio/orders`
keeps working; deprecation no earlier than May 6, 2026.
Expand Down
20 changes: 12 additions & 8 deletions docs/perps.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,15 @@ for ticker, details in schedules.items():
print(ticker, len(details.kalshi_trading_holidays))
```

`markets.schedules(*, tickers)` returns Kalshi trading-holiday closures
(`GET /margin/markets/schedules`) as a ticker → `MarginMarketScheduleDetails`
map. `tickers` is required (1–100, each 1–200 characters) and serializes as a
comma-separated query string. Regular daily and weekend closures are not
included. Each holiday window's spec field `from` is `start` on
`MarginHolidayWindow` (`until` is the exclusive end).
`markets.schedules(*, tickers)` returns recurring Kalshi trading hours and
holiday closures (`GET /margin/markets/schedules`) as a ticker →
`MarginMarketScheduleDetails` map. `tickers` is required (1–100, each 1–200
characters) and serializes as a comma-separated query string. Optional
`kalshi_trading_schedule` is a `MarginTradingCronSchedule` (`timezone` is
`America/New_York`; `open_crons` / `close_crons` are five-field cron lists).
Empty cron arrays mean continuous trading except for
`kalshi_trading_holidays`. Each holiday window's spec field `from` is
`start` on `MarginHolidayWindow` (`until` is the exclusive end).

The margin order side is `bid` / `ask` (not the prediction API's `yes` / `no`).
Orders create/cancel/decrease/amend are POSTs/DELETEs and are **never retried**.
Expand Down Expand Up @@ -231,8 +234,9 @@ perps.portfolio.cancel_cross_exit_trigger("BTC-PERP", trig.id)
(`"cross"` / `"isolated"` / `"auto_rebalance"` / `"managed_isolated"`, or
`None` when the key is absent) is optional on `MarginPosition`,
`MarginSubaccountBalance`, `MarginRiskPosition`, and
`MarginFundingHistoryEntry`. The spec marks it required; the SDK keeps it
optional so older payloads still parse.
`MarginFundingHistoryEntry`. `managed_isolated` uses the same subaccount
number as the market's isolated subaccount. The spec marks it required; the
SDK keeps it optional so older payloads still parse.
- **Portfolio hedging** (since the v3.23.0 spec sync) — `MarginPosition` and
`MarginRiskPosition` carry a **required** `is_portfolio` (`bool`), `True` when
the position is hedged within a portfolio so its margin is computed at the
Expand Down
56 changes: 51 additions & 5 deletions docs/resources/markets.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ recent trades.
| `concert_cancellation_availability(...)` | `GET /concert_cancellation_markets/availability` | no |
| `list_concerts(*, metro_id, ...)` | `GET /concert_cancellation_markets/concerts` | **yes** |
| `search_concerts(*, q)` | `GET /concert_cancellation_markets/concerts/search` | **yes** |
| `create_flight_disruption_market(...)` | `POST /flight_disruption_markets` | **yes** |
| `flight_disruption_availability()` | `GET /flight_disruption_markets/availability` | no |
| `list_flights(*, carrier, flight_number, date)` | `GET /flight_disruption_markets/flights` | **yes** |

!!! warning "Orderbook endpoints require auth"
`orderbook()` and `bulk_orderbooks()` raise `AuthRequiredError` on an
Expand Down Expand Up @@ -155,7 +158,7 @@ Creation is authenticated; availability is public. POST is never retried.

```python
avail = client.markets.weather_point_availability()
print(avail.enabled, [d.name for d in avail.domains])
print(avail.enabled, [d.name for d in avail.domains], avail.max_window_days)

resp = client.markets.create_weather_point_market(
latitude=40.785,
Expand All @@ -167,6 +170,7 @@ resp = client.markets.create_weather_point_market(
end_hour=24,
timezone="America/New_York",
floor_value=2,
end_date="2026-11-12", # optional; omit for a same-day window
)
print(resp.market_ticker, resp.created, resp.latitude, resp.longitude)
```
Expand All @@ -175,7 +179,10 @@ print(resp.market_ticker, resp.created, resp.latitude, resp.longitude)
`cap_value` for `"less"` and `"between"`. The SDK does not enforce that —
unset optional fields are omitted from the wire body. The same request
always returns the same market; `created` is false when it already existed.
The response coordinates are the snapped NOAA MRMS grid-cell center.
Coordinates are rounded to three decimal places; requests that agree to
three decimals share a market. Optional `end_date` (the day after `date`)
opens a window that crosses midnight, at most 24 hours, where availability
returns `max_window_days == 2`.

## Concert cancellation markets

Expand All @@ -201,12 +208,51 @@ print(resp.market_ticker, resp.created, resp.cover)
```

Take `jambase_event_id` and `scheduled_date` from `list_concerts` or
`search_concerts`. A cover missing from `avail.covers` cannot be created. The
same request always returns the same market; `created` is false when it already
existed. Pass the returned `market_ticker` to `POST /communications/rfqs`.
`search_concerts`. A cover missing from `avail.covers` cannot be created.
`enabled` means concerts are listed; it does not promise that a create will
succeed — where listing is on before markets are offered, create returns 409.
The same request always returns the same market; `created` is false when it
already existed. Pass the returned `market_ticker` to `POST /communications/rfqs`.
`list_concerts` is paged by the server (`page` / `total_pages`); there is no
SDK paginator.

## Flight disruption markets

On-request markets on whether a flight is canceled or delayed. Creation and
flight lookup are authenticated; availability is public. POST is never
retried. These endpoints are marked `x-excluded` in the spec; they may not
be launched yet.

```python
avail = client.markets.flight_disruption_availability()
print(avail.enabled, avail.covers, avail.delay_bases, avail.delay_step_minutes)

flights = client.markets.list_flights(
carrier="AA",
flight_number="100",
date="2026-11-25", # YYYY-MM-DD
)
leg = flights.flights[0]

resp = client.markets.create_flight_disruption_market(
carrier=leg.carrier,
flight_number=leg.flight_number,
departure_airport=leg.departure_airport,
arrival_airport=leg.arrival_airport,
scheduled_date=leg.scheduled_date,
cover="cancelled", # FlightCoverLiteral: "cancelled" / "delayed" / "either"
)
print(resp.market_ticker, resp.created, resp.cover)
```

Take the five flight fields from `list_flights`. For `"delayed"` and
`"either"`, also pass `delay_basis` (`"departure"` / `"arrival"`) and
`delay_minutes` (a multiple of `avail.delay_step_minutes`, up to
`avail.max_delay_minutes`); leave both out for `"cancelled"`. A cover
missing from `avail.covers` cannot be created. The same request always
returns the same market; `created` is false when it already existed.
Pass the returned `market_ticker` to `POST /communications/rfqs`.

## Reference

::: kalshi.resources.markets.MarketsResource
Expand Down
18 changes: 17 additions & 1 deletion kalshi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
CreateFCMPositionTransferResponse,
CreateFCMSubtraderRequest,
CreateFCMSubtraderResponse,
CreateFlightDisruptionMarketRequest,
CreateFlightDisruptionMarketResponse,
CreateMarketInMultivariateEventCollectionRequest,
CreateMarketResponse,
CreateOrderGroupRequest,
Expand Down Expand Up @@ -116,6 +118,10 @@
FcmFill,
FCMSubtrader,
Fill,
Flight,
FlightCoverEvent,
FlightCoverLiteral,
FlightDelayBasisLiteral,
ForecastPercentilesPoint,
GenerateApiKeyRequest,
GenerateApiKeyResponse,
Expand All @@ -130,6 +136,8 @@
GetFcmFillsResponse,
GetFCMSubtraderBlockedCategoriesResponse,
GetFiltersBySportsResponse,
GetFlightDisruptionAvailabilityResponse,
GetFlightsResponse,
GetGameStatsResponse,
GetIncentiveProgramsResponse,
GetIncentiveSchedulesResponse,
Expand Down Expand Up @@ -323,6 +331,8 @@
"CreateFCMPositionTransferResponse",
"CreateFCMSubtraderRequest",
"CreateFCMSubtraderResponse",
"CreateFlightDisruptionMarketRequest",
"CreateFlightDisruptionMarketResponse",
"CreateMarketInMultivariateEventCollectionRequest",
"CreateMarketResponse",
"CreateOrderGroupRequest",
Expand Down Expand Up @@ -374,6 +384,10 @@
"FixConfig",
"FixEnvironment",
"FixSessionType",
"Flight",
"FlightCoverEvent",
"FlightCoverLiteral",
"FlightDelayBasisLiteral",
"ForecastPercentilesPoint",
"GenerateApiKeyRequest",
"GenerateApiKeyResponse",
Expand All @@ -388,6 +402,8 @@
"GetFCMSubtraderBlockedCategoriesResponse",
"GetFcmFillsResponse",
"GetFiltersBySportsResponse",
"GetFlightDisruptionAvailabilityResponse",
"GetFlightsResponse",
"GetGameStatsResponse",
"GetIncentiveProgramsResponse",
"GetIncentiveSchedulesResponse",
Expand Down Expand Up @@ -537,4 +553,4 @@
"Withdrawal",
]

__version__ = "22.14.0"
__version__ = "22.15.0"
32 changes: 32 additions & 0 deletions kalshi/_contract_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,30 @@ class ContractEntry:
sdk_model="kalshi.models.markets.SearchConcertsResponse",
spec_schema="SearchConcertsResponse",
),
ContractEntry(
sdk_model="kalshi.models.markets.CreateFlightDisruptionMarketRequest",
spec_schema="CreateFlightDisruptionMarketRequest",
),
ContractEntry(
sdk_model="kalshi.models.markets.CreateFlightDisruptionMarketResponse",
spec_schema="CreateFlightDisruptionMarketResponse",
),
ContractEntry(
sdk_model="kalshi.models.markets.GetFlightDisruptionAvailabilityResponse",
spec_schema="GetFlightDisruptionAvailabilityResponse",
),
ContractEntry(
sdk_model="kalshi.models.markets.FlightCoverEvent",
spec_schema="FlightCoverEvent",
),
ContractEntry(
sdk_model="kalshi.models.markets.Flight",
spec_schema="Flight",
),
ContractEntry(
sdk_model="kalshi.models.markets.GetFlightsResponse",
spec_schema="GetFlightsResponse",
),
# -- orders V2 family (#171) -----------------------------------------
ContractEntry(
sdk_model="kalshi.models.orders.CreateOrderV2Request",
Expand Down Expand Up @@ -898,6 +922,10 @@ class ContractEntry:
sdk_model="kalshi.perps.models.markets.MarginMarketScheduleDetails",
spec_schema="MarginMarketScheduleDetails",
),
ContractEntry(
sdk_model="kalshi.perps.models.markets.MarginTradingCronSchedule",
spec_schema="MarginTradingCronSchedule",
),
ContractEntry(
sdk_model="kalshi.perps.models.markets.MarginMarketCandlestick",
spec_schema="MarginMarketCandlestick",
Expand All @@ -906,6 +934,10 @@ class ContractEntry:
sdk_model="kalshi.perps.models.markets.BidAskDistributionHistorical",
spec_schema="BidAskDistributionHistorical",
),
ContractEntry(
sdk_model="kalshi.perps.models.markets.MarginAskDistributionHistorical",
spec_schema="MarginAskDistributionHistorical",
),
ContractEntry(
sdk_model="kalshi.perps.models.markets.PriceDistributionHistorical",
spec_schema="PriceDistributionHistorical",
Expand Down
16 changes: 16 additions & 0 deletions kalshi/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,18 @@
ConcertMetro,
CreateConcertCancellationMarketRequest,
CreateConcertCancellationMarketResponse,
CreateFlightDisruptionMarketRequest,
CreateFlightDisruptionMarketResponse,
CreateWeatherPointMarketRequest,
CreateWeatherPointMarketResponse,
Flight,
FlightCoverEvent,
FlightCoverLiteral,
FlightDelayBasisLiteral,
GetConcertCancellationAvailabilityResponse,
GetConcertsResponse,
GetFlightDisruptionAvailabilityResponse,
GetFlightsResponse,
GetWeatherPointAvailabilityResponse,
Market,
MarketCandlesticks,
Expand Down Expand Up @@ -300,6 +308,8 @@
"CreateFCMPositionTransferResponse",
"CreateFCMSubtraderRequest",
"CreateFCMSubtraderResponse",
"CreateFlightDisruptionMarketRequest",
"CreateFlightDisruptionMarketResponse",
"CreateMarketInMultivariateEventCollectionRequest",
"CreateMarketResponse",
"CreateOrderGroupRequest",
Expand Down Expand Up @@ -347,6 +357,10 @@
"FCMSubtrader",
"FcmFill",
"Fill",
"Flight",
"FlightCoverEvent",
"FlightCoverLiteral",
"FlightDelayBasisLiteral",
"ForecastPercentilesPoint",
"GenerateApiKeyRequest",
"GenerateApiKeyResponse",
Expand All @@ -361,6 +375,8 @@
"GetFCMSubtraderBlockedCategoriesResponse",
"GetFcmFillsResponse",
"GetFiltersBySportsResponse",
"GetFlightDisruptionAvailabilityResponse",
"GetFlightsResponse",
"GetGameStatsResponse",
"GetIncentiveProgramsResponse",
"GetIncentiveSchedulesResponse",
Expand Down
Loading
Loading