deving
This commit is contained in:
@@ -1,13 +1,26 @@
|
||||
package main
|
||||
|
||||
import "log"
|
||||
import (
|
||||
"log"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/quant/gostock/internal/config"
|
||||
"git.apinb.com/quant/gostock/internal/impl"
|
||||
"git.apinb.com/quant/gostock/internal/logic/strategy"
|
||||
"git.apinb.com/quant/gostock/internal/logic/strategy/rule"
|
||||
)
|
||||
|
||||
var (
|
||||
ServiceKey = "Restful"
|
||||
ServiceKey = "gostock"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.Println("Hello Cli!")
|
||||
config.New(ServiceKey)
|
||||
impl.NewImpl()
|
||||
data := strategy.GetData("000012.SZ")
|
||||
result := rule.NewIdustry().Run(data.Basic.Industry)
|
||||
printer.Json(result)
|
||||
|
||||
log.Println("Done!")
|
||||
}
|
||||
|
||||
27
internal/logic/strategy/data.go
Normal file
27
internal/logic/strategy/data.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package strategy
|
||||
|
||||
import (
|
||||
"git.apinb.com/quant/gostock/internal/impl"
|
||||
"git.apinb.com/quant/gostock/internal/models"
|
||||
)
|
||||
|
||||
type StockData struct {
|
||||
Basic models.StockBasic
|
||||
Daily []models.StockDaily
|
||||
Indicator []models.StockIndicator
|
||||
FinaIndicator []models.StockFinaIndicator
|
||||
}
|
||||
|
||||
func GetData(code string) *StockData {
|
||||
var data StockData
|
||||
impl.DBService.Where("ts_code = ?", code).First(&data.Basic)
|
||||
impl.DBService.Where("ts_code = ?", code).Order("trade_date desc").Find(&data.Daily)
|
||||
impl.DBService.Where("ts_code = ?", code).Order("trade_date desc").Find(&data.Indicator)
|
||||
impl.DBService.Where("ts_code = ?", code).Order("period desc").Find(&data.FinaIndicator)
|
||||
return &data
|
||||
}
|
||||
|
||||
func GetIndustry() (industry []string) {
|
||||
impl.DBService.Model(&models.StockBasic{}).Group("industry").Pluck("industry", &industry)
|
||||
return
|
||||
}
|
||||
1
internal/logic/strategy/result.go
Normal file
1
internal/logic/strategy/result.go
Normal file
@@ -0,0 +1 @@
|
||||
package strategy
|
||||
44
internal/logic/strategy/rule/industry.go
Normal file
44
internal/logic/strategy/rule/industry.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package rule
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"git.apinb.com/quant/gostock/internal/logic/types"
|
||||
)
|
||||
|
||||
var (
|
||||
// 热门行业
|
||||
hotIndustries = "半导体,软件服务,互联网,IT设备,通信设备,元器件,电气设备,汽车配件,汽车整车,生物制药,化学制药,中成药,医疗保健,环境保护,新型电力,仓储物流,小金属,黄金,航空,铅锌,铝,铜"
|
||||
|
||||
// 夕阳行业
|
||||
sunsetIndustries = "全国地产,区域地产,房产服务,火力发电,煤炭开采,焦炭加工,普钢,钢加工,纺织,纺织机械,染料涂料,化纤,造纸,陶瓷,玻璃,百货,超市连锁,电器连锁,公路,铁路,出版业,摩托车"
|
||||
|
||||
// 中性/周期型行业
|
||||
neutralIndustries = "银行,证券,保险,建筑工程,装修装饰,水泥,其他建材,化工原料,农药化肥,汽车服务,运输设备,旅游服务,酒店餐饮,旅游景点,食品,乳制品,白酒,啤酒,家用电器,家居用品,港口,水运,空运,农业综合,种植业,渔业,多元金融,工程机械,轻工机械,机械基件,机床制造,专用机械,化工机械,电器仪表,塑料,橡胶,化纤,服饰,日用化工,文教休闲,影视音像,广告包装,批发业,商贸代理,其他商业,商品城,电信运营,供气供热,软饮料,红黄酒,公共交通,机场,路桥,水力发电,石油加工,石油开采,石油贸易,园区开发,综合类,林业,特种钢"
|
||||
)
|
||||
|
||||
type Industry struct {
|
||||
Key string
|
||||
Name string
|
||||
}
|
||||
|
||||
func NewIdustry() *Industry {
|
||||
return &Industry{
|
||||
Key: "industry",
|
||||
Name: "行业",
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Industry) Run(in string) *types.RuleResult {
|
||||
score := 0
|
||||
desc := "中性/周期型行业"
|
||||
if strings.Contains(hotIndustries, in) {
|
||||
score = 1
|
||||
desc = "热门行业"
|
||||
} else if strings.Contains(sunsetIndustries, in) {
|
||||
score = -1
|
||||
desc = "夕阳行业"
|
||||
}
|
||||
|
||||
return &types.RuleResult{Key: r.Key, Name: r.Name, Score: score, Desc: desc}
|
||||
}
|
||||
27
internal/logic/strategy/rule/st.go
Normal file
27
internal/logic/strategy/rule/st.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package rule
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"git.apinb.com/quant/gostock/internal/logic/types"
|
||||
)
|
||||
|
||||
type ST struct {
|
||||
Key string
|
||||
Name string
|
||||
}
|
||||
|
||||
func NewST() *ST {
|
||||
return &ST{
|
||||
Key: "ST",
|
||||
Name: "ST",
|
||||
}
|
||||
}
|
||||
|
||||
func (r *ST) Run(in string) *types.RuleResult {
|
||||
if strings.Contains(in, "ST") {
|
||||
return &types.RuleResult{Key: r.Key, Name: r.Name, Score: -1, Desc: "有退市风险"}
|
||||
}
|
||||
|
||||
return &types.RuleResult{Key: r.Key, Name: r.Name, Score: 1, Desc: "无退市风险"}
|
||||
}
|
||||
21
internal/logic/strategy/rule/up_date.go
Normal file
21
internal/logic/strategy/rule/up_date.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package rule
|
||||
|
||||
import (
|
||||
"git.apinb.com/quant/gostock/internal/logic/types"
|
||||
)
|
||||
|
||||
type UpDate struct {
|
||||
Key string
|
||||
Name string
|
||||
}
|
||||
|
||||
func NewUpDate() *UpDate {
|
||||
return &UpDate{
|
||||
Key: "UpDate",
|
||||
Name: "上市时间",
|
||||
}
|
||||
}
|
||||
|
||||
func (r *UpDate) Run(in string) *types.RuleResult {
|
||||
return &types.RuleResult{Key: r.Key, Name: r.Name, Score: 0, Desc: "暂不计算"}
|
||||
}
|
||||
8
internal/logic/types/rule.go
Normal file
8
internal/logic/types/rule.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package types
|
||||
|
||||
type RuleResult struct {
|
||||
Key string
|
||||
Name string
|
||||
Score int
|
||||
Desc string
|
||||
}
|
||||
Reference in New Issue
Block a user