forked from thrasher-corp/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
125 lines (117 loc) · 2.72 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"github.com/idoall/gocryptotrader/backtester/backtest"
"github.com/idoall/gocryptotrader/backtester/common"
"github.com/idoall/gocryptotrader/backtester/config"
"github.com/idoall/gocryptotrader/log"
"github.com/idoall/gocryptotrader/signaler"
)
func main() {
var configPath, templatePath, reportOutput string
var printLogo, generateReport, darkReport bool
wd, err := os.Getwd()
if err != nil {
fmt.Printf("Could not get working directory. Error: %v.\n", err)
os.Exit(1)
}
flag.StringVar(
&configPath,
"configpath",
filepath.Join(
wd,
"config",
"examples",
"dca-api-candles.strat"),
"the config containing strategy params")
flag.StringVar(
&templatePath,
"templatepath",
filepath.Join(
wd,
"report",
"tpl.gohtml"),
"the report template to use")
flag.BoolVar(
&generateReport,
"generatereport",
true,
"whether to generate the report file")
flag.StringVar(
&reportOutput,
"outputpath",
filepath.Join(
wd,
"results"),
"the path where to output results")
flag.BoolVar(
&printLogo,
"printlogo",
true,
"print out the logo to the command line, projected profits likely won't be affected if disabled")
flag.BoolVar(
&darkReport,
"darkreport",
false,
"sets the output report to use a dark theme by default")
flag.Parse()
var bt *backtest.BackTest
var cfg *config.Config
log.GlobalLogConfig = log.GenDefaultSettings()
err = log.SetupGlobalLogger()
if err != nil {
fmt.Printf("Could not setup global logger. Error: %v.\n", err)
os.Exit(1)
}
cfg, err = config.ReadConfigFromFile(configPath)
if err != nil {
fmt.Printf("Could not read config. Error: %v.\n", err)
os.Exit(1)
}
if printLogo {
fmt.Print(common.ASCIILogo)
}
err = cfg.Validate()
if err != nil {
fmt.Printf("Could not read config. Error: %v.\n", err)
os.Exit(1)
}
bt, err = backtest.NewFromConfig(cfg, templatePath, reportOutput)
if err != nil {
fmt.Printf("Could not setup backtester from config. Error: %v.\n", err)
os.Exit(1)
}
if cfg.DataSettings.LiveData != nil {
go func() {
err = bt.RunLive()
if err != nil {
fmt.Printf("Could not complete live run. Error: %v.\n", err)
os.Exit(-1)
}
}()
interrupt := signaler.WaitForInterrupt()
log.Infof(log.Global, "Captured %v, shutdown requested.\n", interrupt)
bt.Stop()
} else {
err = bt.Run()
if err != nil {
fmt.Printf("Could not complete run. Error: %v.\n", err)
os.Exit(1)
}
}
err = bt.Statistic.CalculateAllResults()
if err != nil {
log.Error(log.BackTester, err)
os.Exit(1)
}
if generateReport {
bt.Reports.UseDarkMode(darkReport)
err = bt.Reports.GenerateReport()
if err != nil {
log.Error(log.BackTester, err)
}
}
}