Complete fixed-point/subpenny migration per Kalshi API#4
Merged
arshka merged 4 commits intoarshka:mainfrom Mar 10, 2026
Merged
Conversation
Migrate all integer cent fields to `_dollars` string fields and all integer count fields to `_fp` string fields, matching Kalshi's fixed-point migration guide. Add order validation for price_level_structure tick sizes and fractional trading. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Existing code using old integer field names (yes_bid, count, balance, etc.)
now works via CompatModel with deprecation warnings pointing to new names.
GET (reading): Legacy integer accessors derive from new string fields via
__getattr__, e.g. market.yes_bid → int(Decimal("0.45") * 100) = 45.
POST (writing): Old integer params (count=5, yes_price=45) convert to new
string params (count_fp="5", yes_price_dollars="0.45") with warnings.
- New pykalshi/_compat.py: CompatModel base class, conversion functions,
convert_legacy_kwargs helper, and standard legacy param mappings
- Updated 20 model classes in models.py with _legacy_fields mappings
- Updated 6 WebSocket message models in feed.py with _legacy_fields
- Added legacy params to all POST methods in portfolio.py (sync+async)
- Added legacy params to Order.amend/decrease in orders.py (sync+async)
- Added legacy params to create_rfq in communications.py (sync+async)
- 34 new tests in tests/test_compat.py (294 total tests passing)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…put format spread_bps would crash with TypeError when spread/mid were None (empty or one-sided orderbook). cents_to_dollars and int_to_fp now produce canonical fixed-point strings (e.g. "0.50", "5.00") matching the Kalshi API format. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Cover _validate_tick_size for all three price_level_structures (linear_cent, deci_cent, tapered_deci_cent) including boundary conditions, and _validate_fractional for enabled/disabled cases. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Complete migration of all pricing and quantity fields to Kalshi's new fixed-point string format, with a backward-compatibility layer for smooth migration.
What changed
All integer cent fields →
_dollarsstring fields:yes_bid,yes_ask,no_bid,no_ask→yes_bid_dollars,yes_ask_dollars, etc.last_price,previous_yes_bid,previous_yes_ask,previous_price→*_dollarsvariantssettlement_value,notional_value,tick_size→*_dollarsvariantsyes_price,no_price(orders/trades) →yes_price_dollars,no_price_dollars*_dollarsAll integer count fields →
_fpstring fields:count,initial_count,fill_count,remaining_count→*_fpvariantsposition,total_traded→position_fp,total_traded_dollarsvolume,volume_24h,open_interest→*_fpvariantsBackward-compatibility layer (
CompatModel):market.yes_bid,order.count) still work via__getattr__withDeprecationWarningmodel_validator(mode='before')remaps old API field names during the transition period (until March 12)Model field name corrections
Several models had incorrect field names after the initial migration which blindly renamed all fields. Fixed to match actual Kalshi API responses:
balance/portfolio_value(intcents — API never migrated these)yes_price_dollars/no_price_dollars→yes_price_fixed/no_price_fixed(API uses_fixedsuffix for fill prices)total_traded_fp→total_traded_dollars(it's a dollar amount, not a count)liquidity_fp→liquidity_dollarsintcents, keptfee_costasstr(FixedPointDollars)queue_position(int) →queue_position_fp(str)New features
_validate_tick_size()validates price alignment forlinear_cent,deci_cent, andtapered_deci_centstructures_validate_fractional()rejects fractionalcount_fpon non-fractional marketsorderbookandorderbook_fpAPI keys viaAliasChoicesTest plan
🤖 Generated with Claude Code