mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-07 15:11:03 +00:00
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:
@@ -9,8 +9,8 @@ import (
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/engine"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchange/accounts"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/deposit"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
|
||||
@@ -130,16 +130,16 @@ func (e Exchange) CancelOrder(ctx context.Context, exch, orderID string, cp curr
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// AccountInformation returns account information (balance etc) for requested exchange
|
||||
func (e Exchange) AccountInformation(ctx context.Context, exch string, assetType asset.Item) (account.Holdings, error) {
|
||||
// AccountBalances returns account balances for requested exchange
|
||||
func (e Exchange) AccountBalances(ctx context.Context, exch string, assetType asset.Item) (accounts.SubAccounts, error) {
|
||||
ex, err := e.GetExchange(exch)
|
||||
if err != nil {
|
||||
return account.Holdings{}, err
|
||||
return accounts.SubAccounts{}, err
|
||||
}
|
||||
|
||||
accountInfo, err := ex.GetCachedAccountInfo(ctx, assetType)
|
||||
accountInfo, err := ex.GetCachedSubAccounts(ctx, assetType)
|
||||
if err != nil {
|
||||
return account.Holdings{}, err
|
||||
return accounts.SubAccounts{}, err
|
||||
}
|
||||
|
||||
return accountInfo, nil
|
||||
|
||||
@@ -119,11 +119,11 @@ func TestExchange_Pairs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestExchange_AccountInformation(t *testing.T) {
|
||||
func TestExchange_AccountBalances(t *testing.T) {
|
||||
if !configureExchangeKeys() {
|
||||
t.Skip("no exchange configured test skipped")
|
||||
}
|
||||
_, err := exchangeTest.AccountInformation(t.Context(),
|
||||
_, err := exchangeTest.AccountBalances(t.Context(),
|
||||
exchName, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -159,14 +159,14 @@ func TestExchangePairs(t *testing.T) {
|
||||
assert.ErrorIs(t, err, objects.ErrWrongNumArguments)
|
||||
}
|
||||
|
||||
func TestExchangeAccountInfo(t *testing.T) {
|
||||
func TestExchangeAccountBalances(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := gct.ExchangeAccountInfo()
|
||||
_, err := gct.ExchangeAccountBalances()
|
||||
require.ErrorIs(t, err, objects.ErrWrongNumArguments)
|
||||
obj, err := gct.ExchangeAccountInfo(ctx, exch, assetType)
|
||||
obj, err := gct.ExchangeAccountBalances(ctx, exch, assetType)
|
||||
require.NoError(t, err)
|
||||
rString, ok := objects.ToString(obj)
|
||||
require.True(t, ok, "ExchangeAccountInfo return value must return correctly from objects.ToString")
|
||||
require.True(t, ok, "ExchangeAccountBalances return value must return correctly from objects.ToString")
|
||||
require.Contains(t, rString, "Bitstamp REST or Websocket authentication support is not enabled")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user