From 9b7f6ed2cff4a28b452dcfbaf6e9ecd94007dca9 Mon Sep 17 00:00:00 2001 From: yanweidong Date: Tue, 27 Jan 2026 17:21:26 +0800 Subject: [PATCH] deving --- cmd/cli/main.go | 1 + internal/logic/strategy/rule/amount.go | 46 ++++++++++++++++++++++++++ internal/logic/strategy/rule/price.go | 24 ++++++++++---- 3 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 internal/logic/strategy/rule/amount.go diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 93019b5..cdbb90c 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -27,6 +27,7 @@ func main() { rule.NewST().Run(basic.Name), rule.NewIdustry().Run(basic.Industry), rule.NewPrice().Run(basic.TsCode), + rule.NewAmount().Run(basic.TsCode), } printer.Json(result) diff --git a/internal/logic/strategy/rule/amount.go b/internal/logic/strategy/rule/amount.go new file mode 100644 index 0000000..9a532bf --- /dev/null +++ b/internal/logic/strategy/rule/amount.go @@ -0,0 +1,46 @@ +package rule + +import ( + "fmt" + + "git.apinb.com/quant/gostock/internal/impl" + "git.apinb.com/quant/gostock/internal/logic/types" + "git.apinb.com/quant/gostock/internal/models" +) + +var ( + LastAmountDay = 20 + MinAmount float64 = 100000 // 万元为单位 +) + +type Amount struct { + Key string + Name string +} + +func NewAmount() *Amount { + return &Amount{ + Key: "Amount", + Name: "成交额", + } +} + +func (r *Amount) Run(code string) *types.RuleResult { + + var data []models.StockDaily + impl.DBService.Where("ts_code = ?", code).Order("trade_date desc").Limit(LastAmountDay).Find(&data) + + check := true + for _, row := range data { + if row.Amount < MinPrice { + check = false + break + } + } + + if !check { + return &types.RuleResult{Key: r.Key, Name: r.Name, Score: -1, Desc: fmt.Sprintf("最近%d天, 有成交额低于%.2f万元", LastAmountDay, MinAmount)} + } + + return &types.RuleResult{Key: r.Key, Name: r.Name, Score: 1, Desc: fmt.Sprintf("最近%d天, 成交额均高于%.2f万元", LastAmountDay, MinAmount)} +} diff --git a/internal/logic/strategy/rule/price.go b/internal/logic/strategy/rule/price.go index b27198e..02f3e61 100644 --- a/internal/logic/strategy/rule/price.go +++ b/internal/logic/strategy/rule/price.go @@ -1,13 +1,15 @@ package rule import ( - "git.apinb.com/bsm-sdk/core/printer" + "fmt" + "git.apinb.com/quant/gostock/internal/impl" "git.apinb.com/quant/gostock/internal/logic/types" "git.apinb.com/quant/gostock/internal/models" ) var ( + LastDay = 20 MinPrice = 5.0 ) @@ -24,13 +26,21 @@ func NewPrice() *Price { } func (r *Price) Run(code string) *types.RuleResult { - var daily models.StockDaily - impl.DBService.Where("ts_code = ?", code).Order("trade_date desc").Limit(1).First(&daily) - printer.Json(daily) - if daily.Close < MinPrice { - return &types.RuleResult{Key: r.Key, Name: r.Name, Score: -1, Desc: "股价低于5元"} + var data []models.StockDaily + impl.DBService.Where("ts_code = ?", code).Order("trade_date desc").Limit(LastDay).Find(&data) + + check := true + for _, row := range data { + if row.Close < MinPrice { + check = false + break + } } - return &types.RuleResult{Key: r.Key, Name: r.Name, Score: 1, Desc: "股价高于5元"} + if !check { + return &types.RuleResult{Key: r.Key, Name: r.Name, Score: -1, Desc: fmt.Sprintf("最近%d天, 有价格低于%.2f", LastDay, MinPrice)} + } + + return &types.RuleResult{Key: r.Key, Name: r.Name, Score: 1, Desc: fmt.Sprintf("最近%d天, 价格均高于%.2f", LastDay, MinPrice)} }