Files
gostock/cmd/cli/main.go

90 lines
1.9 KiB
Go
Raw Normal View History

2026-01-27 00:25:34 +08:00
package main
2026-01-27 02:09:44 +08:00
import (
"log"
2026-01-28 23:27:21 +08:00
"os"
2026-01-27 02:09:44 +08:00
"git.apinb.com/quant/gostock/internal/config"
"git.apinb.com/quant/gostock/internal/impl"
"git.apinb.com/quant/gostock/internal/logic/strategy"
2026-01-31 18:22:58 +08:00
"git.apinb.com/quant/gostock/internal/logic/strategy/rule"
2026-01-30 20:03:50 +08:00
"git.apinb.com/quant/gostock/internal/logic/types"
2026-01-31 18:22:58 +08:00
"git.apinb.com/quant/gostock/internal/models"
2026-01-28 23:27:21 +08:00
"github.com/gocarina/gocsv"
2026-01-27 02:09:44 +08:00
)
2026-01-27 00:25:34 +08:00
var (
2026-01-27 02:09:44 +08:00
ServiceKey = "gostock"
2026-01-27 00:25:34 +08:00
)
2026-01-31 18:22:58 +08:00
func main() {
2026-01-27 00:25:34 +08:00
log.Println("Hello Cli!")
2026-01-27 02:09:44 +08:00
config.New(ServiceKey)
impl.NewImpl()
2026-01-27 02:34:26 +08:00
2026-02-02 19:04:32 +08:00
code := "601899.SH"
model := models.NewStratModel("selector", code)
stratRule := rule.NewRule(model)
stratRule.RunAi(code)
}
func main2() {
log.Println("Hello Cli!")
config.New(ServiceKey)
impl.NewImpl()
2026-02-01 03:44:51 +08:00
for _, code := range strategy.GetStocks() {
strategy.InitCacheByCode(code)
model := models.NewStratModel("selector", code)
stratRule := rule.NewRule(model)
2026-02-01 14:57:20 +08:00
{
stratRule.RunUpDate(strategy.Cache[code].Basic.ListDate)
stratRule.RunST(strategy.Cache[code].Basic.Name)
stratRule.RunIndustry(strategy.Cache[code].Basic.Industry)
stratRule.RunPrice(code)
stratRule.RunAmount(code)
stratRule.RunRoe(code)
2026-02-01 14:59:45 +08:00
stratRule.RunRsi(code)
2026-02-01 14:57:20 +08:00
}
2026-01-31 18:22:58 +08:00
2026-02-01 03:44:51 +08:00
model.Save()
}
2026-01-30 19:48:18 +08:00
}
2026-02-02 19:04:32 +08:00
func main3() {
2026-01-30 19:48:18 +08:00
log.Println("Hello Cli!")
config.New(ServiceKey)
impl.NewImpl()
2026-01-30 20:03:50 +08:00
data_ok := []*types.ResultData{}
data_not := []*types.ResultData{}
2026-01-28 02:18:48 +08:00
for _, code := range strategy.GetStocks() {
2026-01-28 21:55:50 +08:00
basic := strategy.GetBasic(code)
2026-01-30 20:03:50 +08:00
if ok, data := strategy.MustFilter(basic); ok {
2026-01-29 00:35:41 +08:00
data_ok = append(data_ok, data)
2026-01-28 21:14:37 +08:00
} else {
2026-01-29 00:35:41 +08:00
data_not = append(data_not, data)
2026-01-28 02:18:48 +08:00
}
}
2026-01-28 23:27:21 +08:00
WriteResults(data_ok, "ok")
2026-01-29 00:02:23 +08:00
WriteResults(data_not, "not")
2026-01-28 02:18:48 +08:00
log.Println("Done!")
}
2026-01-27 02:34:26 +08:00
2026-01-30 20:03:50 +08:00
func WriteResults(data []*types.ResultData, tag string) {
2026-01-29 03:16:11 +08:00
rf, err := os.OpenFile("./result/stocks_"+tag+".csv", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.ModePerm)
2026-01-28 23:27:21 +08:00
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)
}
}