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

@@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
"github.com/thrasher-corp/gocryptotrader/exchange/accounts"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
"github.com/thrasher-corp/gocryptotrader/gctscript/modules"
@@ -103,16 +103,16 @@ func TestExchangePairs(t *testing.T) {
assert.ErrorIs(t, err, objects.ErrWrongNumArguments)
}
func TestAccountInfo(t *testing.T) {
func TestAccountBalances(t *testing.T) {
t.Parallel()
_, err := ExchangeAccountInfo()
_, err := ExchangeAccountBalances()
assert.ErrorIs(t, err, objects.ErrWrongNumArguments)
_, err = ExchangeAccountInfo(ctx, exch, assetType)
_, err = ExchangeAccountBalances(ctx, exch, assetType)
assert.NoError(t, err)
_, err = ExchangeAccountInfo(ctx, exchError, assetType)
_, err = ExchangeAccountBalances(ctx, exchError, assetType)
assert.NoError(t, err)
}
@@ -391,7 +391,7 @@ func TestSetSubAccount(t *testing.T) {
t.Fatal("should not be nil")
}
subaccount, ok := ctx.Value(account.ContextSubAccountFlag).(string)
subaccount, ok := ctx.Value(accounts.ContextSubAccountFlag).(string)
if !ok {
t.Fatal("wrong type")
}