49 lines
2.4 KiB
Go
49 lines
2.4 KiB
Go
package models
|
||
|
||
import (
|
||
"time"
|
||
|
||
"git.apinb.com/bsm-sdk/core/database"
|
||
"gorm.io/gorm"
|
||
)
|
||
|
||
// OrderBook 订单簿数据库模型 - 记录完整的买卖交易周期
|
||
type OrderBook struct {
|
||
ID uint `json:"id" gorm:"primaryKey;comment:主键ID"`
|
||
AccountID string `json:"account_id" gorm:"type:varchar(50);not null;index;comment:账户ID"`
|
||
StockCode string `json:"stock_code" gorm:"type:varchar(20);not null;index;comment:股票代码"`
|
||
Ymd int `json:"ymd" gorm:"not null;index;comment:采集日期(年月日数字格式,如20260407)"`
|
||
|
||
// 买入信息
|
||
BuyOrderID string `json:"buy_order_id" gorm:"not null;index;comment:买入订单ID"`
|
||
BuyPrice float64 `json:"buy_price" gorm:"type:decimal(10,4);not null;default:0;column:buy_price;comment:买入价格"`
|
||
BuyVolume int `json:"buy_volume" gorm:"not null;default:0;column:buy_volume;comment:买入数量"`
|
||
BuyTime int64 `json:"buy_time" gorm:"not null;column:buy_time;comment:买入时间戳"`
|
||
BuyCollectedAt time.Time `json:"buy_collected_at" gorm:"not null;column:buy_collected_at;comment:买入数据采集时间"`
|
||
|
||
// 卖出信息 (初始为空,卖出时填充)
|
||
SellOrderID *string `json:"sell_order_id" gorm:"index;comment:卖出订单ID"`
|
||
SellPrice *float64 `json:"sell_price" gorm:"type:decimal(10,4);column:sell_price;comment:卖出价格"`
|
||
SellVolume *int `json:"sell_volume" gorm:"column:sell_volume;comment:卖出数量"`
|
||
SellTime *int64 `json:"sell_time" gorm:"column:sell_time;comment:卖出时间戳"`
|
||
SellCollectedAt *time.Time `json:"sell_collected_at" gorm:"column:sell_collected_at;comment:卖出数据采集时间"`
|
||
|
||
// 交易结果
|
||
IsClosed bool `json:"is_closed" gorm:"not null;default:false;column:is_closed;comment:是否已闭合(卖出)"`
|
||
Profit *float64 `json:"profit" gorm:"type:decimal(15,2);column:profit;comment:盈亏金额"`
|
||
ProfitRate *float64 `json:"profit_rate" gorm:"type:decimal(10,4);column:profit_rate;comment:盈亏比例"`
|
||
|
||
// 系统字段
|
||
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime;comment:记录创建时间"`
|
||
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime;comment:记录更新时间"`
|
||
DeletedAt gorm.DeletedAt `json:"-" gorm:"index;comment:软删除时间"`
|
||
}
|
||
|
||
func init() {
|
||
database.AppendMigrate(&OrderBook{})
|
||
}
|
||
|
||
func (OrderBook) TableName() string {
|
||
return "order_books"
|
||
}
|