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

     1  package tracker
     2  
     3  import (
     4  	"fmt"
     5  	"gitee.com/quant1x/engine/config"
     6  	"gitee.com/quant1x/engine/models"
     7  	"gitee.com/quant1x/gotdx/securities"
     8  	"slices"
     9  )
    10  
    11  // CheckStrategy 检查当前交易日中个股在策略中的执行情况
    12  func CheckStrategy(strategyCode uint64, securityCode string) {
    13  	fmt.Printf("\n策略检测中...\n")
    14  	// 1. 获取快照
    15  	name := securities.GetStockName(securityCode)
    16  	fmt.Printf("\t=> 证券代码: %s, 证券名称: %s...\n", securityCode, name)
    17  	fmt.Printf("\t=> 1. 获取tick[%s]...\n", securityCode)
    18  	snapshot := models.GetTick(securityCode)
    19  	if snapshot == nil {
    20  		fmt.Printf("\t=> 1. 获取tick[%s]...failed\n", securityCode)
    21  		return
    22  	}
    23  	fmt.Printf("\t=> 1. 获取tick[%s]...success\n", securityCode)
    24  
    25  	// 2. 获取策略配置
    26  	fmt.Printf("\t=> 2. 获取策略[%d]配置...\n", strategyCode)
    27  	strategyParameter := config.GetStrategyParameterByCode(strategyCode)
    28  	if strategyParameter == nil {
    29  		fmt.Printf("\t=> 2. 获取策略[%d]配置...not found\n", strategyCode)
    30  		return
    31  	}
    32  	fmt.Printf("\t=> 2. 获取策略[%d]配置...success\n", strategyCode)
    33  	fmt.Printf("\t=> 2. 获取策略[%d]配置, 策略名称=%s\n", strategyCode, strategyParameter.Name)
    34  
    35  	// 3. 检测板块及两融匹配
    36  	fmt.Printf("\t=> 3. 检测策略[%d]板块配置...\n", strategyCode)
    37  	fmt.Printf("\t=> 3. 检测策略[%d]板块配置...是否需要剔除两融...\n", strategyCode)
    38  	if strategyParameter.IgnoreMarginTrading {
    39  		fmt.Printf("\t=> 3. 检测策略[%d]板块配置...是否需要剔除两融, 需要\n", strategyCode)
    40  		// 过滤两融
    41  		marginTradingList := securities.MarginTradingList()
    42  		if len(marginTradingList) == 0 {
    43  			fmt.Printf("\t=> 3. 检测策略[%d]板块配置...是否需要剔除两融, 需要, 两融列表为空, 跳过检测\n", strategyCode)
    44  		} else if slices.Contains(marginTradingList, securityCode) {
    45  			fmt.Printf("\t=> 3. 检测策略[%d]板块配置...是否需要剔除两融, 需要, 检测失败: [%s]为两融标的,\n", strategyCode, securityCode)
    46  			return
    47  		}
    48  	} else {
    49  		fmt.Printf("\t=> 3. 检测策略[%d]板块配置...是否需要剔除两融, 不需要\n", strategyCode)
    50  	}
    51  	fmt.Printf("\t=> 3. 检测策略[%d]板块配置...是否需要剔除两融...success\n", strategyCode)
    52  
    53  	// 4. 检测板块及两融匹配
    54  	fmt.Printf("\t=> 4. 检测策略[%d]板块是否匹配...\n", strategyCode)
    55  	stockList := strategyParameter.StockList()
    56  	if !slices.Contains(stockList, securityCode) {
    57  		fmt.Printf("\t=> 4. 检测策略[%d]板块是否匹配...失败, %s非策略配置的板块成分股\n", strategyCode, securityCode)
    58  		return
    59  	}
    60  	fmt.Printf("\t=> 4. 检测策略[%d]板块是否匹配...success\n", strategyCode)
    61  
    62  	// 5. 获取策略对象
    63  	fmt.Printf("\t=> 5. 获取策略[%d]对象...\n", strategyCode)
    64  	model, err := models.CheckoutStrategy(strategyCode)
    65  	if err != nil {
    66  		fmt.Printf("\t=> 5. 获取策略[%d]对象...失败: %+v\n", strategyCode, err)
    67  		return
    68  	}
    69  	fmt.Printf("\t=> 5. 获取策略[%d]对象...success\n", strategyCode)
    70  
    71  	// 6. 执行过滤规则
    72  	fmt.Printf("\t=> 6. 执行策略[%d]过滤规则...\n", strategyCode)
    73  	v := model.Filter(strategyParameter.Rules, *snapshot)
    74  	if v == nil {
    75  		fmt.Printf("\t=> 6. 执行策略[%d]过滤规则...passed\n", strategyCode)
    76  	} else {
    77  		fmt.Printf("\t=> 6. 执行策略[%d]过滤规则...failed: %+v\n", strategyCode, v)
    78  	}
    79  }