Repository navigation
feat: baostock 优先的可选开关 - #23
Open
xuyixiao0224 wants to merge 1 commit into
Open
xuyixiao0224 wants to merge 1 commit into
xuyixiao0224 wants to merge 1 commit into
Conversation
东财接口被持续风控时,_fetch_history 每轮都要先发一次注定失败的请求再回退 baostock,刷新间隔短时开销明显,日志中也堆满重复告警。 新增可选开关 PA_AGENT_BAOSTOCK_PRIMARY,置 1/true/yes 时直接先走 baostock, 失败仍回退原东财主源;前置条件为 self._baostock_ok,未连接时不启用。 默认关闭,不设置该变量时行为完全不变。
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.
问题
AkShareSource._fetch_history()固定先走东方财富接口,失败才回退 baostock。东财接口在部分网络环境下会被持续风控。此时每次刷新都要先发一次注定失败的请求、等它超时或报错,再回退 baostock。刷新间隔短时这个固定开销很明显,日志里也塞满重复的失败告警。
改动
加一个可选的环境变量开关
PA_AGENT_BAOSTOCK_PRIMARY:1/true/yes时,_fetch_history()直接先走 baostockself._baostock_ok(baostock 已连接成功),未连接时不走这条路兼容性
不设置这个变量时行为完全不变,默认关闭。
为什么用环境变量而不是设置项
想尽量不侵入现有配置:不动
settings.py的 schema、不动设置界面、不影响settings.json的读写兼容。如果维护者认为这更适合作为正式设置项,我可以改成GeneralSettings里的字段并补设置界面。测试
pytest -m "not e2e"ruff check pa_agent testsPA_AGENT_BAOSTOCK_PRIMARY=1→ 日志中直接走 baostock,K 线正常