mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-23 23:16:49 +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:
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/core"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"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/deposit"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
|
||||
@@ -184,32 +184,29 @@ func (w Wrapper) CancelOrder(_ context.Context, exch, orderid string, cp currenc
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// AccountInformation validator for test execution/scripts
|
||||
func (w Wrapper) AccountInformation(_ context.Context, exch string, assetType asset.Item) (account.Holdings, error) {
|
||||
// AccountBalances validator for test execution/scripts
|
||||
func (w Wrapper) AccountBalances(_ context.Context, exch string, assetType asset.Item) (accounts.SubAccounts, error) {
|
||||
if exch == exchError.String() {
|
||||
return account.Holdings{}, errTestFailed
|
||||
return nil, errTestFailed
|
||||
}
|
||||
|
||||
return account.Holdings{
|
||||
Exchange: exch,
|
||||
Accounts: []account.SubAccount{
|
||||
{
|
||||
ID: exch,
|
||||
AssetType: assetType,
|
||||
Currencies: []account.Balance{
|
||||
{
|
||||
Currency: currency.Code{
|
||||
Item: ¤cy.Item{
|
||||
ID: 0,
|
||||
FullName: "Bitcoin",
|
||||
Symbol: "BTC",
|
||||
Role: 1,
|
||||
AssocChain: "",
|
||||
},
|
||||
},
|
||||
Total: 100,
|
||||
Hold: 0,
|
||||
},
|
||||
c := currency.Code{
|
||||
Item: ¤cy.Item{
|
||||
ID: 0,
|
||||
FullName: "Bitcoin",
|
||||
Symbol: "BTC",
|
||||
Role: 1,
|
||||
AssocChain: "",
|
||||
},
|
||||
}
|
||||
return accounts.SubAccounts{
|
||||
{
|
||||
ID: "subacct1",
|
||||
AssetType: assetType,
|
||||
Balances: accounts.CurrencyBalances{
|
||||
c: accounts.Balance{
|
||||
Currency: c,
|
||||
Total: 100,
|
||||
Hold: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
|
||||
@@ -60,20 +62,14 @@ func TestWrapper_IsEnabled(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWrapper_AccountInformation(t *testing.T) {
|
||||
func TestWrapperAccountBalances(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := testWrapper.AccountInformation(t.Context(),
|
||||
exchName, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err := testWrapper.AccountBalances(t.Context(), exchName, asset.Spot)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = testWrapper.AccountInformation(t.Context(),
|
||||
exchError.String(), asset.Spot)
|
||||
if err == nil {
|
||||
t.Fatal("expected AccountInformation to return error on invalid name")
|
||||
}
|
||||
_, err = testWrapper.AccountBalances(t.Context(), exchError.String(), asset.Spot)
|
||||
assert.ErrorIs(t, err, errTestFailed)
|
||||
}
|
||||
|
||||
func TestWrapper_CancelOrder(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user