Fix market data bugs found in code review - #7
Merged
Merged
Conversation
- 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
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
massive_client.py: a snapshot'sprevious_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_removecheckedquantity == 0whileon_trade_executedcheckedquantity > 0— an asymmetric float boundary that could leave a ticker tracked forever after float drift left quantity at e.g.-1e-16instead of exact zero. Aligned to<= 0/> 0. Also dropped an unnecessaryis_on_watchlistDB read inon_trade_executedwhen 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
test_massive.py,test_reconcile.py,test_validation.py)cd backend && uv run --extra dev pytest -v— 128/128 passedcd backend && uv run --extra dev ruff check app/ tests/— clean🤖 Generated with Claude Code
https://claude.ai/code/session_01Qr8v6nVUrBLnCuH8HJWKto