Commit Graph
560 Commits
Author SHA1 Message Date
wshy 312c02fb29 Merge pull request #155 from shy3130/feat/composite-strategy
feat: 新增叠加策略(composite)支持选股与回测
2026-08-02 11:00:52 +08:00
shy3130 a2bea0240a fix(ui): 修复所有弹窗拖拽穿透导致误关闭的问题
问题: 用户在弹窗内容内拖选文本时, 鼠标移到遮罩松开会触发遮罩 click, 导致弹窗意外关闭(click 派发给 mousedown/mouseup 共同祖先)。

方案: 抽取共享 hook useDialogBackdrop, 用 mousedown 跟踪——只有按下和松开都在遮罩上才关闭。Modal.tsx 内置同样逻辑。所有手写遮罩弹窗统一接入。
2026-08-02 10:56:24 +08:00
shy3130 4696fef959 feat(composite): 新增叠加策略(composite)支持选股与回测
引入第四种执行后端 composite: 声明式引用多个子策略, 复用现有注册表/缓存/撮合全链路。

核心设计:
- 退出采用来源投影(每个子策略 exit 仅在自己持仓窗口生效, 不串平其他子策略仓位)
- 评分用标准化排名加权(跨子策略可比, 不依赖 per-strategy 的 min-max 量纲)
- 来源归因(entry_signal_code 标记来源子策略)

后端:
- engine.py: CompositeSpec 数据模型, 两阶段引用校验(孤儿移除/嵌套禁止/asset_types 子集/≤8 上限), _run_composite_strategy 选股执行, find_dependents 删除防护, override_loader 注入保证子策略与单独跑同口径
- composite.py(新): 选股 merge_results + 回测 merge_signal_matrices 合并器(退出投影/排名融合/归因)
- backtest/strategy.py: composite 回测分支(特征计划合并/逐子信号/统一风控/basic_filter/归因)
- api/strategy.py: POST /composite/save 端点, _strategy_detail 返回 composite_children(含 name/source), 删除依赖 409 防护
- monitor.py: 实时监控 fail-closed(回退盘后缓存)
- walkforward.py: 对 composite 显式中文报错
- worker.py: _strategy_dirs 补 composite 目录(修复回测子进程找不到 composite 的 bug)

前端:
- CompositeStrategyDialog(新): 创建/编辑弹窗(自动生成 composite_ ID, 权重归一, 类型标签, 增删子策略)
- StrategySettingsDialog: composite 设置面板(子策略增删改/归一/类型标签)
- StrategyBacktest: 回测页 composite 适配(分组/参数区/结果区展示子策略构成)
- api.ts: 类型扩展(source/backend 加 composite, composite_children 含 name/source)

测试: 36 个 composite 专项测试(加载/选股/回测退出投影/排名/归因/override 透传/API/删除防护), 端到端验证真实内置策略回测通过
2026-08-02 10:56:03 +08:00
wshy 8ead30037a Merge pull request #153 from shy3130/chore/bump-version-0.1.88
chore: 版本号升至 0.1.88
2026-07-31 20:03:47 +08:00
shy3130 e803aa374d chore: 版本号升至 0.1.88
统一升级 4 处版本号至 0.1.88:
- VERSION / backend/app/__init__.py / frontend/package.json: 0.1.87 → 0.1.88
- backend/pyproject.toml: 0.1.83 → 0.1.88 (原已滞后 4 个版本, 一并追上)

本版本包含:
- feat(search): 拼音首字母搜索 + 创业/科创/北交所徽标 (#151)
- fix(security): ext_columns DuckDB SQL 注入修复 (#152, closes #150)
2026-07-31 20:03:43 +08:00
wshy 2d375942db Merge pull request #152 from shy3130/fix/ext-sql-injection-150
fix(security): 修复 ext_columns DuckDB SQL 注入 (#150)
2026-07-31 19:56:52 +08:00
shy3130 a4e580e314 fix(security): 修复 ext_columns DuckDB SQL 注入 (closes #150)
Issue #150 报告了 ext_columns 功能的 DuckDB SQL 注入, 经核查属实:
field_name 经裸双引号拼进 SQL, 攻击者可借 COPY TO 写文件 (RCE) 或
UNION 读数据。已修复, 详见 PR。

根因: 3 个 SQL sink 用未转义的 f"{field_name}", 仅 screener:147 一处
用 _quote_ident 转义; 且 parser 校验不一致 (screener 校验 config_id,
kline/watchlist 零校验)。

修复方案:
1. 新增 backend/app/db_safe.py 集中定义 quote_ident (双引号转义, 对任意
   字符安全) + is_valid_ext_ident (config_id 白名单), 消除不一致根因
2. 3 个 sink 统一改用 quote_ident:
   - screener.py:785 (limit_ladder)
   - kline.py:376 (_attach_ext, GET /api/kline/daily)
   - watchlist.py:279 (watchlist_enriched)
3. kline + watchlist parser 加 config_id 白名单 (screener 已有)
4. screener 复用共享原语, 删除私有 _quote_ident/_EXT_IDENT_RE

关键约束:
- field_name 不能加白名单: FieldDef.name 无校验 + infer_fields_from_df
  直接采用原始 CSV/Parquet 列名, 合法可含中文/点。故只在 sink 转义。
- 不关闭 enable_external_access: 实测会同时禁用 read_parquet (项目核心
  数据访问方式), 不可行。

对 Issue #150 报告的澄清:
- sink #2/#3/#4 (field_name 注入) 属实, 已修
- sink #1 (screener.py:343 conditions[]/order_by) 不存在, 为误报
  (screener.py 无 conditions/order_by/execute 调用)

验证: 后端全量 527 passed (含新增 24 个安全测试, 含 2 个端到端注入
测试: COPY TO 不产生文件 / UNION 不泄漏数据 + 合法特殊字段名回归)
2026-07-31 19:56:33 +08:00
wshy a975e93ecd Merge pull request #151 from shy3130/feat/pinyin-search-and-board-badge
feat(search): 标的搜索支持拼音首字母 + 创业/科创/北交所徽标
2026-07-31 19:39:39 +08:00
shy3130 192f6c4aa9 feat(search): 标的搜索支持拼音首字母 + 创业/科创/北交所徽标
## 1. 拼音首字母搜索 (同花顺式)

后端 search_instruments 新增拼音匹配层, 输入 payh 可命中「平安银行」。
- 辅助函数 _name_pinyin_keys 用 lru_cache 缓存「名称→首字母串」, 命中后
  近似 dict 查找, 全市场遍历 < 1ms
- 多音字用 heteronym 笛卡尔积展开, 「重庆」同时匹配 cq/zq 两种读音;
  并加载 A 股高频地名词典 (重庆/长安/长春/长沙/长城/长江)
- 拼音分支仅在纯 ASCII 字母输入时触发, 中文/数字搜索零开销跳过,
  完全向后兼容
- 搜索分层: ① code/symbol 前缀 → ② 拼音首字母前缀 → ③ 包含匹配

新增依赖: pypinyin>=0.50 (纯 Python, 无 C 扩展)
新增测试: tests/test_instrument_search.py (15 用例覆盖拼音/多音字/兼容/边界)

## 2. 搜索结果显示板块徽标

自选/财务搜索/监控规则/回测选标的 四个搜索入口的结果项, 现在会显示
创业板(橙「创」)/科创板(青「科」)/北交所(紫「北」)彩色徽标。
- 复用项目既有的 boardTag (@/components/stock-table/primitives),
  与自选/策略/Dashboard 表格徽标样式完全统一
- 沪深主板不显示徽标 (信息量低, 保持简洁)

## 验证
- 后端全量测试 503 passed (含新增 15)
- 前端 tsc --noEmit 零错误
2026-07-31 19:38:36 +08:00
wshy 84bc6cb875 Merge pull request #145 from intfoo/feat/index-support
自选/监控/个股分析支持指数(asset_type="index")
2026-07-31 19:19:17 +08:00
wshy b59be65107 Merge pull request #143 from CJ0Hn/feat/watchlist-screenshot-import
fix: 自选截图导入优化
2026-07-31 19:11:12 +08:00
wshy 89bb60bdaf Merge pull request #133 from dunmin1980-ux/cursor/tickflow-pro-rate-limit-p0
TickFlow Pro: process-local 80% RPM safety + Phase 1 probe scaffold
2026-07-31 19:08:11 +08:00
wshy ceb53735b5 Merge pull request #134 from CJ0Hn/fix/numba-parallel-serialize
fix: 串行化 Numba parallel 内核,避免策略页并发崩溃
2026-07-31 19:08:07 +08:00
wshy 16077bb13e Merge pull request #148 from im47cn/fix/test-time-bomb-live-enriched
fix(test): 修复 test_live_enriched_metadata 硬编码日期导致的 time-bomb 失败
2026-07-31 19:04:57 +08:00
shy3130 f8fca96f42 修复停复牌股票实时涨跌停漏算 2026-07-30 13:09:07 +08:00
shy3130 4b6e94e020 修复回测风控参数恢复旧缓存的问题 2026-07-29 21:27:02 +08:00
intfoo 865e75fc8b fix(index): 修复 PR #46 四个阻断项
阻断项1: 前端 TypeScript 类型扩展
- MonitorRule.asset_type 加 'index' (api.ts:517)
- screenerStrategies 参数加 'index' (api.ts:1412)
- klineMinute 响应 asset_type 去重 (api.ts:1296)

阻断项2: 指数监控独立评估
- _evaluate_monitors 股票早期 return 降级为 stock_ready 标志
  仅跳过股票轮, ETF/指数轮独立判断数据新鲜度
- 纯指数行情/自选场景下指数规则可正常触发

阻断项3: 核心指数模式不截断分区
- _process_full_market_records 按 index_mode 条件分支:
  mode=all (完整 CN_Index) → flush 覆盖; mode=core (部分标的) → merge 不截断
- merge_live_enriched_asset 对 index 正确更新 _index_enriched_cache

阻断项4: Free 档额度分批
- _fetch_watchlist_quotes 用 resolve_limit + chunked 按 capability batch 上限分批
- 失败批次跳过不整轮退出, 已有股票实时刷新不受影响
- 复用进程级共享限速器 sleep_between_batches

测试: +7 测试覆盖 4 个阻断项核心场景
2026-07-28 21:13:10 +08:00
shy3130 6e4d6b9784 docs: 完善项目贡献与复审指南 2026-07-28 18:55:05 +08:00
shy3130 b29efebe68 docs: 新增项目完整操作说明书 2026-07-28 13:34:03 +08:00
im47cn 5f1c1cf0bb fix(test): replace hardcoded dates with cn_today() in test_live_enriched_metadata
test_history_strategy_monitor_keeps_live_row_with_exclude_st_enabled used
date(2026,7,20) as the "today" value, but MonitorRuleEngine.evaluate()
calls cn_today() internally. The date mismatch caused the basic_filter
+ history filter to produce 0 rows, making the test fail 8 days after
it was written.

Also fixes test_live_enriched_cache_keeps_instrument_metadata_without_persisting_it
which used the same hardcoded date — would break on any future run.

Replace all hardcoded dates with cn_today() / cn_today()-timedelta(days=3)
so the tests are timeless.
2026-07-28 09:46:51 +08:00
shy3130 d29ceed73d Merge branch 'feat/strategy-monitor-events' 2026-07-26 21:56:22 +08:00
intfoo 76202e0937 fix(index): 前端指数分钟K降级与文案资产中立化
- StockIntradayChart 指数不显示「获取分钟K/重新获取」按钮, 改静态提示
  (指数分钟K仅实时读取, 后端 sync_minute_single 显式拒绝落库)
- api.ts klineMinute 响应类型加 asset_type 可选字段
- RuleEditor/Monitor 文案: 默认规则名/徽标/placeholder/报错/空状态
  "个股信号(监控)→信号(监控)" "指定股票→指定标的" "股票→标的"
2026-07-26 19:59:30 +08:00
intfoo 3e6f9bcfb7 fix(index): 后端分钟K隔离加固与规则资产类型纠正
- kline.sync_minute_single 对指数 symbol 显式 400 (防污染 kline_minute)
- kline.sync_minute 全市场 universe 剔除指数 symbol
- kline.get_minute 响应新增 asset_type 字段 (3 处 return)
- monitor_rules._reconcile_index_asset_type 纠正误存为 stock 的指数规则
  (应用于 save_rule/list_rules/_sync_engine, 混合池不动)
- 文案资产中立化: "个股信号→信号" "指定股票→指定标的" (options label + 校验报错)
- 测试: reconcile 5 断言 + sync_minute_single 拒指数 400 + 分时报错断言同步
2026-07-26 19:59:10 +08:00
intfoo 4d069cc10f feat: 指数(asset_type=index)前端接入 — 自选/监控规则/分析页
- 自选: 搜索含指数+徽标; 板块筛选豁免非股票行; 分时列指数降级
- 监控: RuleEditor 指数资产选项 (仅 signal/price, 隐藏涨停/分时信号); 规则列表指数徽标
- 分析: StockFinancialSearch assetTypes prop; StockAnalysis 搜索开放指数
2026-07-26 18:35:54 +08:00
intfoo ed4355e0ea feat: 指数(asset_type=index)后端接入 — 数据路由/自选enriched/监控指数轮/隔离防污染
- 数据路由: get_name_map 合并指数维表; get_enriched_latest_asset("index") 缓存+flush/merge 分支; daily-batch 按资产分组
- 自选: watchlist_enriched 指数分支 + 行级 asset_type 标注
- 监控: MonitorRuleEngine 第三轮指数评估 (signal/price); 指数实时焐热复刻 ETF flush; Free档自选实时资产分流; 规则校验 (禁 strategy/market/ladder/分时信号)
- 隔离: _resolve_universe 过滤指数防污染股票日K/分钟K; 指数轮 reset_strategy_results=False; 策略/回测/screener 零改动
- AI 分析: prompt 指数无财务文案
2026-07-26 18:35:31 +08:00
shy3130 b43b177899 feat(monitor): add strategy signal event controls 2026-07-26 16:08:42 +08:00
CJohn 3e150ff600 feat(ocr): 截图导入支持多选并串行识别合并
- 文件选择与拖拽支持一次选多张截图,前端按队列逐张调用
  import-image,同一时刻只跑一路 OCR,避免加重小内存机器峰值
- 多张识别结果按股票代码合并去重,优先保留已匹配项,已在自选标记取并集
- 展示多图缩略预览与「识别中 x/y」进度;一次最多 10 张
- request 增加 quiet 选项,队列内失败不逐条弹 toast,结束后统一提示
2026-07-26 12:51:55 +08:00
CJohn e526d25fd0 fix(ocr): 完善截图导入的安全限制与交互状态
- 在 Pillow 完整解码前检查图片像素数,并将 DecompressionBombError
  转为明确的参数错误,避免压缩大图在校验前占用过多内存
- 为 OCR 线程任务设置独立的 AnyIO CapacityLimiter(2),最多同时执行
  两次图片解码与 Tesseract 识别,其余请求排队等待
- 前端调用 ocr-status 检查 Tesseract 是否可用;不可用时禁用截图导入
  入口,并按 Windows、macOS 和 Linux 显示对应安装说明
- 关闭弹窗或重新选择图片时取消旧请求,并通过请求代次校验忽略迟到
  的异步结果,防止旧候选回写到新弹窗
- 禁用已存在于自选列表中的候选项,批量添加接口返回实际净新增数量,
  成功提示使用后端返回值
- 补充图片类型与大小校验、解压炸弹、OCR 状态、并发限制以及批量添加
  数量等测试
2026-07-26 12:19:55 +08:00
CJohn 33921fcc51 fix: 串行化 Numba parallel 内核,避免策略页并发崩溃
并发 run_all 会触发 workqueue Concurrent access,导致后端进程中断。
为 matrix parallel 内核加进程锁,前端对 run_all 做 pending 去重。
2026-07-26 11:56:10 +08:00
shy3130 6f1c4032bb feat(backtest): toggle auxiliary nav series 2026-07-26 00:31:38 +08:00
shy3130 6d7092089c fix(data-source): harden custom source testing 2026-07-25 22:51:27 +08:00
shy3130 96fcbe4fff fix(data-source): validate custom request settings 2026-07-25 22:13:38 +08:00
wshy fffd89fce0 Merge pull request #138 from intfoo/feat/custom-source-timeout-param-ui
自定义数据源超时与请求参数名支持前端配置
2026-07-25 22:01:11 +08:00
wshy ae6cf3bee4 Merge pull request #140 from intfoo/fix/index-quotes-change-pct-polling
fix(index-quotes): compute change_pct for custom data source
2026-07-25 16:59:11 +08:00
wshy dd33821acc Merge pull request #141 from HelloByeAll/agent/backtest-position-curve
feat: 回测净值图叠加仓位曲线
2026-07-25 16:52:03 +08:00
HelloByeAll 852cc2f319 新增: 在回测净值图叠加仓位曲线 2026-07-24 21:12:26 +08:00
intfoo 99b0c6cb35 fix(index-quotes): compute change_pct for custom data source
Custom data source realtime quotes were missing change_pct because _build_index_quotes only kept pre-existing columns. TickFlow path computes it in _fetch_full_market_quotes, but custom source path bypasses that computation.

- _build_index_quotes computes change_pct/change_amount from last_price/prev_close when not provided by the source
- guards prev_close=0 (Polars produces inf, invalid JSON)
- aligns with TickFlow path and _fallback_index_quotes_from_daily
2026-07-24 11:35:19 +08:00
intfoo a15d0468cc feat(data-source): expose custom source timeout & request param names in UI
- backend: pass timeout through DatasetConfigIn / _config_to_dict / _sanitize_dataset
  (previously a hand-set YAML timeout was silently wiped on UI save, resetting to 30s)
- frontend: add per-dataset timeout input; collapsible 请求参数字段映射 with
  symbols/start/end_param (non-realtime) + asset_type/freq_param (minute);
  rename 字段映射 -> 响应参数字段映射; chevron at title end; realtime empty-state hint
- test: timeout config round-trip (custom value persists, default 30 not emitted)
- docs: document timeout in custom-data-source.md
2026-07-23 16:22:18 +08:00
shy3130 60fe9e6fa6 修复回测指标数据缺失提示问题 2026-07-22 13:30:02 +08:00
shy3130 a12e49d66d 修复实时行情下策略图表闪烁问题 2026-07-22 11:42:57 +08:00
shy3130 2d9fe4a4af 修复策略文件无法删除问题 2026-07-22 11:21:13 +08:00
shy3130 2c14fde788 完善个股点位提醒并发布0.1.87 2026-07-21 22:14:07 +08:00
shy3130 b4dae4bca1 修复股票与ETF切换误清策略池 2026-07-21 21:39:05 +08:00
shy3130 0ac6d6f56c 修复分析报告复制按钮兼容性 2026-07-21 20:50:34 +08:00
shy3130 0cb0b38437 修复看板监控通知个股弹窗 2026-07-20 17:10:15 +08:00
shy3130 c8c1a01d55 更新交流群二维码 2026-07-20 13:56:04 +08:00
shy3130 72918fe602 优化策略卡片结果加载性能 2026-07-20 13:01:03 +08:00
shy3130 0635698a08 修复策略监控开启后结果归零 2026-07-20 11:12:19 +08:00
shy3130 e1dbd1cafb 修复监控中心涨跌停信号误报 2026-07-20 10:33:06 +08:00
shy3130 ed41f7b950 修复:个股详情量比开关显示异常 2026-07-20 09:59:14 +08:00