個股端點 story 全部回傳(#2114)Integration Guide — Frontend
Backend branch: feat/2114-stories-no-display-cap → cortex/dev
Endpoints(個股層級,stories[] 改為全部回傳):
- GET /api/signals/stock/{ticker}(technical/chip/financial 三段,含 deprecated *_signals 別名段)
- GET /api/agent/technical/{ticker}
- GET /api/agent/chip/{ticker}
- GET /api/agent/financial/{ticker}
- GET /api/daily-analysis/{ticker}/latest、GET /api/daily-analysis/{ticker}?from=&to=
生效時間:merge 後 cortex-api --reload 立即生效;無 migration、無 schema 變更、不需重啟 scheduler(快取本來就存全部 story,只是讀的時候不再修剪)。
Consumer:個股頁的 story 區塊(技術面/籌碼面/財務面)。本次盤點 docs/integration/ 只有前端 consumer 紀錄;若有未登記的 consumer,請補一份對應檔案。
相容性:沒有欄位改名、新增或刪除,型別不變;只有
stories[]的長度上限拿掉了。前端若假設「最多 3 個」直接排版,會多出來;請改成「預設顯示前 3 個、可展開看完整」。
1. 欄位 diff 表
| endpoint | 欄位 | 型別 | 變動 | 語意 |
|---|---|---|---|---|
| 上列全部 | 各面向 stories |
Story[] |
長度上限移除 | 依引擎排序(priority 優先,同 priority 再比 score)回全部 story;原本每域只回前 3 個 |
| 上列全部 | 各面向 relations |
Relation[] |
隨之變長 | 指向 story 的 relation 涵蓋全部 story,不再有「story 被修剪、relation 也跟著拿掉」 |
GET /api/signals/stock/{ticker} |
story_type/role/story_reasons/chip_signal_type 等 deprecated alias |
不變 | 值不變 | 仍只在前 3 個裡取分數最高者,與改動前同值 |
GET /api/signals/latest(含 ?ticker=&view=full)、GET /api/signals/chip-highlights、GET /api/signals/financial-highlights |
stories |
不變 | 不變 | 列表端點仍依 ses_display.story_top_n_per_domain 每域取前 N 筆 |
2. 行為對照表
| 情境 | 修前 | 修後 |
|---|---|---|
| 某檔某面向有 ≤3 個 story | 全部回 | 全部回(不變) |
| 某檔某面向有 >3 個 story | 只回前 3 個 | 全部回,順序同前(前 3 個與修前完全相同) |
指定 qryDate/歷史日期 |
只回前 3 個 | 全部回 |
首頁/列表 GET /api/signals/latest |
每域前 N 個 | 不變 |
量測(2026-11-03 對 dev 唯讀查 taiwan.latest_ses_snapshot,interval='1d',trading_date = 2026-11-02 的列):
SELECT domain, trading_date, count(*) AS rows,
count(*) FILTER (WHERE jsonb_array_length(stories_json::jsonb) > 3) AS over_3,
max(jsonb_array_length(stories_json::jsonb)) AS max_stories
FROM taiwan.latest_ses_snapshot
WHERE interval = '1d' AND domain IN ('technical', 'chip', 'financial')
AND trading_date = DATE '2026-11-02'
GROUP BY domain, trading_date ORDER BY domain;
domain | trading_date | rows | over_3 | max_stories
-----------+--------------+------+--------+-------------
chip | 2026-11-02 | 2353 | 34 | 4
financial | 2026-11-02 | 2414 | 226 | 5
technical | 2026-11-02 | 2354 | 320 | 10
3. TypeScript type diff
型別不變。唯一要改的是 UI 不可假設 stories.length <= 3:
interface DomainPayload {
- stories: Story[]; // 最多 3 個
+ stories: Story[]; // 全部;依引擎排序,前 3 個即舊版會看到的 3 個
relations: Relation[];
}
4. 範例
2026-11-03 對 dev 資料庫唯讀實測(同一組端點,改動前 = cortex/dev c3147dde 程式,改動後 = 本分支程式;n 為該面向 stories 個數,alias 為 deprecated story_type):
| endpoint | 改動前 | 改動後 |
|---|---|---|
GET /api/signals/stock/4568.TWO(technical) |
n=3 | n=10 |
GET /api/signals/stock/4568.TWO?qryDate=2026-11-02(technical) |
n=3 | n=10 |
GET /api/agent/technical/4568.TWO |
n=3 | n=10 |
GET /api/daily-analysis/4568.TWO/latest |
n=3 | n=10 |
GET /api/agent/chip/1219.TW |
n=3 | n=4 |
GET /api/signals/stock/1219.TW(chip) |
n=3, alias=cost_defense |
n=4, alias=cost_defense |
GET /api/signals/stock/1219.TW?qryDate=2026-10-30(chip) |
n=3, alias=cost_defense |
n=4, alias=cost_defense |
GET /api/agent/financial/2330.TW |
n=3 | n=5 |
GET /api/signals/stock/2330.TW(financial) |
n=3, alias=earnings_acceleration |
n=5, alias=earnings_acceleration |
GET /api/signals/latest?ticker=4568.TWO&view=full(列表) |
n=3 | n=3(不變) |
1219.TW 籌碼面改動後的順序:foreign_entry、institutional_accumulation、cost_defense、ownership_accumulation,前 3 個與改動前相同。#2115 的「成本防守」(high_volume_cost_defense)在 dev 該日 ledger 尚未出現;它出現時會依 priority 301 排在 cost_defense 之後(見 chip-high-volume-support-resistance-frontend.md §4-7)。
5. 前端遷移 checklist
- [ ] story 區塊預設顯示前 3 個(
stories.slice(0, 3)),stories.length > 3時顯示「展開」,展開後顯示全部 - [ ] 版面要容得下較長的清單:量測到單一面向最多 10 個(技術面)
- [ ] 若有用
relations找 story 對應的 signal/event:被展開的第 4 個以後也有 relation,可直接沿用 - [ ] deprecated
story_type等 alias 值不變,不需調整 - [ ] 首頁/列表(
GET /api/signals/latest)不受影響,不需調整
6. 參考
- 需求:#2114
- API 文件:
docs/api-reference.md的GET /api/signals/stock/{ticker}「stories[]回該面向全部 story」一節 - 設定:
config/core.yamlses_display.story_top_n_per_domain(現只作用於列表端點)