39 lines
2.3 KiB
Go
39 lines
2.3 KiB
Go
package models
|
||
|
||
import (
|
||
"time"
|
||
|
||
"git.apinb.com/bsm-sdk/core/database"
|
||
"gorm.io/gorm"
|
||
)
|
||
|
||
// PositionRecord 持仓数据库模型
|
||
type CollectorPosition struct {
|
||
ID uint `json:"id" gorm:"primaryKey;comment:主键ID"`
|
||
AccountID string `json:"account_id" gorm:"type:varchar(50);not null;index;comment:账户ID"`
|
||
Code string `json:"code" gorm:"type:varchar(20);not null;index;comment:股票代码"`
|
||
Ymd int `json:"ymd" gorm:"not null;index;comment:采集日期(年月日数字格式,如20260407)"`
|
||
Volume int `json:"volume" gorm:"not null;default:0;comment:持仓数量"`
|
||
CanUseVolume int `json:"can_use_volume" gorm:"not null;default:0;column:can_use_volume;comment:可用数量"`
|
||
FrozenVolume int `json:"frozen_volume" gorm:"not null;default:0;column:frozen_volume;comment:冻结数量"`
|
||
AvgPrice float64 `json:"avg_price" gorm:"type:decimal(10,4);not null;default:0;column:avg_price;comment:持仓成本价"`
|
||
OpenPrice float64 `json:"open_price" gorm:"type:decimal(10,4);not null;default:0;column:open_price;comment:开仓价格"`
|
||
CurrentPrice float64 `json:"current_price" gorm:"type:decimal(10,4);not null;default:0;column:current_price;comment:当前价格"`
|
||
MarketValue float64 `json:"market_value" gorm:"type:decimal(15,2);not null;default:0;column:market_value;comment:持仓市值"`
|
||
Profit float64 `json:"profit" gorm:"type:decimal(15,2);not null;default:0;comment:持仓盈亏"`
|
||
ProfitRate float64 `json:"profit_rate" gorm:"type:decimal(10,4);not null;default:0;column:profit_rate;comment:盈亏比例"`
|
||
MinProfitRate float64 `json:"min_profit_rate" gorm:"type:decimal(10,4);not null;default:0;column:min_profit_rate;comment:最低盈亏比例"`
|
||
CollectedAt time.Time `json:"collected_at" gorm:"not null;index;comment:数据采集时间"`
|
||
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime;comment:记录创建时间"`
|
||
DeletedAt gorm.DeletedAt `json:"-" gorm:"index;comment:软删除时间"`
|
||
}
|
||
|
||
func init() {
|
||
database.AppendMigrate(&CollectorPosition{})
|
||
}
|
||
|
||
// TableName 设置表名
|
||
func (CollectorPosition) TableName() string {
|
||
return "collector_positions"
|
||
}
|