Exchanges: Remove bespoke pair upgrade handling and abstract Start/Run (#1424)

* Exchanges: Remove Pair upgrade handling

Now redundant behind #1401. These paths should never be met.

Several legacy coin upgrade paths being deprecated as well: ZUSD and CNY
Expecting any users with bad config from 3+ years ago would have to
reset anyway.

Also: At the time the intention of this was to upgrade the config
format.
However now, instead, it'd mostly serve to reset enabled pairs if
there's a config mistake, which doesn't feel right.

* Kraken: Fix typo in Kraken type struct

* Exchanges: Abstract exchange Start() and Run()

* Exchanges: Add test for abstracted Start

* Exchanges: Move Start to Bootstrap

* Simplify waitgroup usage
* Add call to exchange.Bootstrap to allow overide or supplementation

* Exchanges: Concurrent common bootstap actions

* Gateio: Remove incorrect Run in test

* GateIO: Fix pair dependencies in tests

This ensures that the pairs are initialised no more than needed and
kind-of just-in-time.
Better pattern might be to use a function to get these pairs when we
need them.

* Exchanges: Complete UpdatePairs before ExecLims

If we're going to update pairs, it needs to complete before we check for
limits to avoid errors on old pairs

* Exchanges: Remove Start and Run from tmpl

Since they're replaced by bootstrap now and shouldn't need customisation
normally

* Alphapoint: Move Start to Bootstrap

* GateIO: Fix linter shadow var
This commit is contained in:
Gareth Kirwan
2024-01-31 09:29:36 +01:00
committed by GitHub
parent 682737f368
commit d7818ea956
64 changed files with 379 additions and 2176 deletions

View File

@@ -722,7 +722,7 @@ func (bot *Engine) GetExchanges() []exchange.IBotExchange {
// LoadExchange loads an exchange by name. Optional wait group can be added for
// external synchronization.
func (bot *Engine) LoadExchange(name string, wg *sync.WaitGroup) error {
func (bot *Engine) LoadExchange(name string) error {
exch, err := bot.ExchangeManager.NewExchangeByName(name)
if err != nil {
return err
@@ -846,11 +846,7 @@ func (bot *Engine) LoadExchange(name string, wg *sync.WaitGroup) error {
}
}
if wg == nil {
wg = &sync.WaitGroup{}
defer wg.Wait()
}
return exch.Start(context.TODO(), wg)
return exchange.Bootstrap(context.TODO(), exch)
}
func (bot *Engine) dryRunParamInteraction(param string) {
@@ -869,7 +865,6 @@ func (bot *Engine) dryRunParamInteraction(param string) {
// SetupExchanges sets up the exchanges used by the Bot
func (bot *Engine) SetupExchanges() error {
var wg sync.WaitGroup
configs := bot.Config.GetAllExchangeConfigs()
if bot.Settings.EnableAllPairs {
bot.dryRunParamInteraction("enableallpairs")
@@ -902,6 +897,7 @@ func (bot *Engine) SetupExchanges() error {
bot.dryRunParamInteraction("exchangehttpdebugging")
}
var wg sync.WaitGroup
for x := range configs {
if !configs[x].Enabled && !bot.Settings.EnableAllExchanges {
gctlog.Debugf(gctlog.ExchangeSys, "%s: Exchange support: Disabled\n", configs[x].Name)
@@ -910,17 +906,16 @@ func (bot *Engine) SetupExchanges() error {
wg.Add(1)
go func(c config.Exchange) {
defer wg.Done()
err := bot.LoadExchange(c.Name, &wg)
if err != nil {
if err := bot.LoadExchange(c.Name); err != nil {
gctlog.Errorf(gctlog.ExchangeSys, "LoadExchange %s failed: %s\n", c.Name, err)
return
} else {
gctlog.Debugf(gctlog.ExchangeSys,
"%s: Exchange support: Enabled (Authenticated API support: %s - Verbose mode: %s).\n",
c.Name,
common.IsEnabled(c.API.AuthenticatedSupport),
common.IsEnabled(c.Verbose),
)
}
gctlog.Debugf(gctlog.ExchangeSys,
"%s: Exchange support: Enabled (Authenticated API support: %s - Verbose mode: %s).\n",
c.Name,
common.IsEnabled(c.API.AuthenticatedSupport),
common.IsEnabled(c.Verbose),
)
}(configs[x])
}
wg.Wait()

View File

@@ -8,6 +8,7 @@ import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/config"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
@@ -242,9 +243,9 @@ func TestDryRunParamInteraction(t *testing.T) {
},
},
}
if err := bot.LoadExchange(testExchange, nil); err != nil {
t.Error(err)
}
err := bot.LoadExchange(testExchange)
assert.NoError(t, err, "LoadExchange should not error")
exchCfg, err := bot.Config.GetExchangeConfig(testExchange)
if err != nil {
t.Error(err)
@@ -262,9 +263,9 @@ func TestDryRunParamInteraction(t *testing.T) {
bot.Settings.EnableDryRun = true
bot.Settings.CheckParamInteraction = true
bot.Settings.EnableExchangeVerbose = true
if err = bot.LoadExchange(testExchange, nil); err != nil {
t.Error(err)
}
err = bot.LoadExchange(testExchange)
assert.NoError(t, err, "LoadExchange should not error")
exchCfg, err = bot.Config.GetExchangeConfig(testExchange)
if err != nil {

View File

@@ -40,8 +40,8 @@ import (
var testExchange = "Bitstamp"
func CreateTestBot(t *testing.T) *Engine {
t.Helper()
func CreateTestBot(tb testing.TB) *Engine {
tb.Helper()
cFormat := &currency.PairFormat{Uppercase: true}
cp1 := currency.NewPair(currency.BTC, currency.USD)
cp2 := currency.NewPair(currency.BTC, currency.USDT)
@@ -92,9 +92,9 @@ func CreateTestBot(t *testing.T) *Engine {
},
},
}}}
if err := bot.LoadExchange(testExchange, nil); err != nil {
t.Fatalf("SetupTest: Failed to load exchange: %s", err)
}
err := bot.LoadExchange(testExchange)
assert.NoError(tb, err, "LoadExchange should not error")
return bot
}

View File

@@ -310,7 +310,7 @@ func (s *RPCServer) DisableExchange(_ context.Context, r *gctrpc.GenericExchange
// EnableExchange enables an exchange
func (s *RPCServer) EnableExchange(_ context.Context, r *gctrpc.GenericExchangeNameRequest) (*gctrpc.GenericResponse, error) {
err := s.LoadExchange(r.Exchange, nil)
err := s.LoadExchange(r.Exchange)
if err != nil {
return nil, err
}