Files
gocryptotrader/backtester/config/backtesterconfig.go
Scott 1461cba363 backtester: standalone application (#988)
* Ramshackle early leads to GRPC backtester

* Adds GRPC server, default config generation

* Partial support for GRPC backtester config

* Update to use Buf, merge fixes

* Full config for GRPC

* Adds new commands, causes big panic

* Fixes panics

* Setup for the future

* Docs update

* test

* grpc tests

* Fix merge issues. Lint and test

* minor fixes after rebase

* Docs, formatting and main fixes

* Change buf owner

* shazNits

* test-123

* rpc fixes

* string fixes

* Removes --singlerun flag and just relies on --singlerunstrategypath

* fixes test

* initial post merge compatability fixes

* this actually all seems to work? unexpected

* adds pluginpath to config

* rm unused func. add gitignore

* rm unused func. add gitignore

* lintle

* tITLE cASE lOG fIX,rm auth package, gitignore, tmpdir fix

* buf updates + gen. go mod tidy

* x2

* Update default port, update error text
2022-09-08 16:22:30 +10:00

72 lines
1.8 KiB
Go

package config
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"github.com/thrasher-corp/gocryptotrader/backtester/common"
"github.com/thrasher-corp/gocryptotrader/common/file"
gctconfig "github.com/thrasher-corp/gocryptotrader/config"
)
// ReadBacktesterConfigFromPath will take a config from a path
func ReadBacktesterConfigFromPath(path string) (*BacktesterConfig, error) {
if !file.Exists(path) {
return nil, fmt.Errorf("%w %v", common.ErrFileNotFound, path)
}
data, err := os.ReadFile(path)
if err != nil {
return nil, err
}
var resp *BacktesterConfig
err = json.Unmarshal(data, &resp)
return resp, err
}
// GenerateDefaultConfig will return the default backtester config
func GenerateDefaultConfig() (*BacktesterConfig, error) {
wd, err := os.Getwd()
if err != nil {
return nil, err
}
return &BacktesterConfig{
PrintLogo: true,
LogSubheaders: true,
Report: Report{
GenerateReport: true,
TemplatePath: filepath.Join(wd, "report", "tpl.gohtml"),
OutputPath: filepath.Join(wd, "results"),
},
GRPC: GRPC{
Username: "rpcuser",
Password: "helloImTheDefaultPassword",
GRPCConfig: gctconfig.GRPCConfig{
Enabled: true,
ListenAddress: "localhost:9054",
},
TLSDir: DefaultBTDir,
},
UseCMDColours: true,
Colours: common.Colours{
Default: common.CMDColours.Default,
Green: common.CMDColours.Green,
White: common.CMDColours.White,
Grey: common.CMDColours.Grey,
DarkGrey: common.CMDColours.DarkGrey,
H1: common.CMDColours.H1,
H2: common.CMDColours.H2,
H3: common.CMDColours.H3,
H4: common.CMDColours.H4,
Success: common.CMDColours.Success,
Info: common.CMDColours.Info,
Debug: common.CMDColours.Debug,
Warn: common.CMDColours.Warn,
Error: common.CMDColours.Error,
},
}, nil
}