fix(ci): MoneyBox 遷移至新 endpoint 並修正欄位反轉與單位差 - #1051
Merged
Merged
Conversation
- 官網已完全改打 moneybox-exchange.com/api/rates,舊 cems 端點半殘 - 舊端點仍回 200 但 18 於 20 幣別 sell 恆 0,純 API 探測察覺不到搬家 - 新舊 buy 與 sell 語意相反:新 buyRate 等同舊 sell,反之亦然 - 以具名常數表達反向對應,避免後人照字面對接取到價差錯誤側 - 新 API 僅三欄位,base 改由兩側中點推導,spbuy 與 spsell 一律 null - JPY 與 IDR 與 VND 由上游 per-1 還原為既有 per-100 慣例 - 換算以輸入位數推導輸出位數,避免乘除產生二進位浮點雜訊 - 0 與非有限值視為上游未報價,交由既有熔斷判定 測試:新增 9 條守門測試涵蓋映射方向、價差方向、per-100 還原與缺值處理; 以反轉映射的反向測試確認守門會擋;實跑驗證輸出與官網顯示一致且對外欄位 集合零變化;scripts typecheck 與 test:root 157 測試全綠 Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
Contributor
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Contributor
|
✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c7637d7954
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Comment on lines
198
to
+199
| const data = await response.json(); | ||
| const upstreamRows = data?.data?.rates; |
There was a problem hiding this comment.
| // MoneyBox 公開 API。 | ||
| // 2026-08 上游遷移:官網已完全改打自有 endpoint,舊 cems.moneybox.or.kr 雖仍回 200 | ||
| // 但 18/20 幣別的 sell 恆為 0(半殘)。以瀏覽器攔截官網請求確認新端點(PRD 049 §2.1)。 | ||
| const MONEYBOX_API_URL = 'https://moneybox-exchange.com/api/rates'; |
There was a problem hiding this comment.
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.
修什麼
MoneyBox 匯率抓取自 2026-08-22 起持續失敗,已停更 4 天。根因不是上游壞掉,是上游搬家。
以瀏覽器載入官網並攔截網路請求確認:
舊端點半殘(仍回 200、
base持續更新,但 18/20 幣別sell恆為 0),所以純 API 探測分不出「壞掉」與「搬家」。三個陷阱
1. buy / sell 語意相反
新
buyRate≡ 舊sell;新sellRate≡ 舊buy。 三重驗證:sell;賣出 1,028 = 舊buybuyRate;賣出 1,015 = 新sellRatesell<buy;新buyRate<sellRate— 店家低買高賣,順序一致照字面把
sell對到sellRate會取到價差的錯誤那一側。程式碼以具名常數表達這個反向對應,避免後人重蹈:2. JPY / IDR / VND 單位差 100 倍
新 API 一律 per-1,舊 API 對小面額幣別為 per-100。維持既有慣例以保歷史連續。
實跑結果與官網顯示完全一致:JPY 868/872、VND 5.1/5.6、IDR 7.8/9。
3. 上游移除
base/spbuy/spsell新 API 每列僅 3 欄位(
currencyCode/buyRate/sellRate)。端點探查確認/api/rates/latest、/history、/currencies、/config、/branches皆 404。base改由兩側牌告價的算術中點推導spbuy/spsell一律null,不得以其他欄位推導填補我自己引入又修掉的一個回歸
per-100 換算直接乘 100 會產生浮點雜訊:
這些值上游原本直接提供且乾淨,我的換算反而讓公開產物變糟。已改為以輸入位數推導輸出位數收斂(×100 減兩位、中點取較多者加一位),並加守門測試斷言輸出不得帶浮點尾數。
驗證
對外零變化(PR 1 的核心驗收標準):
守門測試:新增 9 條,涵蓋映射方向、價差方向、per-100 還原、0 與非有限值、缺 currencyCode。
反向測試:把映射改回「照字面對接」後,2 條測試立即失敗 —— 守門確實會擋。
scriptstypecheckpnpm test:root刻意不放進這個 PR
輪詢頻率調整。 上游標頭自宣
cache-control: max-age=14400(4 小時),我方 cron 每 5 分鐘(288 次/日,48 倍)。PRD §18.2 已裁決應改依上游快取契約並帶If-Modified-Since。但那會改變對外更新節奏,與本 PR 的「對外零變化」驗收標準衝突,依 PRD §3.2「不混合關注點」原則另開 PR。
關聯
docs/dev/049)🤖 Generated with Claude Code