Files
collector/models/models.go

104 lines
6.8 KiB
Go
Raw Normal View History

2026-04-07 12:22:57 +08:00
package models
import (
"time"
"gorm.io/gorm"
)
// AssetSnapshot 资产快照数据库模型
2026-04-07 14:46:49 +08:00
type CollectorAssets struct {
2026-04-07 12:22:57 +08:00
ID uint `json:"id" gorm:"primaryKey"`
AccountID string `json:"account_id" gorm:"type:varchar(50);not null;index"`
2026-04-07 14:46:49 +08:00
Ymd int `json:"ymd" gorm:"not null;index;comment:年月日数字格式,如20260407"`
2026-04-07 12:22:57 +08:00
Cash float64 `json:"cash" gorm:"type:decimal(15,2);not null;default:0"`
FrozenCash float64 `json:"frozen_cash" gorm:"type:decimal(15,2);not null;default:0;column:frozen_cash"`
MarketValue float64 `json:"market_value" gorm:"type:decimal(15,2);not null;default:0;column:market_value"`
Profit float64 `json:"profit" gorm:"type:decimal(15,2);not null;default:0"`
TotalAsset float64 `json:"total_asset" gorm:"type:decimal(15,2);not null;default:0;column:total_asset"`
DataHash string `json:"data_hash" gorm:"type:varchar(64);not null;index"`
CollectedAt time.Time `json:"collected_at" gorm:"not null;index"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
}
// OrderRecord 订单数据库模型
2026-04-07 14:46:49 +08:00
type CollectorOrder struct {
2026-04-07 12:22:57 +08:00
ID uint `json:"id" gorm:"primaryKey"`
OrderID int64 `json:"order_id" gorm:"not null;index"`
AccountID string `json:"account_id" gorm:"type:varchar(50);not null;index"`
StockCode string `json:"stock_code" gorm:"type:varchar(20);not null;index"`
2026-04-07 14:46:49 +08:00
Ymd int `json:"ymd" gorm:"not null;index;comment:年月日数字格式,如20260407"`
2026-04-07 12:22:57 +08:00
Price float64 `json:"price" gorm:"type:decimal(10,4);not null;default:0"`
Volume int `json:"volume" gorm:"not null;default:0"`
TradedPrice float64 `json:"traded_price" gorm:"type:decimal(10,4);not null;default:0;column:traded_price"`
TradedVolume int `json:"traded_volume" gorm:"not null;default:0;column:traded_volume"`
OrderStatus int `json:"order_status" gorm:"not null;default:0;column:order_status"`
OrderTime int64 `json:"order_time" gorm:"not null;column:order_time"`
OrderRemark string `json:"order_remark" gorm:"type:text;column:order_remark"`
DataHash string `json:"data_hash" gorm:"type:varchar(64);not null"`
CollectedAt time.Time `json:"collected_at" gorm:"not null;index"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
}
// PositionRecord 持仓数据库模型
2026-04-07 14:46:49 +08:00
type CollectorPosition struct {
2026-04-07 12:22:57 +08:00
ID uint `json:"id" gorm:"primaryKey"`
AccountID string `json:"account_id" gorm:"type:varchar(50);not null;index"`
Code string `json:"code" gorm:"type:varchar(20);not null;index"`
2026-04-07 14:46:49 +08:00
Ymd int `json:"ymd" gorm:"not null;index;comment:年月日数字格式,如20260407"`
2026-04-07 12:22:57 +08:00
Volume int `json:"volume" gorm:"not null;default:0"`
CanUseVolume int `json:"can_use_volume" gorm:"not null;default:0;column:can_use_volume"`
FrozenVolume int `json:"frozen_volume" gorm:"not null;default:0;column:frozen_volume"`
AvgPrice float64 `json:"avg_price" gorm:"type:decimal(10,4);not null;default:0;column:avg_price"`
OpenPrice float64 `json:"open_price" gorm:"type:decimal(10,4);not null;default:0;column:open_price"`
CurrentPrice float64 `json:"current_price" gorm:"type:decimal(10,4);not null;default:0;column:current_price"`
MarketValue float64 `json:"market_value" gorm:"type:decimal(15,2);not null;default:0;column:market_value"`
Profit float64 `json:"profit" gorm:"type:decimal(15,2);not null;default:0"`
ProfitRate float64 `json:"profit_rate" gorm:"type:decimal(10,4);not null;default:0;column:profit_rate"`
MinProfitRate float64 `json:"min_profit_rate" gorm:"type:decimal(10,4);not null;default:0;column:min_profit_rate"`
DataHash string `json:"data_hash" gorm:"type:varchar(64);not null"`
CollectedAt time.Time `json:"collected_at" gorm:"not null;index"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
}
// TickRecord 行情数据库模型
2026-04-07 14:46:49 +08:00
type CollectorTick struct {
2026-04-07 12:22:57 +08:00
ID uint `json:"id" gorm:"primaryKey"`
StockCode string `json:"stock_code" gorm:"type:varchar(20);not null;index"`
2026-04-07 14:46:49 +08:00
Ymd int `json:"ymd" gorm:"not null;index;comment:年月日数字格式,如20260407"`
2026-04-07 12:22:57 +08:00
LastPrice float64 `json:"last_price" gorm:"type:decimal(10,4);not null;default:0;column:last_price"`
Open float64 `json:"open" gorm:"type:decimal(10,4);not null;default:0"`
High float64 `json:"high" gorm:"type:decimal(10,4);not null;default:0"`
Low float64 `json:"low" gorm:"type:decimal(10,4);not null;default:0"`
LastClose float64 `json:"last_close" gorm:"type:decimal(10,4);not null;default:0;column:last_close"`
Volume int64 `json:"volume" gorm:"not null;default:0"`
Amount float64 `json:"amount" gorm:"type:decimal(15,2);not null;default:0"`
PVolume int64 `json:"pvolume" gorm:"not null;default:0;column:pvolume"`
BidPrices []float64 `json:"bid_prices" gorm:"type:decimal(10,4)[];column:bid_prices"`
BidVolumes []int `json:"bid_volumes" gorm:"type:integer[];column:bid_volumes"`
AskPrices []float64 `json:"ask_prices" gorm:"type:decimal(10,4)[];column:ask_prices"`
AskVolumes []int `json:"ask_volumes" gorm:"type:integer[];column:ask_volumes"`
Time int64 `json:"time" gorm:"not null;index"`
TimeTag string `json:"timetag" gorm:"type:varchar(50);column:timetag"`
StockStatus int `json:"stock_status" gorm:"not null;default:0;column:stock_status"`
DataHash string `json:"data_hash" gorm:"type:varchar(64);not null"`
CollectedAt time.Time `json:"collected_at" gorm:"not null;index"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
}
// CollectionLog 采集日志数据库模型
2026-04-07 14:46:49 +08:00
type CollectorLog struct {
2026-04-07 12:22:57 +08:00
ID uint `json:"id" gorm:"primaryKey"`
DataHash string `json:"data_hash" gorm:"type:varchar(64);not null;index"`
2026-04-07 14:46:49 +08:00
Ymd int `json:"ymd" gorm:"not null;index;comment:年月日数字格式,如20260407"`
2026-04-07 12:22:57 +08:00
HasChanged bool `json:"has_changed" gorm:"not null;default:false;column:has_changed"`
StatusMessage string `json:"status_message" gorm:"type:text;column:status_message"`
CollectedAt time.Time `json:"collected_at" gorm:"not null;index"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
}