# 全局数据格式 创建人员:Codex 文件职责:记录全局公共表和公共文件型数据的字段级 schema。 书写管理规范:参考 `管理系统说明.md`、`全局规范.md`。 引用文件:`全局存储体系.md`、`/observer/天下模型沉淀/数据库索引数据.md`、`/observer/model/data/stock-data/scripts/integrate_stock_data_to_total_data.py`。 记录方式:schema 账本文档;公共表新增或字段新增时同步更新;变更记录追加在文末。 ## 1. 统一字段约定 | 字段 | 统一含义 | |---|---| | `symbol` | 股票代码,统一形如 `600000.SH`、`000001.SZ`、`920000.BJ` | | `trade_date` | 交易日,`date` | | `trade_time` | 日内分钟时间,`time` | | `calendar_date` | 自然日,`date` | | `snapshot_date` | 快照日期,`date` | | `open_price` / `high_price` / `low_price` / `close_price` | 开高低收价格 | | `volume` | 成交量 | | `amount` | 成交额 | | `run_id` | 构建或实验运行 ID | | `created_at` / `updated_at` | 记录创建 / 更新时间 | ## 2. A 股行情事实表 ### `a_share_daily_price` 默认 A 股前复权日线 K 线主表。 | 字段 | 类型 | 约束 | 含义 | |---|---|---|---| | `trade_date` | `date` | PK | 交易日 | | `symbol` | `char(9)` | PK | 股票代码 | | `open_price` | `decimal(12,4)` | not null | 开盘价 | | `high_price` | `decimal(12,4)` | not null | 最高价 | | `low_price` | `decimal(12,4)` | not null | 最低价 | | `close_price` | `decimal(12,4)` | not null | 收盘价 | | `volume` | `bigint` | nullable | 成交量 | | `amount` | `decimal(20,2)` | nullable | 成交额 | ### `a_share_minute_price` 默认 A 股分钟 K 线主表。 | 字段 | 类型 | 约束 | 含义 | |---|---|---|---| | `trade_date` | `date` | PK | 交易日 | | `trade_time` | `time` | PK | 分钟时间 | | `symbol` | `char(9)` | PK | 股票代码 | | `open_price` | `decimal(12,4)` | not null | 该分钟开盘价 | | `high_price` | `decimal(12,4)` | not null | 该分钟最高价 | | `low_price` | `decimal(12,4)` | not null | 该分钟最低价 | | `close_price` | `decimal(12,4)` | not null | 该分钟收盘价 | | `volume` | `bigint` | nullable | 该分钟成交量 | | `amount` | `decimal(20,2)` | nullable | 该分钟成交额 | | `open_interest` | `bigint` | nullable | 持仓量;部分源为空 | ### `a_share_daily_front_adj_missing_ohlc_20230101_20260508` 前复权源包中停牌 / 无 OHLC 行审计表。 | 字段 | 类型 | 约束 | 含义 | |---|---|---|---| | `trade_date` | `date` | PK | 交易日 | | `symbol` | `char(9)` | PK | 股票代码 | | `volume` | `bigint` | nullable | 源成交量 | | `amount` | `decimal(20,2)` | nullable | 源成交额 | | `pre_close` | `decimal(12,4)` | nullable | 前收价 | | `suspend_flag` | `varchar(8)` | not null | 停牌 / 无价标记 | ### `a_share_daily_price_backup_before_front_adj_20260523_1808` 前复权切换前旧日线备份。字段与 `a_share_daily_price` 相同。 ### `a_share_daily_price_front_sync` 前复权日线同步影子表。 | 字段 | 类型 | 约束 | 含义 | |---|---|---|---| | `trade_date` | `date` | PK | 交易日 | | `symbol` | `char(9)` | PK | 股票代码 | | `open_price` | `decimal(12,4)` | nullable | 开盘价 | | `high_price` | `decimal(12,4)` | nullable | 最高价 | | `low_price` | `decimal(12,4)` | nullable | 最低价 | | `close_price` | `decimal(12,4)` | nullable | 收盘价 | | `pre_close_price` | `decimal(12,4)` | nullable | 前收价 | | `volume` | `bigint unsigned` | nullable | 成交量 | | `amount` | `decimal(20,2)` | nullable | 成交额 | | `turnover` | `double` | nullable | 换手 / 源口径 turnover | | `source_batch_id` | `varchar(64)` | nullable | 源批次 | | `source_table` | `varchar(64)` | not null | 源表名,默认 `cn_stock_kline_1d_front` | | `source_updated_at` | `datetime` | nullable | 源更新时间 | | `sync_run_id` | `varchar(96)` | indexed | 同步运行 ID | | `synced_at` | `timestamp` | auto update | 同步写入时间 | ### `a_share_minute_price_front_sync` 前复权分钟线同步影子表。 | 字段 | 类型 | 约束 | 含义 | |---|---|---|---| | `trade_date` | `date` | PK | 交易日 | | `trade_time` | `time` | PK | 分钟时间 | | `bar_time` | `datetime` | indexed | 完整 bar 时间 | | `symbol` | `char(9)` | PK | 股票代码 | | `open_price` | `decimal(12,4)` | nullable | 开盘价 | | `high_price` | `decimal(12,4)` | nullable | 最高价 | | `low_price` | `decimal(12,4)` | nullable | 最低价 | | `close_price` | `decimal(12,4)` | nullable | 收盘价 | | `volume` | `bigint unsigned` | nullable | 成交量 | | `amount` | `decimal(20,2)` | nullable | 成交额 | | `turnover` | `double` | nullable | 换手 / 源口径 turnover | | `source_batch_id` | `varchar(64)` | nullable | 源批次 | | `source_table` | `varchar(64)` | not null | 源表名,默认 `cn_stock_kline_1m_front` | | `source_updated_at` | `datetime` | nullable | 源更新时间 | | `sync_run_id` | `varchar(96)` | indexed | 同步运行 ID | | `synced_at` | `timestamp` | auto update | 同步写入时间 | ### `a_share_kline_front_sync_run` K 线同步运行记录。 | 字段 | 类型 | 约束 | 含义 | |---|---|---|---| | `run_id` | `varchar(96)` | PK | 同步运行 ID | | `started_at` | `datetime` | indexed | 开始时间 | | `finished_at` | `datetime` | nullable | 结束时间 | | `status` | `varchar(64)` | indexed | 运行状态 | | `periods` | `varchar(64)` | not null | 同步周期范围 | | `start_date` | `date` | nullable | 请求开始日期 | | `end_date` | `date` | nullable | 请求结束日期 | | `symbols_scope` | `text` | nullable | 股票范围 | | `source_host` | `varchar(255)` | not null | 源主机 | | `source_database` | `varchar(128)` | not null | 源数据库 | | `local_database` | `varchar(128)` | not null | 本地数据库 | | `daily_rows_source` | `bigint` | not null | 源日线行数 | | `daily_rows_loaded` | `bigint` | not null | 落库日线行数 | | `minute_rows_source` | `bigint` | not null | 源分钟行数 | | `minute_rows_loaded` | `bigint` | not null | 落库分钟行数 | | `summary_json` | `json` | nullable | 运行摘要 | | `error_message` | `text` | nullable | 错误信息 | ## 3. A 股基础维表和元数据表 ### `a_share_trading_calendar` | 字段 | 类型 | 约束 | 含义 | |---|---|---|---| | `calendar_date` | `date` | PK | 自然日 | | `is_trading_day` | `tinyint` | not null | 是否交易日 | | `trade_date_rank` | `int` | nullable | 交易日序号 | | `weekday` | `tinyint` | not null | 星期 | | `is_weekend` | `tinyint` | not null | 是否周末 | | `market_scope` | `varchar(32)` | not null | 市场范围 | | `source` | `varchar(128)` | not null | 来源 | ### `a_share_profile_snapshot` | 字段 | 类型 | 约束 | 含义 | |---|---|---|---| | `snapshot_date` | `date` | PK | 快照日期 | | `symbol` | `char(9)` | PK | 股票代码 | | `stock_name` | `varchar(64)` | not null | 股票名称 | | `industry_l1` | `varchar(64)` | nullable | 一级行业 | | `industry_l2` | `varchar(64)` | nullable | 二级行业 | | `concepts_raw` | `text` | nullable | 概念原文 | | `main_business_raw` | `text` | nullable | 主营业务原文 | | `industry_source` | `varchar(64)` | nullable | 行业来源 | | `concept_source_url` | `varchar(255)` | nullable | 概念来源 URL | | `main_business_source_url` | `varchar(255)` | nullable | 主营来源 URL | | `status` | `varchar(16)` | not null | 采集状态 | | `error_reason` | `text` | nullable | 错误原因 | ### `a_share_true_capital_turnover` | 字段 | 类型 | 约束 | 含义 | |---|---|---|---| | `trade_date` | `date` | PK | 交易日 | | `symbol` | `char(9)` | PK | 股票代码 | | `total_shares` | `bigint` | nullable | 总股本 | | `float_shares` | `bigint` | nullable | 流通股本 | | `turnover_rate_pct` | `decimal(12,6)` | nullable | 换手率百分比 | ### `a_share_true_market_value` | 字段 | 类型 | 约束 | 含义 | |---|---|---|---| | `trade_date` | `date` | PK | 交易日 | | `symbol` | `char(9)` | PK | 股票代码 | | `total_market_cap` | `decimal(24,6)` | nullable | 总市值 | | `float_market_cap` | `decimal(24,6)` | nullable | 流通市值 | ### `stock_source_artifact` | 字段 | 类型 | 约束 | 含义 | |---|---|---|---| | `artifact_path` | `varchar(512)` | PK | 原始工件路径 | | `artifact_name` | `varchar(255)` | not null | 文件名 | | `artifact_type` | `varchar(16)` | not null | 文件类型 | | `size_bytes` | `bigint` | not null | 文件大小 | | `modified_at` | `datetime` | not null | 文件修改时间 | ### `stock_dataset_manifest` | 字段 | 类型 | 约束 | 含义 | |---|---|---|---| | `manifest_path` | `varchar(512)` | PK | manifest 路径 | | `domain_name` | `varchar(64)` | not null | 数据域 | | `batch_tag` | `varchar(64)` | nullable | 批次标签 | | `manifest_json` | `longtext` | not null | manifest JSON | | `modified_at` | `datetime` | not null | 修改时间 | ### `stock_import_chunk_log` | 字段 | 类型 | 约束 | 含义 | |---|---|---|---| | `id` | `bigint` | PK auto_increment | 日志 ID | | `table_name` | `varchar(64)` | indexed | 目标表 | | `source_group` | `varchar(64)` | not null | 源分组 | | `chunk_file` | `varchar(512)` | not null | chunk 文件 | | `row_count` | `bigint` | not null | chunk 行数 | | `loaded_at` | `datetime` | not null | 导入时间 | | `duration_ms` | `bigint` | not null | 导入耗时 | ## 4. 市场广度缓存表 ### `ts_market_breadth_daily_cache` | 字段 | 类型 | 约束 | 含义 | |---|---|---|---| | `trade_date` | `date` | PK | 交易日 | | `scope_type` | `varchar(32)` | PK | 范围类型 | | `scope_value` | `varchar(128)` | PK | 范围值 | | `industry_snapshot_date` | `date` | nullable | 行业快照日 | | `benchmark_type` | `varchar(32)` | not null | 对比基准 | | `stock_count` | `int` | not null | 股票数 | | `up_count` | `int` | not null | 上涨数 | | `flat_count` | `int` | not null | 平盘数 | | `down_count` | `int` | not null | 下跌数 | | `zero_prev_close_count` | `int` | not null | 前收为零 / 不可算数量 | | `positive_share` | `decimal(12,8)` | nullable | 上涨占比 | | `avg_ret_from_prev_close_pct` | `decimal(18,8)` | nullable | 等权涨跌幅 | | `price_source_table` | `varchar(64)` | not null | 价格源表 | | `profile_source_table` | `varchar(64)` | nullable | 画像源表 | | `profile_snapshot_pit_safe_flag` | `tinyint` | not null | 画像是否 PIT-safe | | `run_id` | `varchar(128)` | not null | 构建运行 ID | | `updated_at` | `timestamp` | auto update | 更新时间 | ### `ts_market_breadth_intraday_cache` 字段同 `ts_market_breadth_daily_cache`,额外包含: | 字段 | 类型 | 约束 | 含义 | |---|---|---|---| | `trade_time` | `time` | PK | 分钟时间 | ### `ts_market_breadth_intraday_daily_peak_cache` | 字段 | 类型 | 约束 | 含义 | |---|---|---|---| | `trade_date` | `date` | PK | 交易日 | | `scope_type` | `varchar(32)` | PK | 范围类型 | | `scope_value` | `varchar(128)` | PK | 范围值 | | `max_up_count` | `int` | not null | 日内最大上涨家数 | | `max_up_time` | `time` | not null | 最大上涨家数时间 | | `first_up_count_ge_3000_time` | `time` | nullable | 首次达到 3000 家上涨时间 | | `has_up_count_ge_3000_flag` | `tinyint` | not null | 是否达到 3000 家 | | `max_positive_share` | `decimal(12,8)` | nullable | 最大上涨占比 | | `max_avg_ret_from_prev_close_pct` | `decimal(18,8)` | nullable | 最大等权涨幅 | | `minute_row_count` | `int` | not null | 分钟行数 | | `source_table` | `varchar(64)` | not null | 来源表 | | `run_id` | `varchar(128)` | not null | 运行 ID | | `updated_at` | `timestamp` | auto update | 更新时间 | ### `ts_market_breadth_cache_run` | 字段 | 类型 | 约束 | 含义 | |---|---|---|---| | `run_id` | `varchar(128)` | PK | 运行 ID | | `run_started_at` | `datetime` | not null | 开始时间 | | `run_finished_at` | `datetime` | nullable | 结束时间 | | `cache_level` | `varchar(32)` | PK | 缓存层级 | | `start_date` | `date` | nullable | 开始日期 | | `end_date` | `date` | nullable | 结束日期 | | `requested_date_count` | `int` | not null | 请求日期数 | | `processed_date_count` | `int` | not null | 处理日期数 | | `daily_cache_rows` | `int` | not null | 日级缓存行数 | | `intraday_cache_rows` | `int` | not null | 分时缓存行数 | | `source_price_table` | `varchar(64)` | not null | 价格源表 | | `source_profile_table` | `varchar(64)` | not null | 画像源表 | | `profile_snapshot_pit_safe_flag` | `tinyint` | not null | 画像是否 PIT-safe | | `run_status` | `varchar(64)` | not null | 运行状态 | | `run_note` | `text` | nullable | 备注 | ## 5. 案例研究归档表 ### `ts_case_study_casepack` | 字段 | 类型 | 约束 | 含义 | |---|---|---|---| | `casepack_id` | `varchar(64)` | PK | 案例包 ID | | `run_id` | `varchar(128)` | indexed | 运行 ID | | `research_scope` | `varchar(128)` | not null | 研究范围 | | `research_object` | `varchar(512)` | not null | 研究对象 | | `source_note_items_json` | `json` | nullable | 来源笔记条目 | | `result_path` | `varchar(1024)` | not null | 结果目录 | | `script_path` | `varchar(1024)` | nullable | 脚本路径 | | `source_panel_path` | `varchar(1024)` | nullable | 来源面板 | | `source_panel_sha256` | `char(64)` | nullable | 来源面板 hash | | `price_source` | `varchar(512)` | nullable | 价格源 | | `case_count` | `int` | not null | 案例数 | | `readout` | `varchar(256)` | not null | 读出状态 | | `engineering_allowed_flag` | `tinyint` | not null | 是否允许工程化 | | `created_at` / `updated_at` | `datetime` | not null | 创建 / 更新时间 | ### `ts_case_study_case_header` 字段:`case_id` PK、`casepack_id`、`run_id`、`case_family`、`research_scope`、`research_object`、`symbol`、`signal_trade_date`、`entry_trade_date`、`window_start_date`、`window_end_date`、`case_type`、`case_boundary_subtype`、`selector_set_key`、`note_item_ids_json`、`source_result_path`、`source_case_table_path`、`source_window_path`、`primary_chart_path`、`primary_chart_sha256`、`price_source`、`case_status`、`engineering_allowed_flag`、`created_at`、`updated_at`。 ### `ts_case_study_kline_window` 字段:`case_id` PK、`symbol`、`trade_date` PK、`relative_day_to_signal`、`relative_day_to_entry`、`open_price`、`high_price`、`low_price`、`close_price`、`volume`、`amount`、`is_signal_flag`、`is_entry_flag`、`created_at`。 ### `ts_case_study_anchor` 字段:`anchor_id` PK、`case_id`、`anchor_type`、`anchor_date`、`relative_day_to_signal`、`relative_day_to_entry`、`open_price`、`high_price`、`low_price`、`close_price`、`anchor_metric_json`、`anchor_reason`、`source_rule_id`、`review_status`、`created_at`。 ### `ts_case_study_asset` 字段:`asset_id` PK、`casepack_id`、`case_id`、`asset_type`、`file_path`、`file_sha256`、`file_size`、`is_primary_chart`、`created_at`。 ### `ts_case_study_judgment` 字段:`case_id` PK、`judgment_version` PK、`judge_type`、`support_original_note_decision`、`ai_chart_review_bucket`、`visual_story`、`visual_position_reading`、`pre_signal_context_reading`、`hidden_condition_tags_json`、`rule_implication`、`manual_review_focus`、`confidence_level`、`human_review_status`、`created_at`。 ### `ts_case_study_tag` 字段:`case_id` PK、`tag_type` PK、`tag_value` PK、`tag_source` PK、`tag_weight`、`created_at`。 ## 6. 无忌 baseline 研究账本表 这些表只表示研究账本,不表示可投产交易系统。 | 表 | 字段摘要 | |---|---| | `ts_baseline_run` | `baseline_run_id` PK、版本、研究范围、买卖策略文本、case 数、收益、胜率、最大亏损、readout、`engineering_allowed_flag`、时间戳 | | `ts_baseline_case_decision` | `baseline_case_id` PK、`baseline_variant_id` PK、案例、代码、决策时点、市场门槛、候选池命中、位置阶段、动作决策、未来函数标记、状态、时间戳 | | `ts_baseline_entry_exit_event` | `baseline_event_id` PK、案例、variant、事件序号、事件类型、交易日、时间、价格、仓位、原因、as-of 证据、分时快照路径 | | `ts_baseline_trade_lot` | `trade_lot_id` PK、入场 / 出场事件、代码、买卖日期时间价格、持有天数、仓位、收益、最大有利 / 不利浮动、退出类型 | | `ts_baseline_case_outcome` | 案例 + variant 复合主键、结果状态、收益、胜负、回撤、最佳收益、失败 / 成功原因、未来结果摘要、复核标记 | | `ts_baseline_audit_check` | run + case + check 复合主键、期望值、实际值、是否通过、严重度、备注、创建时间 | ## 7. 无忌研究产物归档表 ### `ts_wuji_portfolio_archive_manifest` 字段:`run_id` PK、`artifact_name` PK、`csv_path`、`row_count`、`file_sha256`、`created_at`。 ### `ts_wuji_portfolio_archive_row` 字段:`run_id` PK、`artifact_name` PK、`row_key` PK、`row_hash`、`row_json`、`created_at`。 ## 8. 公共信息缓存表 ### `news_body_cache` 字段:`_row_id` PK、`url`、`fetch_status`、`status_code`、`content_type`、`body_text`、`body_length`、`body_hash`、`fetched_at`、`error`、`_dataset_version`、`_source_file`、`_imported_at`。 ### `quality_summary` 字段:`_row_id` PK、`file_name`、`status`、`row_count`、`date_min`、`date_max`、`required_fields`、`missing_fields`、`null_required`、`quality_note`、`meta`、`_dataset_version`、`_source_file`、`_imported_at`。 ## 9. 文件镜像 CSV 格式 `STOCK_TOTAL_DATA_FILE_MIRROR` 中的文件型行情使用以下源字段。 ### 日线 CSV | 字段 | 含义 | |---|---| | `timetag` | 日期或时间标签 | | `open` | 开盘价 | | `high` | 最高价 | | `low` | 最低价 | | `close` | 收盘价 | | `volumn` | 成交量;源字段拼写保留为 `volumn` | | `amount` | 成交额 | ### 分钟 CSV | 字段 | 含义 | |---|---| | `timetag` | 分钟时间标签 | | `open` | 开盘价 | | `high` | 最高价 | | `low` | 最低价 | | `close` | 收盘价 | | `volumn` | 成交量;源字段拼写保留为 `volumn` | | `amount` | 成交额 | | `open_ineterst` | 持仓量;源字段拼写保留为 `open_ineterst` | ## 10. 未冻结字段合同的表组 本机 MySQL 还存在以下表组,已扫描但未在本文冻结字段合同: | 表组 | 原因 | |---|---| | `style_*` | 既包含外部指标,也包含风格 / 风源专题研究表;需要单独拆分后再升格 | | `research_style_ju_*` | 风格局 / 局实体研究表,非全局公共事实表 | | `darkline*` / `dlroot*` / `dltest*` | 暗线专题研究表,非通用行情 / 市场指标事实表 | 如果后续要把其中某些外部指标表升格为全局公共表,必须先补字段级 schema、主键、用途、来源、PIT 边界和使用规范。 ## 11. 变更记录 - 2026-06-03:首次建立全局数据格式文档;根据本机 MySQL `information_schema`、数据库索引文档和 stock-data 脚本整理公共表字段。