feat(sinafinance): rewrite stock as public API, no browser required#563
Merged
feat(sinafinance): rewrite stock as public API, no browser required#563
Conversation
Replace browser-based DOM scraping with direct Sina public APIs: suggest3.sinajs.cn — symbol search (GBK, no auth) hq.sinajs.cn — real-time quote (GBK, no auth) Strategy.PUBLIC, browser: false — no Chrome or login required. Supports A股 (sh/sz), 港股 (hk prefix), 美股 (gb_ prefix). US MarketCap parsed from hq field [12]; formatted as T/B/M.
Introduce EXIT_CODES constant table (sysexits.h conventions) and wire exitCode into every CliError subclass so the process exit code reflects the semantic type of failure: 0 success (default) 1 generic / unexpected error 2 argument / usage error (ArgumentError) 66 empty result / not found (EmptyResultError, SelectorError) 69 service unavailable (BrowserConnectError, AdapterLoadError) 77 permission / auth required (AuthRequiredError) 78 configuration error (ConfigError) 124 timeout (TimeoutError) 130 Ctrl-C / SIGINT (unchanged, tui.ts) resolveExitCode() in commanderAdapter.ts reads err.exitCode for typed CliErrors, and falls back to pattern-matching message text for untyped adapter errors (auth pattern → 77, not-found pattern → 66, else → 1). Shell scripts can now distinguish error categories: opencli spotify status || echo "exit $?" # 69 if browser not running opencli github issues --repo x 2>/dev/null; [ $? -eq 77 ] && opencli github auth
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
将
sinafinance stock命令从 Browser 模式重写为 Public API 模式。动机
原实现(#546 合入)通过浏览器自动化:打开搜索页 → 操作 suggest DOM → 跳转股票页 → 抓取页面 DOM,存在以下问题:
page.wait(5)= 至少 10s 延迟#fcSuggest_140418等动态生成 DOM ID,脆弱方案
新浪本身提供两个无需认证的公开 API:
suggest3.sinajs.cn/suggest?type=11,31,41&key=...hq.sinajs.cn/list={symbol}变化
Strategy.COOKIE→Strategy.PUBLIC,browser: falsesh600519),港股加hk前缀,美股加gb_前缀字段来源