182 lines
9.0 KiB
Go
182 lines
9.0 KiB
Go
|
|
package models
|
||
|
|
|
||
|
|
import (
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"gorm.io/gorm"
|
||
|
|
)
|
||
|
|
|
||
|
|
// Status 状态数据结构
|
||
|
|
type Status struct {
|
||
|
|
Data Data `json:"data"`
|
||
|
|
Status Config `json:"status"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// Data 数据部分
|
||
|
|
type Data struct {
|
||
|
|
Assets Assets `json:"assets"`
|
||
|
|
Orders []Order `json:"order"`
|
||
|
|
Positions []Position `json:"positions"`
|
||
|
|
TickData map[string]Tick `json:"tick_data"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// Assets 资产信息
|
||
|
|
type Assets struct {
|
||
|
|
AccountID string `json:"account_id"`
|
||
|
|
Cash float64 `json:"cash"`
|
||
|
|
FrozenCash float64 `json:"frozen_cash"`
|
||
|
|
MarketValue float64 `json:"market_value"`
|
||
|
|
Profit float64 `json:"profit"`
|
||
|
|
TotalAsset float64 `json:"total_asset"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// Order 订单信息
|
||
|
|
type Order struct {
|
||
|
|
OrderID int64 `json:"order_id"`
|
||
|
|
OrderRemark string `json:"order_remark"`
|
||
|
|
OrderStatus int `json:"order_status"`
|
||
|
|
OrderTime int64 `json:"order_time"`
|
||
|
|
Price float64 `json:"price"`
|
||
|
|
StockCode string `json:"stock_code"`
|
||
|
|
TradedPrice float64 `json:"traded_price"`
|
||
|
|
TradedVolume int `json:"traded_volume"`
|
||
|
|
Volume int `json:"volume"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// Position 持仓信息
|
||
|
|
type Position struct {
|
||
|
|
Code string `json:"code"`
|
||
|
|
Volume int `json:"volume"`
|
||
|
|
CanUseVolume int `json:"can_use_volume"`
|
||
|
|
FrozenVolume int `json:"frozen_volume"`
|
||
|
|
AvgPrice float64 `json:"avg_price"`
|
||
|
|
OpenPrice float64 `json:"open_price"`
|
||
|
|
CurrentPrice float64 `json:"current_price"`
|
||
|
|
MarketValue float64 `json:"market_value"`
|
||
|
|
Profit float64 `json:"profit"`
|
||
|
|
ProfitRate float64 `json:"profit_rate"`
|
||
|
|
MinProfitRate float64 `json:"min_profit_rate"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// Tick 行情数据
|
||
|
|
type Tick struct {
|
||
|
|
LastPrice float64 `json:"lastPrice"`
|
||
|
|
Open float64 `json:"open"`
|
||
|
|
High float64 `json:"high"`
|
||
|
|
Low float64 `json:"low"`
|
||
|
|
LastClose float64 `json:"lastClose"`
|
||
|
|
Volume int64 `json:"volume"`
|
||
|
|
Amount float64 `json:"amount"`
|
||
|
|
PVolume int64 `json:"pvolume"`
|
||
|
|
BidPrice []float64 `json:"bidPrice"`
|
||
|
|
BidVol []int `json:"bidVol"`
|
||
|
|
AskPrice []float64 `json:"askPrice"`
|
||
|
|
AskVol []int `json:"askVol"`
|
||
|
|
Time int64 `json:"time"`
|
||
|
|
TimeTag string `json:"timetag"`
|
||
|
|
StockStatus int `json:"stockStatus"`
|
||
|
|
LastSettlementPrice float64 `json:"lastSettlementPrice"`
|
||
|
|
SettlementPrice float64 `json:"settlementPrice"`
|
||
|
|
OpenInt int `json:"openInt"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// Config 配置信息
|
||
|
|
type Config struct {
|
||
|
|
ConfigKey string `json:"config_key"`
|
||
|
|
HomeName string `json:"home_name"`
|
||
|
|
ProjectRoot string `json:"project_root"`
|
||
|
|
QmtStatus string `json:"qmt_status"`
|
||
|
|
StartTime int64 `json:"start_time"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// AssetSnapshot 资产快照数据库模型
|
||
|
|
type AssetSnapshot struct {
|
||
|
|
ID uint `json:"id" gorm:"primaryKey"`
|
||
|
|
AccountID string `json:"account_id" gorm:"type:varchar(50);not null;index"`
|
||
|
|
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 订单数据库模型
|
||
|
|
type OrderRecord struct {
|
||
|
|
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"`
|
||
|
|
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 持仓数据库模型
|
||
|
|
type PositionRecord struct {
|
||
|
|
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"`
|
||
|
|
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 行情数据库模型
|
||
|
|
type TickRecord struct {
|
||
|
|
ID uint `json:"id" gorm:"primaryKey"`
|
||
|
|
StockCode string `json:"stock_code" gorm:"type:varchar(20);not null;index"`
|
||
|
|
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 采集日志数据库模型
|
||
|
|
type CollectionLog struct {
|
||
|
|
ID uint `json:"id" gorm:"primaryKey"`
|
||
|
|
DataHash string `json:"data_hash" gorm:"type:varchar(64);not null;index"`
|
||
|
|
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"`
|
||
|
|
}
|