gitee.com/quant1x/engine@v1.8.4/command/command_tracker.go (about) 1 package command 2 3 import ( 4 "fmt" 5 "gitee.com/quant1x/engine/models" 6 "gitee.com/quant1x/engine/permissions" 7 "gitee.com/quant1x/engine/tracker" 8 "gitee.com/quant1x/gox/api" 9 "gitee.com/quant1x/gox/logger" 10 cmder "github.com/spf13/cobra" 11 "strings" 12 ) 13 14 const ( 15 trackerCommand = "tracker" 16 trackerDescription = "实时跟踪" 17 ) 18 19 var ( 20 trackerStrategyCodes = "1" // 策略编号 21 CmdTracker *cmder.Command = nil // 实时跟踪 22 ) 23 24 func initTracker() { 25 CmdTracker = &cmder.Command{ 26 Use: trackerCommand, 27 Example: Application + " " + trackerCommand + " --no=1", 28 //Args: cobra.MinimumNArgs(0), 29 Args: func(cmd *cmder.Command, args []string) error { 30 return nil 31 }, 32 Short: trackerDescription, 33 Long: trackerDescription, 34 Run: func(cmd *cmder.Command, args []string) { 35 var strategyCodes []uint64 36 array := strings.Split(trackerStrategyCodes, ",") 37 for _, strategyNumber := range array { 38 strategyNumber := strings.TrimSpace(strategyNumber) 39 code := api.ParseUint(strategyNumber) 40 // 1. 确定策略是否存在 41 medel, err := models.CheckoutStrategy(code) 42 if err != nil { 43 fmt.Printf("策略编号%d, 不存在\n", code) 44 logger.Errorf("策略编号%d, 不存在", code) 45 continue 46 } 47 // 2. 确定策略是否有权限 48 err = permissions.CheckPermission(medel) 49 if err != nil { 50 fmt.Printf("策略编号%d, 权限验证失败: %+v\n", code, err) 51 logger.Errorf("策略编号%d, 权限验证失败: %+v", code, err) 52 continue 53 } 54 strategyCodes = append(strategyCodes, code) 55 } 56 if len(strategyCodes) == 0 { 57 fmt.Println("没有有效的策略编号, 实时扫描结束") 58 logger.Info("没有有效的策略编号, 实时扫描结束") 59 return 60 } 61 tracker.Tracker(strategyCodes...) 62 }, 63 } 64 65 CmdTracker.Flags().StringVar(&trackerStrategyCodes, "no", trackerStrategyCodes, "策略编号, 多个用逗号分隔") 66 }