Skip to content

Commit

Permalink
WSM: Fix error on OrderManager not enabled
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gbjk committed Sep 8, 2023
1 parent aa00f10 commit 945e56c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
1 change: 1 addition & 0 deletions engine/subsystem_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type iCommsManager interface {

// 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
Expand Down
9 changes: 6 additions & 3 deletions engine/websocketroutine_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ func setupWebsocketRoutineManager(exchangeManager iExchangeManager, orderManager
if exchangeManager == nil {
return nil, errNilExchangeManager
}
if orderManager == nil {
return nil, errNilOrderManager
}
if syncer == nil {
return nil, errNilCurrencyPairSyncer
}
Expand Down Expand Up @@ -287,6 +284,9 @@ func (m *WebsocketRoutineManager) websocketDataHandler(exchName string, data int
}
m.syncer.PrintOrderbookSummary(base, "websocket", nil)
case *order.Detail:
if !m.orderManager.IsRunning() {
return nil
}
if !m.orderManager.Exists(d) {
err := m.orderManager.Add(d)
if err != nil {
Expand All @@ -310,6 +310,9 @@ func (m *WebsocketRoutineManager) websocketDataHandler(exchName string, data int
m.printOrderSummary(od, true)
}
case []order.Detail:
if !m.orderManager.IsRunning() {
return nil
}
for x := range d {
if !m.orderManager.Exists(&d[x]) {
err := m.orderManager.Add(&d[x])
Expand Down
5 changes: 0 additions & 5 deletions engine/websocketroutine_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ func TestWebsocketRoutineManagerSetup(t *testing.T) {
}

_, err = setupWebsocketRoutineManager(NewExchangeManager(), (*OrderManager)(nil), nil, nil, false)
if !errors.Is(err, errNilOrderManager) {
t.Errorf("error '%v', expected '%v'", err, errNilOrderManager)
}

_, err = setupWebsocketRoutineManager(NewExchangeManager(), &OrderManager{}, nil, nil, false)
if !errors.Is(err, errNilCurrencyPairSyncer) {
t.Errorf("error '%v', expected '%v'", err, errNilCurrencyPairSyncer)
}
Expand Down
1 change: 0 additions & 1 deletion engine/websocketroutine_manager_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
)

var (
errNilOrderManager = errors.New("nil order manager received")
errNilCurrencyPairSyncer = errors.New("nil currency pair syncer received")
errNilCurrencyConfig = errors.New("nil currency config received")
errNilCurrencyPairFormat = errors.New("nil currency pair format received")
Expand Down

0 comments on commit 945e56c

Please sign in to comment.