mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-08 07:26:48 +00:00
engine: Adds shutdown method to exchange manager and unload all exchanges when engine is stopped (#1112)
* engine: shutdown and unload exchange when engine is stopped * linter: fixes * engine/exchMan: add nil check * engine/exchanges: add shutdown method to exchanges, rm len check lock not needed, expanded code coverage, address some nits * exchMan: report all failed shutdowns across exchanges, implement timer and monitoring routines. * exchMan: improve shutdown sequence and aloc. * further improvement * exchman: log from warn to error * websockconnection: Suppress error return when closure is caused by library * linter: fix * fix racies * add note on why not parallel tests * glorious: nits * spelling kween * thrasher: nits * engine: change print of setting using reflection, I keep forgetting to implement this so program around forgetfulness * engine/exchange_management: remove wait group and just rely on intermediary lock * glorious: nits * Update common/common.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * Update main.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> --------- Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io> Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
@@ -331,7 +331,7 @@ func TestLoadDataLive(t *testing.T) {
|
||||
Funding: &funding.FundManager{},
|
||||
DataHolder: &data.HandlerHolder{},
|
||||
Statistic: &fakeStats{},
|
||||
exchangeManager: engine.SetupExchangeManager(),
|
||||
exchangeManager: engine.NewExchangeManager(),
|
||||
shutdown: make(chan struct{}),
|
||||
}
|
||||
|
||||
@@ -1103,13 +1103,16 @@ func TestProcessFillEvent(t *testing.T) {
|
||||
ev := &fill.Fill{
|
||||
Base: de.Base,
|
||||
}
|
||||
em := engine.SetupExchangeManager()
|
||||
em := engine.NewExchangeManager()
|
||||
exch, err := em.NewExchangeByName(testExchange)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
exch.SetDefaults()
|
||||
em.Add(exch)
|
||||
err = em.Add(exch)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
|
||||
}
|
||||
b, err := funding.CreateItem(testExchange, a, cp.Base, decimal.Zero, decimal.Zero)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received '%v' expected '%v'", err, nil)
|
||||
@@ -1210,13 +1213,16 @@ func TestProcessFuturesFillEvent(t *testing.T) {
|
||||
ev := &fill.Fill{
|
||||
Base: de.Base,
|
||||
}
|
||||
em := engine.SetupExchangeManager()
|
||||
em := engine.NewExchangeManager()
|
||||
exch, err := em.NewExchangeByName(testExchange)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
exch.SetDefaults()
|
||||
em.Add(exch)
|
||||
err = em.Add(exch)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
|
||||
}
|
||||
b, err := funding.CreateItem(testExchange, a, cp.Base, decimal.Zero, decimal.Zero)
|
||||
if !errors.Is(err, expectedError) {
|
||||
t.Errorf("received '%v' expected '%v'", err, expectedError)
|
||||
|
||||
@@ -33,7 +33,7 @@ func TestSetupLiveDataHandler(t *testing.T) {
|
||||
t.Errorf("received '%v' expected '%v'", err, gctcommon.ErrNilPointer)
|
||||
}
|
||||
|
||||
bt.exchangeManager = engine.SetupExchangeManager()
|
||||
bt.exchangeManager = engine.NewExchangeManager()
|
||||
err = bt.SetupLiveDataHandler(-1, -1, false, false)
|
||||
if !errors.Is(err, gctcommon.ErrNilPointer) {
|
||||
t.Errorf("received '%v' expected '%v'", err, gctcommon.ErrNilPointer)
|
||||
|
||||
@@ -56,7 +56,7 @@ func NewBacktester() (*BackTest, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bt.exchangeManager = engine.SetupExchangeManager()
|
||||
bt.exchangeManager = engine.NewExchangeManager()
|
||||
|
||||
return bt, nil
|
||||
}
|
||||
@@ -166,7 +166,10 @@ func (bt *BackTest) SetupFromConfig(cfg *config.Config, templatePath, output str
|
||||
return err
|
||||
}
|
||||
}
|
||||
bt.exchangeManager.Add(exch)
|
||||
err = bt.exchangeManager.Add(exch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
@@ -824,9 +827,14 @@ func (bt *BackTest) loadData(cfg *config.Config, exch gctexchange.IBotExchange,
|
||||
}
|
||||
case cfg.DataSettings.LiveData != nil:
|
||||
if !b.Features.Enabled.Kline.Intervals.ExchangeSupported(cfg.DataSettings.Interval) {
|
||||
return nil, fmt.Errorf("%w don't trade live on custom candle interval of %v", gctkline.ErrCannotConstructInterval, cfg.DataSettings.Interval)
|
||||
return nil, fmt.Errorf("%w don't trade live on custom candle interval of %v",
|
||||
gctkline.ErrCannotConstructInterval,
|
||||
cfg.DataSettings.Interval)
|
||||
}
|
||||
err = bt.exchangeManager.Add(exch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bt.exchangeManager.Add(exch)
|
||||
err = bt.LiveDataHandler.AppendDataSource(&liveDataSourceSetup{
|
||||
exchange: exch,
|
||||
interval: cfg.DataSettings.Interval,
|
||||
|
||||
Reference in New Issue
Block a user