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

@@ -141,8 +141,7 @@ func (b *Base) ExchangeExists(exchangeName string) bool {
})
}
// AddressExists checks to see if there is an address associated with the
// portfolio base
// AddressExists checks to see if there is an address associated with the portfolio base
func (b *Base) AddressExists(address string) bool {
b.mtx.RLock()
defer b.mtx.RUnlock()
@@ -181,7 +180,7 @@ func (b *Base) AddExchangeAddress(exchangeName string, coinType currency.Code, b
})
}
// UpdateAddressBalance updates the portfolio base balance
// UpdateAddressBalance updates the portfolio base balance.
func (b *Base) UpdateAddressBalance(address string, amount float64) {
b.mtx.Lock()
defer b.mtx.Unlock()
@@ -203,8 +202,7 @@ func (b *Base) RemoveExchangeAddress(exchangeName string, coinType currency.Code
}))
}
// UpdateExchangeAddressBalance updates the portfolio balance when checked
// against correct exchangeName and coinType.
// UpdateExchangeAddressBalance updates the portfolio balance when checked against correct exchangeName and coinType.
func (b *Base) UpdateExchangeAddressBalance(exchangeName string, coinType currency.Code, balance float64) {
b.mtx.Lock()
defer b.mtx.Unlock()
@@ -216,7 +214,7 @@ func (b *Base) UpdateExchangeAddressBalance(exchangeName string, coinType curren
}
}
// AddAddress adds an address to the portfolio base or updates its balance if it already exists
// AddAddress adds an address to the portfolio base or updates its balance if it already exists.
func (b *Base) AddAddress(address, description string, coinType currency.Code, balance float64) error {
if address == "" {
return common.ErrAddressIsEmptyOrInvalid