Repository navigation
Fall back to corporate-action tickers in /quote - #13
Merged
Merged
Conversation
While a corporate action is pending PSX lists a stock under a suffixed ticker (LUCK as LUCKXD after going ex-dividend), so quote lookups for the plain ticker returned 404. Try the XD/XB/XR variants (and the plain ticker for a suffixed request) against the cached screener before returning 404. No extra PSX request is made. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011BozobrSBF72VtuhM8jgUY
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.
Problem
/stocks/{symbol}/quotereturned 404 for stocks with a pending corporate action. While a dividend, bonus or rights issue is pending, PSX lists the stock in its screener under a suffixed ticker (LUCK→LUCKXD), andpsxdata.quote()only matches the exact ticker.The production logs (Sep 28 – Oct 2) show the impact:
/quote/LUCKreturned 404 2,085 times, from 133 clients./quote/LUCKXDreturned 200 581 times.The live screener currently has 23 suffixed tickers: 21
XD, plusBPLXBandEFULXR.Change
api/routers/stocks.py: if the exact ticker isn't in the screener, try theXD(ex-dividend),XB(ex-bonus) andXR(ex-rights) variants, in that order.LUCKXD) also falls back to the plain ticker once PSX drops the suffix.JVDCR1, are separate securities and are not matched.quote()just cached, so it makes no extra PSX request. The same holds in proxy-passthrough mode, where the cache-only client answers it.data.symbolis the ticker PSX currently lists. A request forLUCKreturns"symbol": "LUCKXD".Testing
tests/api/test_stocks.pycover the plain → suffixed and suffixed → plain lookups, an exact match skipping the screener, and unrelated suffixes still returning 404. The existing 404 test now mocks the screener.ruff check api/,mypy api/andpytest tests/api/all pass: 228 tests./quote/LUCK→ 200,LUCKXD, 410.56/quote/LUCKXD→ 200/quote/ENGRO→ 200/quote/MZNPETF→ 404Not covered
ETFs (MZNPETF, HBLTETF and others), JUBL and PTCL also return 404 on
/quote. They aren't in PSX's screener under any ticker, so they need a different data source and are left for a separate change.