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

     1  package tracker
     2  
     3  import (
     4  	"gitee.com/quant1x/engine/config"
     5  	"gitee.com/quant1x/engine/models"
     6  	"gitee.com/quant1x/gotdx/securities"
     7  )
     8  
     9  // SectorInfo 板块信息
    10  type SectorInfo struct {
    11  	Code           string   `name:"代码"`     // 板块代码
    12  	Name           string   `name:"名称"`     // 板块名称
    13  	Type           string   `name:"类型"`     // 板块类型
    14  	OpenAmount     float64  `name:"开盘金额"`   // 开盘金额
    15  	OpenChangeRate float64  `name:"开盘涨幅"`   // 开盘涨幅
    16  	ChangeRate     float64  `name:"板块涨幅"`   // 板块涨幅
    17  	Rank           int      `name:"板块排名"`   // 板块排名
    18  	TopCode        string   `name:"领涨个股"`   // 领涨个股
    19  	TopName        string   `name:"领涨个股名称"` // 领涨个股名称
    20  	TopRate        float64  `name:"领涨个股涨幅"` // 领涨个股涨幅
    21  	Count          int      `name:"总数"`     // 总数
    22  	LimitUpNum     int      `name:"涨停数"`    // 涨停数
    23  	NoChangeNum    int      `name:"平盘数"`    // 平盘数
    24  	UpCount        int      `name:"上涨家数"`   // 上涨家数
    25  	DownCount      int      `name:"下跌家数"`   // 下跌家数
    26  	Capital        float64  // 流通盘
    27  	FreeCapital    float64  // 自由流通股本
    28  	OpenTurnZ      float64  `name:"开盘换手"`   // 开盘换手
    29  	StockCodes     []string `dataframe:"-"` // 股票代码
    30  }
    31  
    32  // 通过板块类型扫描板块
    33  //
    34  //	板块排名从1开始
    35  func scanBlockByType(pbarIndex *int, blockType securities.BlockType, rule *config.StrategyParameter) []SectorInfo {
    36  	bs := []SectorInfo{}
    37  	isHead := rule.Flag == models.OrderFlagHead
    38  	blocks := scanSectorSnapshots(pbarIndex, blockType, isHead)
    39  	rank := 0
    40  	for i := 0; i < len(blocks); i++ {
    41  		v := blocks[i]
    42  		// 获取板块内个股列表
    43  		blockInfo := securities.GetBlockInfo(v.SecurityCode)
    44  		stockCodes := blockInfo.ConstituentStocks
    45  		stockCount := len(stockCodes)
    46  		if stockCount == 0 {
    47  			continue
    48  		}
    49  		rank++
    50  		bi := SectorInfo{
    51  			Code:           v.SecurityCode,
    52  			Name:           v.Name,
    53  			Type:           BlockTypeName(v.SecurityCode),
    54  			OpenAmount:     float64(v.IndexOpenAmount),
    55  			OpenChangeRate: v.OpeningChangeRate,
    56  			ChangeRate:     v.ChangeRate,
    57  			Rank:           rank,
    58  			OpenTurnZ:      v.OpenTurnZ,
    59  			StockCodes:     stockCodes,
    60  		}
    61  		bs = append(bs, bi)
    62  	}
    63  	return bs
    64  }
    65  
    66  func scanBlockByTypeForTick(pbarIndex *int, blockType securities.BlockType) []SectorInfo {
    67  	bs := []SectorInfo{}
    68  	blocks := scanSectorSnapshots(pbarIndex, blockType, false)
    69  	rank := 0
    70  	for i := 0; i < len(blocks); i++ {
    71  		v := blocks[i]
    72  		// 获取板块内个股列表
    73  		blockInfo := securities.GetBlockInfo(v.SecurityCode)
    74  		stockCodes := blockInfo.ConstituentStocks
    75  		stockCount := len(stockCodes)
    76  		if stockCount == 0 {
    77  			continue
    78  		}
    79  		rank++
    80  		bi := SectorInfo{
    81  			Code:           v.SecurityCode,
    82  			Name:           v.Name,
    83  			Type:           BlockTypeName(v.SecurityCode),
    84  			OpenAmount:     float64(v.IndexOpenAmount),
    85  			OpenChangeRate: v.OpeningChangeRate,
    86  			ChangeRate:     v.ChangeRate,
    87  			Rank:           rank,
    88  			OpenTurnZ:      v.OpenTurnZ,
    89  			StockCodes:     stockCodes,
    90  		}
    91  		bs = append(bs, bi)
    92  	}
    93  	return bs
    94  }
    95  
    96  // TopBlockWithType 板块排行
    97  func TopBlockWithType(pbarIndex *int, rule *config.StrategyParameter) map[securities.BlockType][]SectorInfo {
    98  	tmpMap := map[securities.BlockType][]SectorInfo{}
    99  	blockTypes := []securities.BlockType{securities.BK_GAINIAN}
   100  	for _, blockType := range blockTypes {
   101  		blocks := scanBlockByType(pbarIndex, blockType, rule)
   102  		tmpMap[blockType] = blocks
   103  	}
   104  	return tmpMap
   105  }
   106  
   107  var (
   108  	// 缓存板块类型名称
   109  	__mapBlockTypeName = map[string]string{}
   110  )
   111  
   112  func init() {
   113  	_ = GetBlockList()
   114  }
   115  
   116  func GetBlockList() []string {
   117  	// 执行板块指数的检测
   118  	blockInfos := securities.BlockList()
   119  	var blockCodes []string
   120  	for _, v := range blockInfos {
   121  		// 只保留行业和概念
   122  		if v.Type != securities.BK_HANGYE && v.Type != securities.BK_GAINIAN {
   123  			continue
   124  		}
   125  		blockCode := v.Code
   126  		blockCodes = append(blockCodes, blockCode)
   127  		blockTypeName, _ := securities.BlockTypeNameByTypeCode(v.Type)
   128  		__mapBlockTypeName[blockCode] = blockTypeName
   129  	}
   130  
   131  	return blockCodes
   132  }
   133  
   134  func BlockTypeName(blockCode string) string {
   135  	name, _ := __mapBlockTypeName[blockCode]
   136  	return name
   137  }