Skip to content

FIX/strike_limit typed as float causes API requests to fail#28

Open
MarketDataDev03 wants to merge 1 commit into
mainfrom
strike_limit_typed_as_float
Open

FIX/strike_limit typed as float causes API requests to fail#28
MarketDataDev03 wants to merge 1 commit into
mainfrom
strike_limit_typed_as_float

Conversation

@MarketDataDev03
Copy link
Copy Markdown
Collaborator

Fix: strike_limit typed as float causes API requests to fail

Closes #24

Summary

options.chain(..., strike_limit=10) failed because strike_limit was annotated
as float | None. Pydantic (lax mode) coerced the integer 10 to 10.0, which
was then serialized into the request URL as strikeLimit=10.0 — a value the API
rejects, since strike_limit is a count of strikes, not a price.

This PR changes the field's type to int | None so integer inputs stay integers
on the wire, and updates the documentation accordingly.

Problem

client.options.chain(symbol="AAPL", strike_limit=10)
# → request URL: .../options/chain/AAPL/?...&strikeLimit=10.0
# → API rejects the request

Root cause — src/marketdata/input_types/options.py:67:

strike_limit: float | None = Field(
    description="The strike limit to filter by", alias="strikeLimit", default=None
)

Changes

src/marketdata/input_types/options.py

-    strike_limit: float | None = Field(
+    strike_limit: int | None = Field(
         description="The strike limit to filter by", alias="strikeLimit", default=None
     )

With int | None, Pydantic keeps 10 as 10, and _build_url serializes it
into strikeLimit=10.

docs/options.md

-- `strike_limit` (float, optional): Limit the number of strikes
+- `strike_limit` (int, optional): Limit the number of strikes

Testing

Two new tests in src/tests/test_options_chain.py, covering the bug at two
levels:

  • test_options_chain_input_strike_limit_typed_as_int — unit test on the
    input model. Asserts that OptionsChainInput(strike_limit=10).strike_limit is
    kept as an int (type(...) is int), not coerced to a float.
  • test_options_chain_strike_limit_is_int_on_wire — integration test that
    inspects the actual outgoing request via
    respx_mock.calls.last.request.url.params and asserts
    params["strikeLimit"] == "10" (not "10.0"). Mirrors the existing
    test_options_chain_input_date_range_aliases_on_wire pattern.

Developed with a TDD red → green cycle.

297 passed

Full suite green — no regressions.

Files changed

File Change
src/marketdata/input_types/options.py strike_limit retyped float | Noneint | None
docs/options.md Documented type updated to int
src/tests/test_options_chain.py 2 new regression tests

@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (fb1ea8e) to head (a986efd).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #28   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           52        52           
  Lines         2281      2281           
=========================================
  Hits          2281      2281           
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MarketDataDev03 MarketDataDev03 changed the title strike_limit typed as float causes API requests to fail FIX/strike_limit typed as float causes API requests to fail May 28, 2026
@MarketDataDev03 MarketDataDev03 marked this pull request as ready for review May 28, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

strike_limit typed as float causes API request to fail

1 participant