Skip to content

Fix market data bugs found in code review - #7

Merged
Piyushpal77 merged 1 commit into
mainfrom
fix/market-data-review-findings
Sep 11, 2026
Merged

Piyushpal77 merged 1 commit into
mainfrom
fix/market-data-review-findings

Conversation

@Piyushpal77

Copy link
Copy Markdown
Owner

Summary

  • massive_client.py: a snapshot's previous_close == 0.0 (thin data, newly-listed ticker) was accepted as a real day-change anchor instead of falling back to "first observed price" — now anything falsy triggers the fallback.
  • reconcile.py: on_watchlist_remove checked quantity == 0 while on_trade_executed checked quantity > 0 — an asymmetric float boundary that could leave a ticker tracked forever after float drift left quantity at e.g. -1e-16 instead of exact zero. Aligned to <= 0 / > 0. Also dropped an unnecessary is_on_watchlist DB read in on_trade_executed when a position is still open.
  • validation.py: validate_ticker("ß") uppercased to "SS" and passed the 1-5-letter regex despite being a single non-ASCII character. Added an ASCII check before the regex.

Found via /code-review backend, verified by hand, and regression-tested.

Test plan

  • Added regression tests for all three fixes (test_massive.py, test_reconcile.py, test_validation.py)
  • cd backend && uv run --extra dev pytest -v — 128/128 passed
  • cd backend && uv run --extra dev ruff check app/ tests/ — clean

🤖 Generated with Claude Code

https://claude.ai/code/session_01Qr8v6nVUrBLnCuH8HJWKto

- massive_client.py: treat a snapshot's previous_close of 0.0 (thin
  data, newly-listed ticker) the same as missing, falling back to the
  first-observed-price anchor instead of pinning day-change to a zero
  baseline.
- reconcile.py: align on_watchlist_remove's open-position check
  (quantity <= 0) with on_trade_executed's (quantity > 0) so tiny
  float drift after a "full" sell can't leave a ticker tracked
  forever. Also skip the now-unneeded is_on_watchlist read when a
  position is still open.
- validation.py: reject non-ASCII input before uppercasing, since
  some Unicode codepoints expand under .upper() (German sharp s ->
  "SS") and could otherwise slip through the 1-5-letter format check.

Added regression tests for all three. Full suite: 128/128 passing.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qr8v6nVUrBLnCuH8HJWKto
@Piyushpal77
Piyushpal77 merged commit c8b9ea9 into main Sep 11, 2026
1 check passed
@Piyushpal77
Piyushpal77 deleted the fix/market-data-review-findings branch September 11, 2026 13:23
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.

1 participant