This commit is contained in:
yanweidong
2026-01-28 23:27:21 +08:00
parent 303acaccb2
commit b4a2962db2
6 changed files with 49 additions and 19 deletions

2
.gitignore vendored
View File

@@ -24,8 +24,6 @@ logs/
.vscode/ .vscode/
.builds/ .builds/
result/
results/
# Go workspace file # Go workspace file
go.work go.work

View File

@@ -2,39 +2,63 @@ package main
import ( import (
"log" "log"
"os"
"git.apinb.com/quant/gostock/internal/config" "git.apinb.com/quant/gostock/internal/config"
"git.apinb.com/quant/gostock/internal/impl" "git.apinb.com/quant/gostock/internal/impl"
"git.apinb.com/quant/gostock/internal/logic/strategy" "git.apinb.com/quant/gostock/internal/logic/strategy"
"git.apinb.com/quant/gostock/internal/logic/strategy/rule" "git.apinb.com/quant/gostock/internal/logic/strategy/rule"
"git.apinb.com/quant/gostock/internal/models" "git.apinb.com/quant/gostock/internal/models"
"github.com/gocarina/gocsv"
) )
var ( var (
ServiceKey = "gostock" ServiceKey = "gostock"
) )
type ResultData struct { // Our example struct, you can use "-" to ignore a field
Code string `csv:"code"`
Name string `csv:"name"`
Desc string `csv:"desc"`
Pass string `csv:"pass"`
}
func main() { func main() {
log.Println("Hello Cli!") log.Println("Hello Cli!")
config.New(ServiceKey) config.New(ServiceKey)
impl.NewImpl() impl.NewImpl()
var okStocks []string data_ok := []*ResultData{}
data_not := []*ResultData{}
for _, code := range strategy.GetStocks() { for _, code := range strategy.GetStocks() {
basic := strategy.GetBasic(code) basic := strategy.GetBasic(code)
if ok, desc := RuleFilter(basic); ok { if ok, desc := RuleFilter(basic); ok {
okStocks = append(okStocks, code) data_ok = append(data_ok, &ResultData{Code: code, Name: basic.Name, Desc: desc, Pass: "OK"})
log.Println(code, basic.Name, "===>", "OK!")
} else { } else {
log.Println(code, basic.Name, desc) data_not = append(data_not, &ResultData{Code: code, Name: basic.Name, Desc: desc, Pass: "NOT"})
} }
} }
log.Println("共选出", len(okStocks), "支标的!") WriteResults(data_ok, "ok")
WriteResults(data_ok, "not")
log.Println("Done!") log.Println("Done!")
} }
func WriteResults(data []*ResultData, tag string) {
rf, err := os.OpenFile("./result/stocks_"+tag+".csv", os.O_RDWR|os.O_CREATE, os.ModePerm)
if err != nil {
panic(err)
}
defer rf.Close()
err = gocsv.MarshalFile(&data, rf) // Use this to save the CSV back to the file
if err != nil {
panic(err)
}
}
func RuleFilter(basic *models.StockBasic) (bool, string) { func RuleFilter(basic *models.StockBasic) (bool, string) {
if re := rule.NewUpDate().Run(basic.ListDate); re.Score <= 0 { if re := rule.NewUpDate().Run(basic.ListDate); re.Score <= 0 {
return false, re.Desc return false, re.Desc

1
go.mod
View File

@@ -48,6 +48,7 @@ require (
github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.28.0 // indirect github.com/go-playground/validator/v10 v10.28.0 // indirect
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1
github.com/goccy/go-json v0.10.5 // indirect github.com/goccy/go-json v0.10.5 // indirect
github.com/google/uuid v1.6.0 // indirect github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect github.com/gorilla/websocket v1.5.3 // indirect

2
go.sum
View File

@@ -53,6 +53,8 @@ github.com/go-playground/validator/v10 v10.28.0 h1:Q7ibns33JjyW48gHkuFT91qX48KG0
github.com/go-playground/validator/v10 v10.28.0/go.mod h1:GoI6I1SjPBh9p7ykNE/yj3fFYbyDOpwMn5KXd+m2hUU= github.com/go-playground/validator/v10 v10.28.0/go.mod h1:GoI6I1SjPBh9p7ykNE/yj3fFYbyDOpwMn5KXd+m2hUU=
github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo= github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo=
github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU= github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU=
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1 h1:FWNFq4fM1wPfcK40yHE5UO3RUdSNPaBC+j3PokzA6OQ=
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1/go.mod h1:5YoVOkjYAQumqlV356Hj3xeYh4BdZuLE0/nRkf2NKkI=
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw= github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw=

View File

@@ -26,22 +26,26 @@ type StockArgConf struct {
} }
func NewRsi(args *models.StockArgs) *Rsi { func NewRsi(args *models.StockArgs) *Rsi {
rsi := &Rsi{
Key: "Rsi",
Name: "RSI指标",
Conf: nil,
Args: nil,
}
if args == nil {
return rsi
}
var conf StockArgConf var conf StockArgConf
err := json.Unmarshal([]byte(args.Config), &conf) err := json.Unmarshal([]byte(args.Config), &conf)
if err != nil { if err != nil {
return &Rsi{ return rsi
Key: "Rsi",
Name: "RSI指标",
Conf: nil,
Args: args,
}
}
return &Rsi{
Key: "Rsi",
Name: "RSI指标",
Conf: &conf,
Args: args,
} }
rsi.Conf = &conf
rsi.Args = args
return rsi
} }
func (r *Rsi) Run(code string) *types.RuleResult { func (r *Rsi) Run(code string) *types.RuleResult {

1
result/readme.txt Normal file
View File

@@ -0,0 +1 @@
计算结果暂存目录