Skip to content

Fall back to corporate-action tickers in /quote - #13

Merged
mtauha merged 1 commit into
mainfrom
claude/quote-corporate-action-suffix
Oct 5, 2026
Merged

mtauha merged 1 commit into
mainfrom
claude/quote-corporate-action-suffix

Conversation

@mtauha

@mtauha mtauha commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Problem

/stocks/{symbol}/quote returned 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), and psxdata.quote() only matches the exact ticker.

The production logs (Sep 28 – Oct 2) show the impact:

  • /quote/LUCK returned 404 2,085 times, from 133 clients.
  • /quote/LUCKXD returned 200 581 times.
  • FCCL, ISL, INDU, COLG, SAZEW, LCI, FHAM and JVDC failed the same way.

The live screener currently has 23 suffixed tickers: 21 XD, plus BPLXB and EFULXR.

Change

  • api/routers/stocks.py: if the exact ticker isn't in the screener, try the XD (ex-dividend), XB (ex-bonus) and XR (ex-rights) variants, in that order.
    • A suffixed request (LUCKXD) also falls back to the plain ticker once PSX drops the suffix.
    • Other suffixes, such as the rights ticker JVDCR1, are separate securities and are not matched.
  • The fallback reads the screener that quote() just cached, so it makes no extra PSX request. The same holds in proxy-passthrough mode, where the cache-only client answers it.
  • An exact match never touches the fallback.
  • Behavior change: the response's data.symbol is the ticker PSX currently lists. A request for LUCK returns "symbol": "LUCKXD".

Testing

  • New tests in tests/api/test_stocks.py cover 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/ and pytest tests/api/ all pass: 228 tests.
  • Live check against PSX through the app's TestClient:
    • /quote/LUCK → 200, LUCKXD, 410.56
    • /quote/LUCKXD → 200
    • /quote/ENGRO → 200
    • /quote/MZNPETF → 404

Not 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.

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
@mtauha
mtauha merged commit ee742d7 into main Oct 5, 2026
4 checks passed
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.

2 participants