mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-08 23:16:54 +00:00
Feature: Faster start & stop times (#648)
* Updates starting and stopping routines to be a bit more parallel with less waiting required * Removes stop, removes debugging output * linting and test fixes * Add extra kill switch for exiting on exchange loading delay * Fixes fun math * breaks loop instead of switch. Moves param warns higher * Removes unceccary gos. passes in cfg to remove data race * Removes os signal processing. Fixes bad master merge
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
@@ -224,83 +225,62 @@ func (bot *Engine) LoadExchange(name string, useWG bool, wg *sync.WaitGroup) err
|
||||
return ErrExchangeFailedToLoad
|
||||
}
|
||||
|
||||
exch.SetDefaults()
|
||||
var localWG sync.WaitGroup
|
||||
localWG.Add(1)
|
||||
go func() {
|
||||
exch.SetDefaults()
|
||||
localWG.Done()
|
||||
}()
|
||||
exchCfg, err := bot.Config.GetExchangeConfig(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if bot.Settings.EnableAllPairs {
|
||||
if exchCfg.CurrencyPairs != nil {
|
||||
bot.dryrunParamInteraction("enableallpairs")
|
||||
assets := exchCfg.CurrencyPairs.GetAssetTypes()
|
||||
for x := range assets {
|
||||
var pairs currency.Pairs
|
||||
pairs, err = exchCfg.CurrencyPairs.GetPairs(assets[x], false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
exchCfg.CurrencyPairs.StorePairs(assets[x], pairs, true)
|
||||
if bot.Settings.EnableAllPairs &&
|
||||
exchCfg.CurrencyPairs != nil {
|
||||
assets := exchCfg.CurrencyPairs.GetAssetTypes()
|
||||
for x := range assets {
|
||||
var pairs currency.Pairs
|
||||
pairs, err = exchCfg.CurrencyPairs.GetPairs(assets[x], false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
exchCfg.CurrencyPairs.StorePairs(assets[x], pairs, true)
|
||||
}
|
||||
}
|
||||
|
||||
if bot.Settings.EnableExchangeVerbose {
|
||||
bot.dryrunParamInteraction("exchangeverbose")
|
||||
exchCfg.Verbose = true
|
||||
}
|
||||
|
||||
if bot.Settings.EnableExchangeWebsocketSupport {
|
||||
bot.dryrunParamInteraction("exchangewebsocketsupport")
|
||||
if exchCfg.Features != nil {
|
||||
if exchCfg.Features.Supports.Websocket {
|
||||
exchCfg.Features.Enabled.Websocket = true
|
||||
}
|
||||
if exchCfg.Features != nil {
|
||||
if bot.Settings.EnableExchangeWebsocketSupport &&
|
||||
exchCfg.Features.Supports.Websocket {
|
||||
exchCfg.Features.Enabled.Websocket = true
|
||||
}
|
||||
}
|
||||
|
||||
if bot.Settings.EnableExchangeAutoPairUpdates {
|
||||
bot.dryrunParamInteraction("exchangeautopairupdates")
|
||||
if exchCfg.Features != nil {
|
||||
if exchCfg.Features.Supports.RESTCapabilities.AutoPairUpdates {
|
||||
exchCfg.Features.Enabled.AutoPairUpdates = true
|
||||
}
|
||||
if bot.Settings.EnableExchangeAutoPairUpdates &&
|
||||
exchCfg.Features.Supports.RESTCapabilities.AutoPairUpdates {
|
||||
exchCfg.Features.Enabled.AutoPairUpdates = true
|
||||
}
|
||||
}
|
||||
|
||||
if bot.Settings.DisableExchangeAutoPairUpdates {
|
||||
bot.dryrunParamInteraction("exchangedisableautopairupdates")
|
||||
if exchCfg.Features != nil {
|
||||
if bot.Settings.DisableExchangeAutoPairUpdates {
|
||||
if exchCfg.Features.Supports.RESTCapabilities.AutoPairUpdates {
|
||||
exchCfg.Features.Enabled.AutoPairUpdates = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if bot.Settings.HTTPUserAgent != "" {
|
||||
bot.dryrunParamInteraction("httpuseragent")
|
||||
exchCfg.HTTPUserAgent = bot.Settings.HTTPUserAgent
|
||||
}
|
||||
|
||||
if bot.Settings.HTTPProxy != "" {
|
||||
bot.dryrunParamInteraction("httpproxy")
|
||||
exchCfg.ProxyAddress = bot.Settings.HTTPProxy
|
||||
}
|
||||
|
||||
if bot.Settings.HTTPTimeout != exchange.DefaultHTTPTimeout {
|
||||
bot.dryrunParamInteraction("httptimeout")
|
||||
exchCfg.HTTPTimeout = bot.Settings.HTTPTimeout
|
||||
}
|
||||
|
||||
if bot.Settings.EnableExchangeHTTPDebugging {
|
||||
bot.dryrunParamInteraction("exchangehttpdebugging")
|
||||
exchCfg.HTTPDebugging = bot.Settings.EnableExchangeHTTPDebugging
|
||||
}
|
||||
|
||||
if bot.Settings.EnableAllExchanges {
|
||||
bot.dryrunParamInteraction("enableallexchanges")
|
||||
}
|
||||
|
||||
localWG.Wait()
|
||||
if !bot.Settings.EnableExchangeHTTPRateLimiter {
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"Loaded exchange %s rate limiting has been turned off.\n",
|
||||
@@ -324,7 +304,6 @@ func (bot *Engine) LoadExchange(name string, useWG bool, wg *sync.WaitGroup) err
|
||||
}
|
||||
|
||||
bot.exchangeManager.add(exch)
|
||||
|
||||
base := exch.GetBase()
|
||||
if base.API.AuthenticatedSupport ||
|
||||
base.API.AuthenticatedWebsocketSupport {
|
||||
@@ -363,25 +342,65 @@ func (bot *Engine) LoadExchange(name string, useWG bool, wg *sync.WaitGroup) err
|
||||
}
|
||||
|
||||
// SetupExchanges sets up the exchanges used by the Bot
|
||||
func (bot *Engine) SetupExchanges() {
|
||||
func (bot *Engine) SetupExchanges() error {
|
||||
var wg sync.WaitGroup
|
||||
configs := bot.Config.GetAllExchangeConfigs()
|
||||
if bot.Settings.EnableAllPairs {
|
||||
bot.dryrunParamInteraction("enableallpairs")
|
||||
}
|
||||
if bot.Settings.EnableAllExchanges {
|
||||
bot.dryrunParamInteraction("enableallexchanges")
|
||||
}
|
||||
if bot.Settings.EnableExchangeVerbose {
|
||||
bot.dryrunParamInteraction("exchangeverbose")
|
||||
}
|
||||
if bot.Settings.EnableExchangeWebsocketSupport {
|
||||
bot.dryrunParamInteraction("exchangewebsocketsupport")
|
||||
}
|
||||
if bot.Settings.EnableExchangeAutoPairUpdates {
|
||||
bot.dryrunParamInteraction("exchangeautopairupdates")
|
||||
}
|
||||
if bot.Settings.DisableExchangeAutoPairUpdates {
|
||||
bot.dryrunParamInteraction("exchangedisableautopairupdates")
|
||||
}
|
||||
if bot.Settings.HTTPUserAgent != "" {
|
||||
bot.dryrunParamInteraction("httpuseragent")
|
||||
}
|
||||
if bot.Settings.HTTPProxy != "" {
|
||||
bot.dryrunParamInteraction("httpproxy")
|
||||
}
|
||||
if bot.Settings.HTTPTimeout != exchange.DefaultHTTPTimeout {
|
||||
bot.dryrunParamInteraction("httptimeout")
|
||||
}
|
||||
if bot.Settings.EnableExchangeHTTPDebugging {
|
||||
bot.dryrunParamInteraction("exchangehttpdebugging")
|
||||
}
|
||||
|
||||
for x := range configs {
|
||||
if !configs[x].Enabled && !bot.Settings.EnableAllExchanges {
|
||||
log.Debugf(log.ExchangeSys, "%s: Exchange support: Disabled\n", configs[x].Name)
|
||||
continue
|
||||
}
|
||||
err := bot.LoadExchange(configs[x].Name, true, &wg)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "LoadExchange %s failed: %s\n", configs[x].Name, err)
|
||||
continue
|
||||
}
|
||||
log.Debugf(log.ExchangeSys,
|
||||
"%s: Exchange support: Enabled (Authenticated API support: %s - Verbose mode: %s).\n",
|
||||
configs[x].Name,
|
||||
common.IsEnabled(configs[x].API.AuthenticatedSupport),
|
||||
common.IsEnabled(configs[x].Verbose),
|
||||
)
|
||||
wg.Add(1)
|
||||
cfg := configs[x]
|
||||
go func(currCfg config.ExchangeConfig) {
|
||||
defer wg.Done()
|
||||
err := bot.LoadExchange(currCfg.Name, true, &wg)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "LoadExchange %s failed: %s\n", currCfg.Name, err)
|
||||
return
|
||||
}
|
||||
log.Debugf(log.ExchangeSys,
|
||||
"%s: Exchange support: Enabled (Authenticated API support: %s - Verbose mode: %s).\n",
|
||||
currCfg.Name,
|
||||
common.IsEnabled(currCfg.API.AuthenticatedSupport),
|
||||
common.IsEnabled(currCfg.Verbose),
|
||||
)
|
||||
}(cfg)
|
||||
}
|
||||
wg.Wait()
|
||||
if len(bot.exchangeManager.exchanges) == 0 {
|
||||
return errors.New("no exchanges are loaded")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user