Files
gocryptotrader/backtester/config/backtesterconfig.go
Ryan O'Hara-Reid e99adca86f encoding/json: Add custom JSON package with build tag support for Sonic (#1623)
* tag optional sonic and allow full library conversion

* Add workflow and disallow arm and darwin usage

* Add basic hotswap benchmark

* linter: fix

* use bash

* linter: fix?

* Fix whoopsie, add to make file, also add mention in features list.

* test enforcement

* actually read documentation see if this works

* linter: fix

* linter: fix

* sonic: bump tagged version

* encoding/json: drop build tag arch and os filters

* encoding/json: consolidate tests

* encoding/json: log build tag usage

* rm superfluous builds

* glorious/nits: add template change and regen docs

* glorious/nits: update commentary on nolint directive

* glorious/nits: rm init func and log results in main.go

* Test to actually pull flag in

* linter: fix

* thrasher: nits

* gk: nits 4 goflags goooooooooo!

* gk: nits rn

* make sonic default json implementation

* screen 386

* linter: fix

* Add commentary

* glorious: nits Makefile not working

* gk: nits

* gk: nits whoops

* whoopsirino

* mention 32bit systems won't be sonic

* gk: super-duper nit of extremes

---------

Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
2025-02-20 16:05:55 +11:00

73 lines
1.9 KiB
Go

package config
import (
"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"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
)
// 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,
},
StopAllTasksOnClose: true,
}, nil
}