Files
gostock/internal/models/strat_model.go

91 lines
1.9 KiB
Go
Raw Normal View History

2026-01-31 17:21:33 +08:00
package models
import (
2026-02-01 14:57:20 +08:00
"fmt"
2026-01-31 17:21:33 +08:00
"time"
"git.apinb.com/bsm-sdk/core/database"
"git.apinb.com/bsm-sdk/core/utils"
"git.apinb.com/quant/gostock/internal/impl"
"gorm.io/gorm"
)
// StartModel 策略模型
type StratModel struct {
gorm.Model
StratKey string
Ymd int
Code string
2026-01-31 18:22:58 +08:00
UpDateDay int //上市时间,天数
2026-01-31 17:21:33 +08:00
IndustryScore int // 行业分组
2026-01-31 18:22:58 +08:00
StScore int
2026-01-31 17:21:33 +08:00
GtAmount int // 每日交易额大于设定值
GtPrice int // 最近20日交易日价格大于设定值
GtRoe int // ROE 是否大于设定值
2026-02-01 14:57:20 +08:00
ScoreRsi int
// 值
ValRoe float64
ValRsiOversold int
ValRsiPrve float64
ValRsiLast float64
Desc []StratDesc `gorm:"foreignKey:StratModelID"`
2026-02-02 19:04:32 +08:00
//AI
AiScrore int
AiReply string
2026-01-31 17:21:33 +08:00
}
func init() {
database.AppendMigrate(&StratModel{})
}
// TableName 设置表名
func (StratModel) TableName() string {
return "strat_model"
}
func NewStratModel(key, code string) *StratModel {
obj := StratModel{
StratKey: key,
Ymd: GetYmd(),
Code: code,
}
return &obj
}
2026-01-31 18:22:58 +08:00
func (s *StratModel) AddDesc(d string) {
2026-02-01 14:57:20 +08:00
hash := utils.Md5(fmt.Sprintf("%s-%d-%s:%s", s.StratKey, s.Ymd, s.Code, d))
var cnt int64
impl.DBService.Model(&StratDesc{}).Where("hash=?", hash).Count(&cnt)
if cnt > 0 {
return
}
s.Desc = append(s.Desc, StratDesc{
Hash: hash,
Desc: d,
})
2026-01-31 18:22:58 +08:00
}
2026-01-31 17:21:33 +08:00
func (s *StratModel) Save() error {
var cnt int64
impl.DBService.Model(&StratModel{}).Where("strat_key=? and ymd=? and code=?", s.StratKey, s.Ymd, s.Code).Count(&cnt)
if cnt == 0 {
// create record.
return impl.DBService.Create(s).Error
} else {
// update record.
return impl.DBService.Model(&StratModel{}).Where("strat_key=? and ymd=? and code=?", s.StratKey, s.Ymd, s.Code).Updates(s).Error
}
return nil
}
func GetYmd() int {
ymd := time.Now().Format("20060102")
return utils.String2Int(ymd)
}