exchanges: shift GetDefaultConfig wrapper function to exchange.go (#1472)

* Shift wrapper function GetDefaultConfig to exchange.Base method definition, to ensure set defaults doesn't get called twice and to reduce code

* rm alphapoint bootstrap method as is defined as exchange.Base method

* add tests

* glorious: make it a function and make it IBOTEXCHANGE

---------

Co-authored-by: shazbert <ryan.oharareid@thrasher.io>
This commit is contained in:
Ryan O'Hara-Reid
2024-04-12 16:15:43 +10:00
committed by GitHub
parent 98eae1e0ce
commit 9657a570dd
39 changed files with 234 additions and 616 deletions

View File

@@ -36,7 +36,7 @@ func main() {
cfgs := make([]config.Exchange, 0, len(exchanges))
for x := range exchanges {
var cfg *config.Exchange
cfg, err = exchanges[x].GetDefaultConfig(context.Background())
cfg, err = exchange.GetDefaultConfig(context.Background(), exchanges[x])
if err != nil {
log.Printf("Failed to get exchanges default config. Err: %s", err)
continue

View File

@@ -26,25 +26,6 @@ import (
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
)
// GetDefaultConfig returns a default exchange config
func ({{.Variable}} *{{.CapitalName}}) GetDefaultConfig(ctx context.Context) (*config.Exchange, error) {
{{.Variable}}.SetDefaults()
exchCfg := new(config.Exchange)
exchCfg.Name = {{.Variable}}.Name
exchCfg.HTTPTimeout = exchange.DefaultHTTPTimeout
exchCfg.BaseCurrencies = {{.Variable}}.BaseCurrencies
{{.Variable}}.SetupDefaults(exchCfg)
if {{.Variable}}.Features.Supports.RESTCapabilities.AutoPairUpdates {
err := {{.Variable}}.UpdateTradablePairs(ctx, true)
if err != nil {
return nil, err
}
}
return exchCfg, nil
}
// SetDefaults sets the basic defaults for {{.CapitalName}}
func ({{.Variable}} *{{.CapitalName}}) SetDefaults() {
{{.Variable}}.Name = "{{.CapitalName}}"