-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
72 lines (64 loc) · 1.56 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"fmt"
"gitee.com/quant1x/engine/command"
"gitee.com/quant1x/engine/config"
_ "gitee.com/quant1x/engine/strategies"
"gitee.com/quant1x/engine/utils"
"gitee.com/quant1x/gox/logger"
"gitee.com/quant1x/gox/runtime"
_ "net/http/pprof"
"os"
"runtime/pprof"
"time"
)
// 系统构建时传入的值
// go build -ldflags "-X 'main.MinVersion=${version}'"
var (
MinVersion = utils.InvalidVersion // 应用版本号
tdxVersion = utils.InvalidVersion // tdx api版本号
)
var (
cpuProfile = "./cpu.pprof"
memProfile = "./mem.pprof"
)
func resetVersions() {
if MinVersion == utils.InvalidVersion {
MinVersion = utils.CurrentVersion()
}
if tdxVersion == utils.InvalidVersion {
tdxVersion = utils.RequireVersion("gitee.com/quant1x/gotdx")
}
}
// 更新基础数据,特征,执行策略,回测等功能入口
func main() {
if config.PprofEnable() {
fCpu, err := os.Create(cpuProfile)
if err != nil {
logger.Fatal(err)
}
_ = pprof.StartCPUProfile(fCpu)
defer pprof.StopCPUProfile()
}
mainStart := time.Now()
resetVersions()
defer func() {
runtime.CatchPanic("")
elapsedTime := time.Since(mainStart) / time.Millisecond
fmt.Printf("\n总耗时: %.3fs\n", float64(elapsedTime)/1000)
}()
// stock模块内的更新版本号
command.UpdateApplicationVersion(MinVersion)
runtime.GoMaxProcs()
// 命令字
rootCommand := command.GlobalFlags()
_ = rootCommand.Execute()
if config.PprofEnable() {
fMem, err := os.Create(memProfile)
if err != nil {
logger.Fatal(err)
}
_ = pprof.WriteHeapProfile(fMem)
_ = fMem.Close()
}
}