gitee.com/quant1x/engine@v1.8.4/tracker/sector_snapshot.go (about)

     1  package tracker
     2  
     3  import (
     4  	"fmt"
     5  	"gitee.com/quant1x/engine/factors"
     6  	"gitee.com/quant1x/engine/models"
     7  	"gitee.com/quant1x/gotdx/securities"
     8  	"gitee.com/quant1x/gox/api"
     9  	"gitee.com/quant1x/gox/progressbar"
    10  	"gitee.com/quant1x/num"
    11  )
    12  
    13  // 板块扫描
    14  func scanSectorSnapshots(pbarIndex *int, blockType securities.BlockType, isHead bool) (list []factors.QuoteSnapshot) {
    15  	// 执行板块指数的检测
    16  	blockInfos := securities.BlockList()
    17  	// 获取指定类型的板块代码列表
    18  	var blockCodes []string
    19  	for _, v := range blockInfos {
    20  		if v.Type != blockType {
    21  			continue
    22  		}
    23  		blockCode := v.Code
    24  		blockCodes = append(blockCodes, blockCode)
    25  		blockTypeName, _ := securities.BlockTypeNameByTypeCode(v.Type)
    26  		__mapBlockTypeName[blockCode] = blockTypeName
    27  	}
    28  
    29  	blockCount := len(blockCodes)
    30  	fmt.Println()
    31  	btn, ok := securities.BlockTypeNameByTypeCode(blockType)
    32  	if !ok {
    33  		btn = num.AnyToString(blockType)
    34  	}
    35  	bar := progressbar.NewBar(*pbarIndex, "执行[扫描"+btn+"板块指数]", blockCount)
    36  	*pbarIndex++
    37  	for i := 0; i < blockCount; i++ {
    38  		bar.Add(1)
    39  		blockCode := blockCodes[i]
    40  		snapshot := models.GetStrategySnapshot(blockCode)
    41  		if snapshot == nil {
    42  			continue
    43  		}
    44  		list = append(list, *snapshot)
    45  	}
    46  	if isHead {
    47  		api.SliceSort(list, SectorSortForHead)
    48  	} else {
    49  		api.SliceSort(list, SectorSortForTick)
    50  	}
    51  	return list
    52  }