This commit is contained in:
2026-02-24 16:29:28 +08:00
parent 5340b07795
commit 24fe2a97cf
8 changed files with 411 additions and 58 deletions

View File

@@ -3,9 +3,11 @@ package restful
import (
"log"
"git.apinb.com/bsm-sdk/core/utils"
"git.apinb.com/quant/gostock/internal/impl"
"git.apinb.com/quant/gostock/internal/logic/mock"
"git.apinb.com/quant/gostock/internal/logic/strategy"
"git.apinb.com/quant/gostock/internal/logic/strategy/indicator"
"git.apinb.com/quant/gostock/internal/logic/strategy/rule"
"git.apinb.com/quant/gostock/internal/models"
"github.com/gin-gonic/gin"
@@ -13,41 +15,67 @@ import (
func Starter(ctx *gin.Context) {
log.Println("Strategy START.")
ymd := models.GetYmd()
ymdQuery := ctx.DefaultQuery("ymd", "")
var ymd int
if ymdQuery != "" {
ymd = utils.String2Int(ymdQuery)
}
if ymd == 0 {
ymd = models.GetYmd()
}
for _, code := range strategy.GetStocks() {
strategy.InitCacheByCode(code)
basic := strategy.GetBasic(code)
model := models.NewStratModel("selector", code, ymd)
stratRule := rule.NewRule(model)
{
// 规则:上市时间
stratRule.RunUpDate(strategy.Cache[code].Basic.ListDate)
stratRule.RunUpDate(basic.ListDate)
// 规则是否是ST
stratRule.RunST(strategy.Cache[code].Basic.Name)
stratRule.RunST(basic.Name)
// 规则:行业,剔除夕阳和中性行业
stratRule.RunIndustry(strategy.Cache[code].Basic.Industry)
stratRule.RunIndustry(basic.Industry)
// 规则最近20天每天最低价高于5元
stratRule.RunPrice(code)
// 规则每天交易额超过10亿
stratRule.RunAmount(code)
// 规则ROE 市盈率必须为正
stratRule.RunRoe(code)
// 规则RSI指标贴近下轨并成上涨趋势
stratRule.RunRsi(code)
// 满足以上规则在让Deepseek分析
if model.UpDateDay > 360 && model.StScore > 0 && model.IndustryScore > 1 && model.GtPrice > 0 && model.GtAmount > 0 && model.GtRoe > 0 && model.ScoreRsi > 0 {
if model.UpDateDay > 360 && model.StScore > 0 && model.IndustryScore > 1 && model.GtPrice > 0 && model.GtAmount > 0 && model.RoeScore > 0 {
model.AiScore = 0 // 待分析
model.TotalScore = float64(model.IndustryScore + model.StScore + model.GtPrice + model.GtAmount + model.GtRoe + model.ScoreRsi)
model.Status = 1
model.TotalScore = float64(model.IndustryScore + model.StScore + model.GtPrice + model.GtAmount + model.RoeScore)
model.RecommendDesc = "Rule规则"
} else {
model.Status = -1
model.AiScore = -2
model.AddDesc("无需AI分析")
model.AddDesc("Rule规则不满足不加入标的")
}
}
model.Save()
}
var allowStocks []*models.StratModel
impl.DBService.Model(&models.StratModel{}).Where("status=1 and ymd=?", ymd).Find(&allowStocks)
for _, m := range allowStocks {
// CTARSI指标贴近下轨并成上涨趋势
indicator.New(m).RunRsi()
// 满足以上规则在让Deepseek分析
if m.ScoreRsi < 0 {
impl.DBService.Model(m).Where("id=?", m.ID).Updates(map[string]any{"ai_score": -2, "recommend_desc": m.RecommendDesc + "||" + "无需AI分析,RsiScore:" + utils.Int2String(m.ScoreRsi)})
}
// CTAMACD指标红绿柱及价量关系
score, desc := indicator.New(m).RunMacd()
impl.DBService.Model(m).Where("id=?", m.ID).Updates(map[string]any{"macd_score": score, "recommend_desc": m.RecommendDesc + "||" + desc})
}
// 加入资金流向特大的标的
var codes []string
impl.DBService.Model(&models.MoneyTotal{}).Where("is_greater_pervious = ? and last3_day_mf_amount>?", true, 100000).Pluck("code", &codes)