fix(trading): make equity heartbeats reliable#10
Merged
Conversation
kunkundi
approved these changes
Jul 17, 2026
kunkundi
left a comment
Owner
There was a problem hiding this comment.
再次评审 PR #10 的最新版本。
此前评审中发现了两个需要处理的问题:
- P1:权益心跳刷新行情期间若发生并发成交,旧账户状态可能覆盖成交后的持仓和同分钟权益点。
- P2:后台任务每 5 秒轮询,但原时间判断只接受
15:00:00,可能错过当天收盘权益点。
相关修复已补充到该 PR 分支:
- 行情请求移到状态锁之外,写入前在跨进程锁内重新读取最新账户状态,只合并行情字段,避免覆盖并发成交结果。
- SQLite 权益同步延后到 JSON 状态完成合并之后,确保两处保存的是同一个最终权益点。
- 权益心跳使用独立的采样时段,覆盖整个
15:00分钟,并继续将记录时间规范化为15:00:00。 - 原有交易执行时段没有放宽。
- 增加并发成交和
15:00:01 / 15:00:59 / 15:01:00边界回归测试。
结合 Issue #9 重新核对后,独立后台采样、自然分钟分桶、实时行情刷新和缓存失效等目标均已覆盖。相关测试及 GitHub Validate 均通过,当前 PR 状态为 CLEAN / MERGEABLE。
未发现新的阻塞问题,建议批准合并。
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.
修改内容
:00。refresh_position_quotes()调用,改用项目已有的refresh_realtime_prices()。问题原因
现有实时权益心跳只在
get_practice_payload()处理完整 Dashboard 请求时触发。页面关闭、请求较少或运行在无头服务器上时,服务没有独立生产者继续写入分钟权益点。原有时间判断比较距上一点经过的秒数。若上一点记录在
10:00:59,即使当前已经进入10:01,在10:01:01仍会因为不足 60 秒而跳过;长期运行后采样秒数也会持续漂移。此外,持仓刷新调用了项目中不存在的
refresh_position_quotes()。该异常会被降级处理捕获,因此任务表面可继续运行,但权益可能基于旧持仓价格写入。Closes #9
兼容性与影响范围
验证结果
新增的 3 项 Dashboard 心跳定向测试全部通过:
完整验证共运行 467 项 Python 测试,其中 462 项通过;其余 5 项均可在未修改的
main上复现,属于 Windows 路径分隔符、POSIX 权限位和子进程中文编码差异,与本次修改无关。完整验证同时通过了受影响的 Python 编译检查及 JavaScript、Shell、Windows BAT 语法检查。