crypto_quant/sql/table/crypto_trade_data.sql

35 lines
1.6 KiB
SQL
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.

CREATE TABLE IF NOT EXISTS crypto_trade_data (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
symbol VARCHAR(50) NOT NULL COMMENT '交易对',
ts BIGINT NOT NULL COMMENT '交易时间戳',
date_time VARCHAR(50) NOT NULL COMMENT '交易日期时间',
tradeId VARCHAR(50) NOT NULL COMMENT '交易ID',
side VARCHAR(10) NOT NULL COMMENT '交易方向(buy:买入,sell:卖出)',
sz DECIMAL(30,8) NOT NULL COMMENT '交易数量',
px DECIMAL(20,5) NOT NULL COMMENT '交易价格',
create_time VARCHAR(50) NOT NULL COMMENT '创建时间',
UNIQUE KEY uniq_tradeId (tradeId),
INDEX idx_symbol (symbol),
INDEX idx_side (side),
INDEX idx_ts (ts),
INDEX idx_date_time (date_time),
INDEX idx_symbol_ts (symbol, ts),
INDEX idx_side_ts (side, ts)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='加密货币交易数据表';
-- 添加注释说明
-- 该表用于存储加密货币市场的实时交易数据
-- 主要功能:
-- 1. 存储每笔交易的详细信息(交易对、方向、数量、价格等)
-- 2. 记录交易时间戳和日期时间
-- 3. 为交易分析提供基础数据
-- 4. 支持按交易对、方向、时间等维度查询
-- 索引说明:
-- uniq_tradeId: 交易ID唯一索引防止重复数据
-- idx_symbol: 交易对索引,支持按交易对查询
-- idx_side: 交易方向索引,支持按买卖方向查询
-- idx_ts: 时间戳索引,支持按时间查询
-- idx_date_time: 日期时间索引,支持按日期查询
-- idx_symbol_ts: 交易对+时间戳复合索引,支持按交易对和时间范围查询
-- idx_side_ts: 交易方向+时间戳复合索引,支持按方向和时间范围查询