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

@@ -8,9 +8,10 @@ import (
"github.com/thrasher-corp/gocryptotrader/common/key"
"github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/dispatch"
"github.com/thrasher-corp/gocryptotrader/exchange/accounts"
"github.com/thrasher-corp/gocryptotrader/exchange/order/limits"
"github.com/thrasher-corp/gocryptotrader/exchange/websocket"
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/collateral"
"github.com/thrasher-corp/gocryptotrader/exchanges/currencystate"
@@ -86,7 +87,7 @@ type IBotExchange interface {
GetOrderExecutionLimits(a asset.Item, cp currency.Pair) (limits.MinMaxLevel, error)
CheckOrderExecutionLimits(a asset.Item, cp currency.Pair, price, amount float64, orderType order.Type) error
UpdateOrderExecutionLimits(ctx context.Context, a asset.Item) error
GetCredentials(ctx context.Context) (*account.Credentials, error)
GetCredentials(ctx context.Context) (*accounts.Credentials, error)
EnsureOnePairEnabled() error
PrintEnabledPairs()
IsVerbose() bool
@@ -98,10 +99,10 @@ type IBotExchange interface {
// VerifyAPICredentials determines if the credentials supplied have unset
// required values. See exchanges/credentials.go Base method for
// implementation.
VerifyAPICredentials(creds *account.Credentials) error
VerifyAPICredentials(creds *accounts.Credentials) error
// GetDefaultCredentials returns the exchange.Base api credentials loaded by
// config.json. See exchanges/credentials.go Base method for implementation.
GetDefaultCredentials() *account.Credentials
GetDefaultCredentials() *accounts.Credentials
FunctionalityChecker
AccountManagement
@@ -151,9 +152,11 @@ type CurrencyStateManagement interface {
// AccountManagement defines functionality for exchange account management
type AccountManagement interface {
UpdateAccountInfo(ctx context.Context, a asset.Item) (account.Holdings, error)
GetCachedAccountInfo(ctx context.Context, a asset.Item) (account.Holdings, error)
UpdateAccountBalances(ctx context.Context, a asset.Item) (accounts.SubAccounts, error)
GetCachedSubAccounts(ctx context.Context, a asset.Item) (accounts.SubAccounts, error)
GetCachedCurrencyBalances(ctx context.Context, a asset.Item) (accounts.CurrencyBalances, error)
HasAssetTypeAccountSegregation() bool
SubscribeAccountBalances() (dispatch.Pipe, error)
}
// FunctionalityChecker defines functionality for retrieving exchange