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>
Several models had incorrect field names after the fixed-point migration (f73888e) which blindly renamed all fields. This fixes them to match the actual API: - BalanceModel: revert to balance/portfolio_value (int cents, never migrated) - FillModel: yes/no_price_dollars → yes/no_price_fixed (API uses _fixed suffix) - PositionModel: total_traded_fp → total_traded_dollars - MarketModel: liquidity_fp → liquidity_dollars - SettlementModel: revert costs/revenue to int cents, keep fee_cost as str - QueuePositionModel: queue_position (int) → queue_position_fp (str) Also adds model_validator to CompatModel for transition period input aliasing — remaps old API field names to new ones using _legacy_fields. 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
yes_price_dollars,yes_ask_dollars, etc.) and counts are fixed-point strings (count_fp,position_fp, etc.)CompatModel) so old integer field names still work with aDeprecationWarning, easing migration for existing usersspread_bpscrash on one-sided orderbooks and normalize compat output formatModel field name corrections (e5d1162)
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)Transition period support
Added
model_validator(mode='before')toCompatModelthat remaps old API field names to new ones using the existing_legacy_fieldsmapping. This handles the transition period (until March 12) where the API may return old field names.Test plan
🤖 Generated with Claude Code