Files
easy-tdx/web-ui/src/market.ts
T
Justin Gu ecd8af1676 feat(web-ui): 取行情整合 + 市场智能识别 + 一键寻优全策略
- 取消单标的/寻优页独立的「取行情」按钮,整合进「开始回测/开始寻测」
  (SymbolPicker 经 defineExpose 暴露 loadBars,父组件串联取数+回测)
- 取消市场手动选择(沪/深/北交所下拉),改为 market.ts 按代码段智能
  识别(17 边界用例验证),代码框旁显示识别结果
- 成交价下拉精简为中文「开盘价/收盘价」,初始资金默认 100 万
- 寻优页 ParamGridPicker 切换策略自动填入预设参数网格
- 寻优页新增「一键寻优所有策略」按钮 + 全局策略排名表
  (OptimizeView 复用 store.runOptimizeAll,结果区含最佳/排名/合计网格点)
- types/api/store 新增 OptimizeAll 契约 + submitOptimizeAllTask
- vue-tsc + vite build 通过
2026-07-04 00:09:05 +08:00

51 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// A股代码 → 市场智能识别。
// 用户只输入 6 位代码,按代码段规则自动匹配 沪市(SH)/深市(SZ)/北交所(BJ)
// 拼成后端要求的 "市场:代码" 格式(如 SZ:000001)。
export type Market = 'SH' | 'SZ' | 'BJ'
/**
* 根据 6 位股票代码智能判断所属市场。
*
* 规则(按优先级,先匹配到的为准):
* - 北交所(BJ)43/83/87/92/93/920(小盘/三板)或 4xx/8xx 开头
* - 沪市(SH) 6/9 开头(主板 60/68 科创、B 股 900)或 5 开头(基金 50/51/56/58
* - 其余归深市(SZ)000/001/002/003/300/301 创业板、200 B股 等
*
* @param code 6 位股票代码(纯数字)
* @returns 市场代码 SH/SZ/BJ;无法判断时默认深市(覆盖面最广)
*/
export function detectMarket(code: string): Market {
const c = code.trim()
if (!/^\d{6}$/.test(c)) return 'SZ'
// 北交所:43/83/87/92(含920段)/93 + 4xx/8xx(三板/小盘)
if (/^(43|83|87|92|93|4|8)/.test(c)) return 'BJ'
// 沪市:6xx(主板/科创板 60/68)、9xxB股)、5xx(沪市基金 50/51/56/58/50ETF 等)
if (/^[695]/.test(c)) return 'SH'
// 其余归深市:000/001/002/003/300/301/200 等
return 'SZ'
}
/**
* 把 6 位代码转成后端要求的 "市场:代码" 格式。
* @param code 6 位股票代码
*/
export function toSymbol(code: string): string {
return `${detectMarket(code)}:${code.trim()}`
}
/** 市场中文显示名。 */
export function marketLabel(market: Market): string {
switch (market) {
case 'SH':
return '沪市'
case 'BJ':
return '北交所'
default:
return '深市'
}
}