6 Star 18 Fork 28

王布衣 / gotdx

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
block_industry.go 1.99 KB
一键复制 编辑 原始数据 按行查看 历史
package securities
import (
"bufio"
"gitee.com/quant1x/exchange/cache"
"gitee.com/quant1x/gox/api"
"gitee.com/quant1x/gox/text/encoding"
"io"
"os"
"slices"
"strings"
)
// IndustryInfo 行业板块对应
type IndustryInfo struct {
MarketId int // 市场代码
Code string // 股票代码
Block string // 行业板块代码
Block5 string // 二级行业板块代码
XBlock string // x行业代码
XBlock5 string // x二级行业代码
}
// 获取行业板块
func loadIndustryBlocks() []IndustryInfo {
hyfile := "tdxhy.cfg"
name := hyfile
cacheFilename := cache.GetBlockPath() + "/" + name
if !api.FileExist(cacheFilename) {
// 如果文件不存在, 导出内嵌资源
err := export(cacheFilename, name)
if err != nil {
return nil
}
}
file, err := os.Open(cacheFilename)
if err != nil {
return nil
}
defer api.CloseQuietly(file)
reader := bufio.NewReader(file)
// 按行处理txt
decoder := encoding.NewDecoder("GBK")
var hys = []IndustryInfo{}
for {
data, _, err := reader.ReadLine()
if err == io.EOF {
break
}
line := decoder.ConvertString(string(data))
arr := strings.Split(line, "|")
bc := arr[2]
bc5 := bc
if len(bc5) >= 5 {
bc5 = bc5[0:5]
}
var xbc, xbc5 string
if len(arr) >= 6 {
xbc5 = arr[5]
if len(xbc5) >= 6 {
xbc = xbc5[:5]
}
}
hy := IndustryInfo{
MarketId: int(api.ParseInt(arr[0])),
Code: arr[1],
Block: bc,
Block5: bc5,
XBlock: xbc,
XBlock5: xbc5,
}
hys = append(hys, hy)
}
return hys
}
// 从行业信息中提取股票代码列表
func industryConstituentStockList(hys []IndustryInfo, block string) []string {
list := []string{}
for _, v := range hys {
if len(block) == 5 {
//if v.Block5 == block {
if strings.HasPrefix(v.Block5, block) || strings.HasPrefix(v.XBlock5, block) {
list = append(list, v.Code)
}
} else {
if v.Block == block || v.XBlock == block {
list = append(list, v.Code)
}
}
}
if len(list) > 0 {
slices.Sort(list)
}
return list
}
Go
1
https://gitee.com/quant1x/gotdx.git
git@gitee.com:quant1x/gotdx.git
quant1x
gotdx
gotdx
v1.22.6

搜索帮助