Ai
7 Star 43 Fork 44

王布衣/gotdx

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
block_parse.go 2.08 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2025-08-07 13:19 +08:00 . sort imports
package securities
import (
"fmt"
"gitee.com/quant1x/exchange"
"gitee.com/quant1x/exchange/cache"
"gitee.com/quant1x/gox/api"
)
// SectorFilename 板块缓存文件名
func SectorFilename(date ...string) string {
name := "blocks"
cacheDate := exchange.LastTradeDate()
if len(date) > 0 {
cacheDate = exchange.FixTradeDate(date[0])
}
filename := fmt.Sprintf("%s/%s.%s", cache.GetMetaPath(), name, cacheDate)
return filename
}
// 读取板块数据
func parseAndGenerateBlockFile() {
blockInfos := loadIndexBlockInfos()
block2Name := map[string]string{}
for _, v := range blockInfos {
block2Name[v.Block] = v.Name
}
bks := []string{"block.dat", "block_gn.dat", "block_fg.dat", "block_zs.dat"}
//bks := []string{"block_gn.dat", "block_fg.dat", "block_zs.dat"}
name2block := map[string]__raw_block_info{}
for _, v := range bks {
bi := parseRawBlockData(v)
if bi != nil {
for _, bk := range (*bi).Data {
blockName := bk.BlockName
if bn, ok := block2Name[blockName]; ok {
blockName = bn
}
name2block[blockName] = bk
}
}
}
// 行业代码映射
code2hy := map[string]string{}
for _, v := range blockInfos {
if v.Name != v.Block {
code2hy[v.Block] = v.Name
}
}
// 行业板块数据
hys := loadIndustryBlocks()
for i, v := range blockInfos {
bn := v.Name
__info, ok := name2block[bn]
if ok {
list := []string{}
for _, sc := range __info.List {
if len(sc.Code) < 5 {
continue
}
marketId, _, _ := exchange.DetectMarket(sc.Code)
if marketId == exchange.MarketIdBeiJing {
continue
}
list = append(list, sc.Code)
}
blockInfos[i].Count = int(__info.Num)
blockInfos[i].ConstituentStocks = list
continue
}
bc := v.Block
stockList := industryConstituentStockList(hys, bc)
if len(stockList) > 0 {
blockInfos[i].Count = len(stockList)
blockInfos[i].ConstituentStocks = stockList
}
}
blockInfos = api.Filter(blockInfos, func(info BlockInfo) bool {
return len(info.ConstituentStocks) > 0
})
if len(blockInfos) > 0 {
filename := SectorFilename()
_ = api.SlicesToCsv(filename, blockInfos)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/gotdx.git
git@gitee.com:quant1x/gotdx.git
quant1x
gotdx
gotdx
v1.23.15

搜索帮助