model

package
v0.0.0-...-ee4cec9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClassStock   = "stock"
	ClassBStock  = "bstock"
	ClassIndex   = "index"
	ClassETF     = "etf"
	ClassBlock   = "block"
	ClassUnknown = "unknown"
)
View Source
const SchemaMajor = 5

SchemaMajor 表示数据库 schema 的主版本号。 当发生破坏性变更(表重命名、字段语义变化等)时递增。 已安装的数据库 major 版本与当前代码不匹配时,工具将拒绝操作并提示用户查看文档。

View Source
const SchemaMinor = 0

SchemaMinor 表示数据库 schema 的次版本号。 当发生非破坏性变更(新增表、新增字段等)时递增。

Variables

View Source
var (
	ViewStockBFQ = DefineView(stockBFQView("v_stock_bfq", "stock"))
	ViewStockQFQ = DefineView(adjustedQFQView("v_stock_qfq", "stock", 2))
	ViewStockHFQ = DefineView(adjustedHFQView("v_stock_hfq", "stock", 2))
	ViewETFBFQ   = DefineView(stockBFQView("v_etf_bfq", "etf"))
	ViewETFQFQ   = DefineView(adjustedQFQView("v_etf_qfq", "etf", 3))
	ViewETFHFQ   = DefineView(adjustedHFQView("v_etf_hfq", "etf", 3))
)

--- 定义视图 ---

命名约定:v_<class>_<fq>,class 放前面便于 tab-complete 按归属浏览 (v_stock_<TAB> / v_etf_<TAB> 各列出 3 个)。 stock / etf 拆开维护:ETF 价格 scale=1000、ROUND 精度 3 位, stock scale=100、ROUND 精度 2 位。

View Source
var MetaTable = SchemaFromStruct(
	"_meta",
	Meta{},
	[]string{"key"},
)
View Source
var TableAdjustFactor = SchemaFromStruct(
	"raw_adjust_factor",
	Factor{},
	[]string{"symbol", "date"},
)
View Source
var TableBasicDaily = SchemaFromStruct(
	"raw_basic_daily",
	BasicDaily{},
	[]string{"symbol", "date"},
)
View Source
var TableBlockInfo = SchemaFromStruct(
	"raw_tdx_blocks_info",
	BlockInfo{},
	[]string{"block_code"},
)
View Source
var TableBlockMember = SchemaFromStruct(
	"raw_tdx_blocks_member",
	BlockMember{},
	[]string{"block_code", "stock_symbol"},
)
View Source
var TableGbbq = SchemaFromStruct(
	"raw_gbbq",
	GbbqData{},
	[]string{"symbol", "date"},
)
View Source
var TableHoliday = SchemaFromStruct(
	"raw_holidays",
	Holiday{},
	[]string{""},
)
View Source
var TableKline1Min = SchemaFromStruct(
	"raw_kline_1min",
	KlineMin{},
	[]string{"symbol", "datetime"},
)
View Source
var TableKlineDaily = SchemaFromStruct(
	"raw_kline_daily",
	KlineDay{},
	[]string{"symbol", "date"},
)
View Source
var TableSymbolClass = SchemaFromStruct(
	"raw_symbol_class",
	SymbolClass{},
	[]string{"symbol"},
)
View Source
var TableSymbolName = SchemaFromStruct(
	"raw_symbol_name",
	SymbolName{},
	[]string{"symbol"},
)

Functions

func ClassifyCode

func ClassifyCode(symbol string) string

ClassifyCode 根据 symbol (如 "sh600000") 返回所属分类。 未匹配到任何规则返回 ClassUnknown。

func PriceScale

func PriceScale(symbol string) float64

PriceScale 返回 TDX 日线/分钟线原始整数价格的换算系数。 TDX 把不同品种用不同分辨率存储:

  • 股票/指数/板块/北交所/可转债: 单位 0.01 元 (分), 返回 100
  • ETF/LOF/老封基 (class=etf): 单位 0.001 元, 返回 1000
  • 沪市 B 股 (sh900) / 深市 B 股 (sz20): 单位 0.001 元 (USD/HKD), 返回 1000

未识别的 symbol 默认按股票 (100) 处理。

func SymbolFromCode

func SymbolFromCode(code string) (string, bool)

SymbolFromCode 根据 6 位裸数字代码 (如 "600000") 反查市场前缀, 返回完整 symbol (如 "sh600000")。复用 classRules,只考虑 stock/etf 类型, 因为指数 (index) 和板块 (block) 没有公司行为数据, 也能避免 "000" 同时命中 sh 指数和 sz 股票的歧义。 多前缀匹配时取最长前缀。未匹配返回 (code, false)。

Types

type BasicDaily

type BasicDaily struct {
	Date          time.Time `col:"date" type:"date"`
	Symbol        string    `col:"symbol"`
	Close         float64   `col:"close"`
	PreClose      float64   `col:"preclose"`
	ChangePercent float64   `col:"change_pct"`
	Amplitude     float64   `col:"amplitude"`
	Turnover      float64   `col:"turnover"`
	FloatMV       float64   `col:"floatmv"`
	TotalMV       float64   `col:"totalmv"`
}

BasicDaily 是每日衍生指标(PreClose/涨跌幅/振幅/换手率/市值)。 覆盖 stock + etf 两类 symbol。

type BlockInfo

type BlockInfo struct {
	BlockType   string `col:"block_type"`
	BlockName   string `col:"block_name"`
	BlockSymbol string `col:"block_symbol"`
	BlockCode   string `col:"block_code"`
	ParentCode  string `col:"parent_code"`
	BlockLevel  int    `col:"block_level"`
}

type BlockMember

type BlockMember struct {
	StockSymbol string `col:"stock_symbol"`
	BlockCode   string `col:"block_code"`
}

type Column

type Column struct {
	Name     string
	Type     DataType
	Nullable bool
}

type DataType

type DataType int
const (
	TypeString DataType = iota
	TypeFloat64
	TypeInt64
	TypeDate     // YYYY-MM-DD
	TypeDateTime // YYYY-MM-DD HH:MM:SS
)

type Factor

type Factor struct {
	Symbol    string    `col:"symbol"`
	Date      time.Time `col:"date" type:"date"`
	HfqFactor float64   `col:"hfq_factor"`
}

type GbbqData

type GbbqData struct {
	Category int       `col:"category"`
	Symbol   string    `col:"symbol"`
	Date     time.Time `col:"date" type:"date"`
	C1       float64   `col:"c1"`
	C2       float64   `col:"c2"`
	C3       float64   `col:"c3"`
	C4       float64   `col:"c4"`
}

type Holiday

type Holiday struct {
	Date time.Time `col:"date" type:"date"`
}

type KlineDay

type KlineDay struct {
	Symbol string    `col:"symbol"`
	Open   float64   `col:"open"`
	High   float64   `col:"high"`
	Low    float64   `col:"low"`
	Close  float64   `col:"close"`
	Amount float64   `col:"amount"`
	Volume int64     `col:"volume"`
	Date   time.Time `col:"date" type:"date"`
}

type KlineMin

type KlineMin struct {
	Symbol   string    `col:"symbol"`
	Open     float64   `col:"open"`
	High     float64   `col:"high"`
	Low      float64   `col:"low"`
	Close    float64   `col:"close"`
	Amount   float64   `col:"amount"`
	Volume   int64     `col:"volume"`
	Datetime time.Time `col:"datetime" type:"datetime" `
}

type Meta

type Meta struct {
	Key   string `col:"key"`
	Value string `col:"value"`
}

type SymbolClass

type SymbolClass struct {
	Symbol string `col:"symbol"`
	Class  string `col:"class"`
}

type SymbolName

type SymbolName struct {
	Symbol string `col:"symbol"`
	Name   string `col:"name"`
	Class  string `col:"class"`
}

type TableMeta

type TableMeta struct {
	TableName  string
	Columns    []Column
	OrderByKey []string
}

func AllTables

func AllTables() []*TableMeta

AllTables 返回当前所有已注册的表结构

func SchemaFromStruct

func SchemaFromStruct(tableName string, model interface{}, orderByKey []string) *TableMeta

SchemaFromStruct 通过反射生成 TableMeta 并自动注册 返回值为指针类型 *TableMeta

type ViewDef

type ViewDef struct {
	Name       string
	DuckDB     string
	ClickHouse string
}

ViewDef 描述一个数据库视图:名字 + 每种方言的 SELECT 主体 SQL。 与 TableMeta 一样是纯数据、dialect 无关——具体取哪一栏、怎么拼 CREATE VIEW 由各 driver 自己决定(对应 driver 里的 mapType)。声明即自注册到 model registry。

func AllViews

func AllViews() []ViewDef

AllViews 返回当前所有已注册的视图定义

func DefineView

func DefineView(view ViewDef) ViewDef

DefineView 注册一个视图并原样返回,供 var 声明处持有。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL