gitee.com/quant1x/engine@v1.8.4/tracker/executor.go (about) 1 package tracker 2 3 import ( 4 "fmt" 5 "gitee.com/quant1x/engine/config" 6 "gitee.com/quant1x/engine/market" 7 "gitee.com/quant1x/engine/models" 8 "gitee.com/quant1x/engine/permissions" 9 "gitee.com/quant1x/gox/concurrent" 10 "gitee.com/quant1x/gox/logger" 11 "gitee.com/quant1x/gox/progressbar" 12 "gitee.com/quant1x/gox/tags" 13 "gitee.com/quant1x/pkg/tablewriter" 14 "os" 15 ) 16 17 // ExecuteStrategy 执行策略 18 // Deprecated: 推荐 ExecuteStrategy 19 func v1ExecuteStrategy(model models.Strategy, barIndex *int) { 20 fmt.Printf("策略模块: %s\n", model.Name()) 21 // 加载即时行情 22 models.SyncAllSnapshots(barIndex) 23 fmt.Println() 24 // 执行策略 25 allCodes := market.GetCodeList() 26 count := len(allCodes) 27 bar := progressbar.NewBar(*barIndex, "执行["+model.Name()+"]", count) 28 results := concurrent.NewTreeMap[string, models.ResultInfo]() 29 for _, securityCode := range allCodes { 30 // 此处可以增加过滤规则 31 model.Evaluate(securityCode, results) 32 bar.Add(1) 33 } 34 // 输出一个换行符, 结束上一个进度条 35 fmt.Println() 36 table := tablewriter.NewWriter(os.Stdout) 37 table.SetHeader(tags.GetHeadersByTags(models.ResultInfo{})) 38 results.Each(func(key string, value models.ResultInfo) { 39 table.Append(tags.GetValuesByTags(value)) 40 }) 41 table.Render() 42 } 43 44 // ExecuteStrategy 执行策略 45 func ExecuteStrategy(model models.Strategy, barIndex *int) { 46 // 策略权限验证 47 err := permissions.CheckPermission(model) 48 if err != nil { 49 logger.Error(err) 50 return 51 } 52 tradeRule := config.GetStrategyParameterByCode(model.Code()) 53 if tradeRule == nil { 54 fmt.Printf("strategy[%d]: trade rule not found\n", model.Code()) 55 return 56 } 57 // 加载快照数据 58 models.SyncAllSnapshots(barIndex) 59 // 计算市场情绪 60 MarketSentiment() 61 // 扫描板块 62 ScanAllSectors(barIndex, model) 63 // 扫描个股 64 AllScan(barIndex, model) 65 }