Files
gocryptotrader/backtester/main.go
Scott 6eaa2e4073 Backtester: USD tracking (#818)
* Initial concept for creating price tracking pairs

* Completes coverage, even with a slow test

* I dont know what point to hook this stuff up

* Bit of a broken way of handling tracking pairs

* Correctly calculates USD rates against all currencies

* Removes dependency on GCT config

* Failed currency statistics redesign

* initial Update chart to use highcharts

* Minor changes to stats

* Creats funding stats to handle the stat calculations. Needs more work

* tracks USD snapshots and BREAKS THINGS FURTHER

* Fixed!

* Adds ratio calculations and such, but its WRONG. do it at totals level dummy

* End of day basic lint

* Remaining lints

* USD totals statistics

* Minor panic fixes

* Printing of funding stats, but its bad

* Properly calculates overall benchmark, moves funding stat output

* Adds some template charge, removes duplicate fields

* New charts!

* Darkcharts. funding protection when disabled

* Now works with usd tracking/funding disabled!

* Attempting to only show working stats based on settings.

* Spruces up the goose/reporting

* Completes report HTML rendering

* lint and test fixes

* funding statistics testing

* slightly more test coverage

* Test coverage

* Initial documentation

* Fixes tests

* Database testing and rendering improvements and breakages

* report and cmd rendering, linting. fix comma output. rm gct cfg

* PR mode 🎉 Path field, config builder support,testing,linting,docs

* minor calculation improvement

* Secret lint that did not show up locally

* Disable USD tracking for example configs

* ShazNitNoScope

* Forgotten errors

* ""

* literally Logarithmically logically renders the date 👀

* Fixes typos, fixes parallel test, fixes chart gui and exporting
2021-11-08 12:10:15 +11:00

123 lines
2.7 KiB
Go

package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"github.com/thrasher-corp/gocryptotrader/backtester/backtest"
"github.com/thrasher-corp/gocryptotrader/backtester/common"
"github.com/thrasher-corp/gocryptotrader/backtester/config"
"github.com/thrasher-corp/gocryptotrader/log"
"github.com/thrasher-corp/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
logConfig := log.GenDefaultSettings()
log.GlobalLogConfig = &logConfig
log.SetupGlobalLogger()
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)
}
}
}