diff --git a/cmd/main/main.go b/cmd/main/main.go index 224e7be..f505697 100644 --- a/cmd/main/main.go +++ b/cmd/main/main.go @@ -31,6 +31,7 @@ func main() { app.Use(gin.Recovery()) app.GET("/", restful.Ping) app.GET("/start/strategy", restful.Starter) + app.GET("/recommend", restful.Recommend) // 启动HTTP服务器 err := app.Run(fmt.Sprintf(":%s", config.Spec.Port)) diff --git a/cmd/top/main.go b/cmd/top/main.go deleted file mode 100644 index d389abd..0000000 --- a/cmd/top/main.go +++ /dev/null @@ -1,63 +0,0 @@ -package main - -import ( - "fmt" - - "git.apinb.com/quant/gostock/internal/config" - "git.apinb.com/quant/gostock/internal/impl" - "git.apinb.com/quant/gostock/internal/logic/strategy" -) - -var ( - ServiceKey = "gostock" -) - -func main() { - config.New(ServiceKey) - impl.NewImpl() - - fmt.Println("") - ymd := lastYmd() - strategy.TotalScore(ymd) - //run(lastYmd()) - fmt.Println("") -} - -func lastYmd() int { - var ymd int - sql := "select ymd from strat_model sm group by ymd order by ymd desc limit 1" - impl.DBService.Raw(sql).Scan(&ymd) - return ymd -} - -func run(ymd int) { - // tw := table.NewWriter() - // tw.SetStyle(table.StyleLight) - // tw.AppendHeader(table.Row{"ID", "Code", "Name", "OpenDate", "OpenPrice", "TodayPrice", "PNL/Per", "PNLRate(%)"}) - // var data []models.StratModel - // impl.DBService.Where("status=?", 0).Find(&data) - // var tPNL, tPNLR, cost, sell float64 - // for _, item := range data { - // var stock models.StockBasic - // impl.DBService.Where("ts_code=?", item.Code).First(&stock) - - // var daily models.StockDaily - // impl.DBService.Model(&models.StockDaily{}).Where("ts_code=?", item.Code).Order("id desc").Limit(1).First(&daily) - - // high := utils.FloatRound(daily.High*0.995, 2) - // pnl := utils.FloatRound(high-item.OpenPrice, 2) - // pnlRate := utils.FloatRound(pnl/item.OpenPrice*100, 2) - - // tPNL = tPNL + pnl - // cost = cost + item.OpenPrice - // sell = sell + high - - // tw.AppendRow(table.Row{item.ID, item.Code, stock.Name, item.CreatedAt.Format("2006-01-02"), item.OpenPrice, high, pnl, pnlRate}) - // } - - // tPNLR = utils.FloatRound(((sell-cost)/cost)*100, 2) - - // tw.AppendFooter(table.Row{"", "", "", "TOTAL", utils.FloatRound(cost, 2), utils.FloatRound(sell, 2), utils.FloatRound(tPNL, 2), tPNLR}) - - // fmt.Println(tw.Render()) -} diff --git a/cmd/total/main.go b/cmd/total/main.go new file mode 100644 index 0000000..3c8d12e --- /dev/null +++ b/cmd/total/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "git.apinb.com/quant/gostock/internal/config" + "git.apinb.com/quant/gostock/internal/impl" + "git.apinb.com/quant/gostock/internal/logic/strategy" +) + +var ( + ServiceKey = "gostock" +) + +func main() { + config.New(ServiceKey) + impl.NewImpl() + + ymd := lastYmd() + strategy.TotalScore(ymd) +} + +func lastYmd() int { + var ymd int + sql := "select ymd from strat_model sm group by ymd order by ymd desc limit 1" + impl.DBService.Raw(sql).Scan(&ymd) + return ymd +} diff --git a/internal/logic/restful/recommend.go b/internal/logic/restful/recommend.go new file mode 100644 index 0000000..fc52e29 --- /dev/null +++ b/internal/logic/restful/recommend.go @@ -0,0 +1,23 @@ +package restful + +import ( + "git.apinb.com/quant/gostock/internal/impl" + "git.apinb.com/quant/gostock/internal/logic/strategy" + "git.apinb.com/quant/gostock/internal/models" + "github.com/gin-gonic/gin" +) + +func Recommend(ctx *gin.Context) { + ymd := lastYmd() + strategy.TotalScore(ymd) + var stocks []string + impl.DBService.Model(&models.StratModel{}).Where("total_score>?", 0).Pluck("code", &stocks) + ctx.JSON(200, stocks) + return +} +func lastYmd() int { + var ymd int + sql := "select ymd from strat_model sm group by ymd order by ymd desc limit 1" + impl.DBService.Raw(sql).Scan(&ymd) + return ymd +} diff --git a/internal/logic/restful/starter.go b/internal/logic/restful/starter.go index 67796ae..e561073 100644 --- a/internal/logic/restful/starter.go +++ b/internal/logic/restful/starter.go @@ -35,8 +35,9 @@ func Starter(ctx *gin.Context) { stratRule.RunRsi(code) // 满足以上规则在让Deepseek分析 - if model.UpDateDay > 180 && 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.GtRoe > 0 && model.ScoreRsi > 0 { model.AiScore = 0 // 待分析 + model.TotalScore = float64(model.IndustryScore + model.StScore + model.GtPrice + model.GtAmount + model.GtRoe + model.ScoreRsi) model.RecommendDesc = "Rule规则" } else { model.AiScore = -2 diff --git a/internal/logic/strategy/rule/roe.go b/internal/logic/strategy/rule/roe.go index e31e793..53f28e7 100644 --- a/internal/logic/strategy/rule/roe.go +++ b/internal/logic/strategy/rule/roe.go @@ -10,7 +10,7 @@ import ( ) var ( - MinRoe float64 = 0 + MinRoe float64 = 5 ) func (r *RuleFactory) RunRoe(code string) { diff --git a/internal/logic/strategy/rule/rsi.go b/internal/logic/strategy/rule/rsi.go index f11a0eb..5d7899e 100644 --- a/internal/logic/strategy/rule/rsi.go +++ b/internal/logic/strategy/rule/rsi.go @@ -11,7 +11,7 @@ import ( ) var ( - offset = 0 // 偏移量 + offset = 1 // 偏移量 ) type StockArgConf struct { diff --git a/internal/logic/strategy/total.go b/internal/logic/strategy/total.go index 1b584a4..fafc151 100644 --- a/internal/logic/strategy/total.go +++ b/internal/logic/strategy/total.go @@ -5,14 +5,12 @@ import ( "git.apinb.com/bsm-sdk/core/utils" "git.apinb.com/quant/gostock/internal/impl" - "git.apinb.com/quant/gostock/internal/models" ) func TotalScore(ymd int) { log.Println("Total Score", ymd) - impl.DBService.Model(&models.StratModel{}).Where("ymd=?", ymd).Update("total_score", 0) - where := "where up_date_day>180 and st_score>0 and gt_amount>0 and gt_price>0 and gt_roe>0 and score_rsi>0 and ai_score>=5 and ymd=" + utils.Int2String(ymd) - sql := "update strat_model set total_score=industry_score+val_roe+ai_score " + where + where := " where up_date_day>360 and ymd=" + utils.Int2String(ymd) + sql := "update strat_model set total_score=industry_score+st_score+gt_amount+gt_price+gt_roe+score_rsi" + where log.Println("SQL:", sql) err := impl.DBService.Exec(sql).Error diff --git a/internal/models/strat_model.go b/internal/models/strat_model.go index e2a96d3..a168de4 100644 --- a/internal/models/strat_model.go +++ b/internal/models/strat_model.go @@ -44,7 +44,7 @@ type StratModel struct { AiRisk string TotalDesc string - TotalScore float64 + TotalScore float64 `gorm:"default:0"` } func init() {