mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-14 07:26:47 +00:00
* Engine: Fix false test passes for nil OrderManager TestWebsocketRoutineManagerSetup tests that passing a nil value returns errNilOrderManager; However that's not actually what would happen when order manager is configured off. The arguments to setupWebsocketRoutineManager are interface types. When a nil pointer of interface type is passed, it does NOT equal nil. nil is a primitive type. A nil pointer of interface type has the value (nil;type). See [the Go lang spec](https://golang.org/ref/spec#Comparison_operators): ``` Interface values are comparable. Two interface values are equal if they have identical dynamic types and equal dynamic values or if both have value nil. ``` So that means that whilst this test was passing, because it was sending in a real nil value and comparing it to a real nil, that's not what would happen at runtime. At runtime the bot.OrderManager would be a nil pointer to a concrete type *OrderManager, and so not comparible to nil. This commit just fixes that oversight, and explains the often misunderstood mechanics of comparing interface types to nil. In practical terms this means that the tests assert that the WSRM would not run without a OM, but in fact it actually would. And panic later. This commit SHOULD introduce a FAILing test. Sorry if you're bisecting. * WSM: Fix error on OrderManager not enabled It's okay for OrderManager to not be enabled; It's configurable. Remove the WSM setup protection and move it to runtime using IsRunning. Left the WSM deps so they can be fixed as apporpriate to each.
88 lines
3.3 KiB
Go
88 lines
3.3 KiB
Go
package engine
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/thrasher-corp/gocryptotrader/communications/base"
|
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
|
"github.com/thrasher-corp/gocryptotrader/database"
|
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
|
"github.com/thrasher-corp/gocryptotrader/portfolio"
|
|
)
|
|
|
|
const (
|
|
// MsgSubSystemStarting message to return when subsystem is starting up
|
|
MsgSubSystemStarting = "starting..."
|
|
// MsgSubSystemStarted message to return when subsystem has started
|
|
MsgSubSystemStarted = "started."
|
|
// MsgSubSystemShuttingDown message to return when a subsystem is shutting down
|
|
MsgSubSystemShuttingDown = "shutting down..."
|
|
// MsgSubSystemShutdown message to return when a subsystem has shutdown
|
|
MsgSubSystemShutdown = "shutdown."
|
|
)
|
|
|
|
var (
|
|
// ErrSubSystemAlreadyStarted message to return when a subsystem is already started
|
|
ErrSubSystemAlreadyStarted = errors.New("subsystem already started")
|
|
// ErrSubSystemNotStarted message to return when subsystem not started
|
|
ErrSubSystemNotStarted = errors.New("subsystem not started")
|
|
// ErrNilSubsystem is returned when a subsystem hasn't had its Setup() func run
|
|
ErrNilSubsystem = errors.New("subsystem not setup")
|
|
errNilWaitGroup = errors.New("nil wait group received")
|
|
errNilExchangeManager = errors.New("cannot start with nil exchange manager")
|
|
errNilDatabaseConnectionManager = errors.New("cannot start with nil database connection manager")
|
|
errNilConfig = errors.New("received nil config")
|
|
)
|
|
|
|
// iExchangeManager limits exposure of accessible functions to exchange manager
|
|
// so that subsystems can use some functionality
|
|
type iExchangeManager interface {
|
|
GetExchanges() ([]exchange.IBotExchange, error)
|
|
GetExchangeByName(string) (exchange.IBotExchange, error)
|
|
}
|
|
|
|
// iCommsManager limits exposure of accessible functions to communication manager
|
|
type iCommsManager interface {
|
|
PushEvent(evt base.Event)
|
|
}
|
|
|
|
// iOrderManager defines a limited scoped order manager
|
|
type iOrderManager interface {
|
|
IsRunning() bool
|
|
Exists(*order.Detail) bool
|
|
Add(*order.Detail) error
|
|
Cancel(context.Context, *order.Cancel) error
|
|
GetByExchangeAndID(string, string) (*order.Detail, error)
|
|
UpdateExistingOrder(*order.Detail) error
|
|
}
|
|
|
|
// iPortfolioManager limits exposure of accessible functions to portfolio manager
|
|
type iPortfolioManager interface {
|
|
GetPortfolioSummary() portfolio.Summary
|
|
IsWhiteListed(string) bool
|
|
IsExchangeSupported(string, string) bool
|
|
}
|
|
|
|
// iBot limits exposure of accessible functions to engine bot
|
|
type iBot interface {
|
|
SetupExchanges() error
|
|
}
|
|
|
|
// iCurrencyPairSyncer defines a limited scoped currency pair syncer
|
|
type iCurrencyPairSyncer interface {
|
|
IsRunning() bool
|
|
PrintTickerSummary(*ticker.Price, string, error)
|
|
PrintOrderbookSummary(*orderbook.Base, string, error)
|
|
WebsocketUpdate(string, currency.Pair, asset.Item, syncItemType, error) error
|
|
}
|
|
|
|
// iDatabaseConnectionManager defines a limited scoped databaseConnectionManager
|
|
type iDatabaseConnectionManager interface {
|
|
GetInstance() database.IDatabase
|
|
}
|