fix: 交易分析接口对资金或回合文件缺失不设防 - #191
Open
xukanshan wants to merge 2 commits into
Open
Conversation
问题背景: init_bt_apis 内各路由约定 getter 对文件缺失返回 None, 但路由层 普遍不做 None 检查; get_bt_closes 的存在性判断与 indice.csv 的 可选叠加逻辑也存在条件缺陷。 问题表现: - 策略名为空串等边界请求下, qrybtcloses 连续 5 次调用 get_bt_closes 后直接取下标, 抛 TypeError: 'NoneType' object is not subscriptable, 接口 500; - get_bt_kline 返回 None 时 qrybars 解包即抛 cannot unpack non-iterable NoneType; - closes.csv 存在而 summary.json 缺失时, 存在性判断用 or 逻辑漏判, 打开 summary 抛 FileNotFoundError; - 存在 indice.csv 但 btchart.json 缺失时, 对 None 遍历抛 TypeError; - 任意路由传入无效工作区 id 时, 分支内仅给 ret 赋值未 return, 穿透后用空路径继续执行。 问题原因: 路由层与 getter 的 None 返回约定之间缺少防护; 两个条件表达式 与实际语义不符。 问题修复: - 各路由对无效工作区统一提前 return result=-1; - qrybtcloses 改为单次调用 get_bt_closes 并对 None 提前返回 result=-2(顺带消除一次请求重复解析 5 遍 CSV 的浪费); - qrybars 对 get_bt_kline 返回 None 提前返回 result=-2; - closes 存在性判断 or 改为 and; - indice 叠加循环对 None 跳过。 验证: 以实际回测输出验证: 空 straid、无效 wsid 等边界请求全部返回 约定错误码(200 + result=-1/-2)而非 500(9 个路由逐一验证), 正常请求结果与修复前完全一致。 (cherry picked from commit a422ea0)
问题背景: get_bt_analysis 需要同时读取 funds.csv 与 closes.csv, 与已修复的 get_bt_closes 存在性判断属同一缺陷家族。 问题表现: 仅存在其中一个文件时, 存在性判断(or 逻辑)漏判, read_csv 抛 FileNotFoundError, 接口 500。 问题修复: 存在性判断 or 改为 and, 任一文件缺失即按约定返回 None, 由路由层的 None 防护统一兜底。 验证: 以实际回测输出验证, 正常请求结果不变, 缺失文件场景 返回约定错误码而非 500。 (cherry picked from commit 6ce86a5)
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.
问题背景:
get_bt_analysis 需要同时读取 funds.csv 与 closes.csv,
与已修复的 get_bt_closes 存在性判断属同一缺陷家族。
问题表现:
仅存在其中一个文件时, 存在性判断(or 逻辑)漏判,
read_csv 抛 FileNotFoundError, 接口 500。
问题修复:
存在性判断 or 改为 and, 任一文件缺失即按约定返回 None,
由路由层的 None 防护统一兜底。
验证:
以实际回测输出验证, 正常请求结果不变, 缺失文件场景
返回约定错误码而非 500。