mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-02 07:26:53 +00:00
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:
@@ -20,13 +20,14 @@ func main() {
|
||||
|
||||
log.Printf("Loading exchanges..")
|
||||
var wg sync.WaitGroup
|
||||
for x := range exchange.Exchanges {
|
||||
name := exchange.Exchanges[x]
|
||||
err = engine.Bot.LoadExchange(name, &wg)
|
||||
if err != nil {
|
||||
log.Printf("Failed to load exchange %s. Err: %s", name, err)
|
||||
continue
|
||||
}
|
||||
for i := range exchange.Exchanges {
|
||||
wg.Add(1)
|
||||
go func(name string) {
|
||||
defer wg.Done()
|
||||
if err = engine.Bot.LoadExchange(name); err != nil {
|
||||
log.Printf("Failed to load exchange %s. Err: %s", name, err)
|
||||
}
|
||||
}(exchange.Exchanges[i])
|
||||
}
|
||||
wg.Wait()
|
||||
log.Println("Done.")
|
||||
|
||||
@@ -3,8 +3,6 @@ package {{.Name}}
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
@@ -182,42 +180,6 @@ func ({{.Variable}} *{{.CapitalName}}) Setup(exch *config.Exchange) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Start starts the {{.CapitalName}} go routine
|
||||
func ({{.Variable}} *{{.CapitalName}}) Start(ctx context.Context, wg *sync.WaitGroup) error {
|
||||
if wg == nil {
|
||||
return fmt.Errorf("%T %w", wg, common.ErrNilPointer)
|
||||
}
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
{{.Variable}}.Run(ctx)
|
||||
wg.Done()
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run implements the {{.CapitalName}} wrapper
|
||||
func ({{.Variable}} *{{.CapitalName}}) Run(ctx context.Context) {
|
||||
if {{.Variable}}.Verbose {
|
||||
{{ if .WS }} log.Debugf(log.ExchangeSys,
|
||||
"%s Websocket: %s.",
|
||||
{{.Variable}}.Name,
|
||||
common.IsEnabled({{.Variable}}.Websocket.IsEnabled())) {{ end }}
|
||||
{{.Variable}}.PrintEnabledPairs()
|
||||
}
|
||||
|
||||
if !{{.Variable}}.GetEnabledFeatures().AutoPairUpdates {
|
||||
return
|
||||
}
|
||||
|
||||
err := {{.Variable}}.UpdateTradablePairs(ctx, false)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to update tradable pairs. Err: %s",
|
||||
{{.Variable}}.Name,
|
||||
err)
|
||||
}
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func ({{.Variable}} *{{.CapitalName}}) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
// Implement fetching the exchange available pairs if supported
|
||||
|
||||
@@ -32,18 +32,19 @@ func main() {
|
||||
|
||||
log.Printf("Loading exchanges..")
|
||||
var wg sync.WaitGroup
|
||||
for x := range exchange.Exchanges {
|
||||
if exchange.Exchanges[x] == "ftx" {
|
||||
for i := range exchange.Exchanges {
|
||||
name := exchange.Exchanges[i]
|
||||
if name == "ftx" {
|
||||
log.Println("Skipping exchange FTX...")
|
||||
continue
|
||||
}
|
||||
err = engine.Bot.LoadExchange(exchange.Exchanges[x], &wg)
|
||||
if err != nil {
|
||||
log.Printf("Failed to load exchange %s. Err: %s",
|
||||
exchange.Exchanges[x],
|
||||
err)
|
||||
continue
|
||||
}
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
if err := engine.Bot.LoadExchange(name); err != nil {
|
||||
log.Printf("Failed to load exchange %s. Err: %s", name, err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
log.Println("Done.")
|
||||
|
||||
@@ -68,17 +68,19 @@ func main() {
|
||||
log.Println("Loading exchanges..")
|
||||
|
||||
var wg sync.WaitGroup
|
||||
for x := range exchange.Exchanges {
|
||||
name := exchange.Exchanges[x]
|
||||
for i := range exchange.Exchanges {
|
||||
name := exchange.Exchanges[i]
|
||||
if _, ok := wrapperConfig.Exchanges[name]; !ok {
|
||||
wrapperConfig.Exchanges[strings.ToLower(name)] = &config.APICredentialsConfig{}
|
||||
}
|
||||
if shouldLoadExchange(name) {
|
||||
err = bot.LoadExchange(name, &wg)
|
||||
if err != nil {
|
||||
log.Printf("Failed to load exchange %s. Err: %s", name, err)
|
||||
continue
|
||||
}
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
if err = bot.LoadExchange(name); err != nil {
|
||||
log.Printf("Failed to load exchange %s. Err: %s", name, err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
Reference in New Issue
Block a user