Skip to content

Fix: min/max price filters on OptionsChainInput are never validated (#32)#33

Merged
MarketDataDev03 merged 2 commits into
mainfrom
min_max_filter_bug
Jun 10, 2026
Merged

Fix: min/max price filters on OptionsChainInput are never validated (#32)#33
MarketDataDev03 merged 2 commits into
mainfrom
min_max_filter_bug

Conversation

@MarketDataDev03

@MarketDataDev03 MarketDataDev03 commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

Fix: min/max price filters on OptionsChainInput are never validated

Closes #32

Problem

OptionsChainInput declared a model_validator meant to enforce min ≤ max on
the bid/ask price filters, but the check never ran. It reused the date-only
helper _validate_min_max_dates, which compares the two values only when both
pass check_is_date(...). Bid/ask filters are float, so the comparison was
skipped entirely and an inverted range was accepted silently:

# Before: constructs fine, no error raised.
OptionsChainInput(symbol="AAPL", min_bid=5.0, max_bid=1.0)
OptionsChainInput(symbol="AAPL", min_ask=10.0, max_ask=2.0)

This sent obviously invalid requests to the API instead of rejecting them
client-side, defeating the purpose of the validator. There was also a typo in
the local variable (params_typles).

Changes

  • exceptions.py — introduced a common base MinMaxValidationError, with
    two specialized subclasses sharing it:
    • MinMaxValueValidationError — numeric ranges.
    • MinMaxDateValidationError — date ranges (previously a direct subclass of
      BaseMarketdataException; now also catchable as MinMaxValidationError).
  • input_types/base.py — added a numeric-aware helper
    _validate_min_max_value(min_param, max_param) that raises
    MinMaxValueValidationError when both bounds are set and min > max. The
    existing _validate_min_max_dates is kept for genuine date ranges.
  • input_types/options.pyOptionsChainInput.validate_input now uses
    _validate_min_max_value for the (min_bid, max_bid) and (min_ask, max_ask)
    pairs, and fixed the params_typlesparams_tuples typo.

Why a separate helper instead of reusing the date helper

Date filters can be datetime.date or strings in several formats, so they need
the check_is_date gating. Price filters are plain numbers and just need a
direct min > max comparison. Keeping the two helpers separate avoids
overloading one path and keeps each validation intent explicit.

Scope note

min_open_interest, min_volume, max_bid_ask_spread, and
max_bid_ask_spread_pct have no min/max counterpart in the model, so there are
no other ordered numeric pairs to validate.

@MarketDataDev03 MarketDataDev03 marked this pull request as ready for review June 1, 2026 14:49
@MarketDataDev03 MarketDataDev03 self-assigned this Jun 1, 2026
@codecov

codecov Bot commented Jun 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (69eb52c) to head (2f9961a).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #33   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           52        52           
  Lines         2284      2293    +9     
=========================================
+ Hits          2284      2293    +9     
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 Harness.
📢 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 marked this pull request as draft June 1, 2026 14:51
@MarketDataDev03 MarketDataDev03 marked this pull request as ready for review June 1, 2026 14:51
@MarketDataDev02 MarketDataDev02 self-requested a review June 8, 2026 16:27
# Conflicts:
#	src/tests/test_input_types.py
@MarketDataDev03 MarketDataDev03 merged commit 608240f into main Jun 10, 2026
5 checks passed
@MarketDataDev03 MarketDataDev03 deleted the min_max_filter_bug branch June 10, 2026 14:03
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.

Bug: min/max price filters on options.chain are never validated (min_bid > max_bid passes silently)

2 participants