accounts: Move to instance methods, fix races and isolate tests (#1923)

* Bybit: Fix race in TestUpdateAccountInfo and  TestWSHandleData

* DriveBy rename TestWSHandleData
* This doesn't address running with -race=2+ due to the singleton

* Accounts: Add account.GetService()

* exchange: Assertify TestSetupDefaults

* Exchanges: Add account.Service override for testing

* Exchanges: Remove duplicate IsWebsocketEnabled test from TestSetupDefaults

* Dispatch: Replace nil checks with NilGuard

* Engine: Remove deprecated printAccountHoldingsChangeSummary

* Dispatcher: Add EnsureRunning method

* Accounts: Move singleton accounts service to exchange Accounts

* Move singleton accounts service to exchange Accounts

This maintains the concept of a global store, whilst allowing exchanges
to override it when needed, particularly for testing.

APIServer:

* Remove getAllActiveAccounts from apiserver

Deprecated apiserver only thing using this, so remove it instead of
updating it

* Update comment for UpdateAccountBalances everywhere

* Docs: Add punctuation to function comments

* Bybit: Coverage for wsProcessWalletPushData Save
This commit is contained in:
Gareth Kirwan
2025-10-28 09:52:45 +07:00
committed by GitHub
parent bda9bbec66
commit 73e200e4e7
140 changed files with 3515 additions and 4025 deletions

View File

@@ -7,8 +7,8 @@ import (
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/exchange/accounts"
"github.com/thrasher-corp/gocryptotrader/exchange/websocket"
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
"github.com/thrasher-corp/gocryptotrader/exchanges/fill"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
@@ -329,15 +329,9 @@ func (m *WebsocketRoutineManager) websocketDataHandler(exchName string, data any
return fmt.Errorf("%w %s", d.Err, d.Error())
case websocket.UnhandledMessageWarning:
log.Warnf(log.WebsocketMgr, "%s unhandled message - %s", exchName, d.Message)
case account.Change:
case []accounts.Change, accounts.Change:
if m.verbose {
m.printAccountHoldingsChangeSummary(exchName, d)
}
case []account.Change:
if m.verbose {
for x := range d {
m.printAccountHoldingsChangeSummary(exchName, d[x])
}
log.Debugf(log.WebsocketMgr, "%s %+v", exchName, d)
}
case []trade.Data, trade.Data:
if m.verbose {
@@ -349,10 +343,7 @@ func (m *WebsocketRoutineManager) websocketDataHandler(exchName string, data any
}
default:
if m.verbose {
log.Warnf(log.WebsocketMgr,
"%s websocket Unknown type: %+v",
exchName,
d)
log.Warnf(log.WebsocketMgr, "%s websocket Unknown type: %+v", exchName, d)
}
}
return nil
@@ -396,21 +387,6 @@ func (m *WebsocketRoutineManager) printOrderSummary(o *order.Detail, isUpdate bo
o.RemainingAmount)
}
// printAccountHoldingsChangeSummary this function will be deprecated when a
// account holdings update is done.
func (m *WebsocketRoutineManager) printAccountHoldingsChangeSummary(exch string, o account.Change) {
if m == nil || atomic.LoadInt32(&m.state) == stoppedState || o.Balance == nil {
return
}
log.Debugf(log.WebsocketMgr,
"Account Holdings Balance Changed: %s %s %s has changed balance by %f for account: %s",
exch,
o.AssetType,
o.Balance.Currency,
o.Balance.Total,
o.Account)
}
// registerWebsocketDataHandler registers an externally (GCT Library) defined
// dedicated filter specific data types for internal & external strategy use.
// InterceptorOnly as true will purge all other registered handlers