mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-31 15:10:42 +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:
@@ -29,7 +29,6 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/database"
|
||||
"github.com/thrasher-corp/gocryptotrader/dispatch"
|
||||
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/protocol"
|
||||
@@ -707,67 +706,6 @@ func TestGetExchangeNamesByCurrency(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCollatedExchangeAccountInfoByCoin(t *testing.T) {
|
||||
t.Parallel()
|
||||
CreateTestBot(t)
|
||||
|
||||
var exchangeInfo []account.Holdings
|
||||
|
||||
var bitfinexHoldings account.Holdings
|
||||
bitfinexHoldings.Exchange = "Bitfinex"
|
||||
bitfinexHoldings.Accounts = append(bitfinexHoldings.Accounts,
|
||||
account.SubAccount{
|
||||
Currencies: []account.Balance{
|
||||
{
|
||||
Currency: currency.BTC,
|
||||
Total: 100,
|
||||
Hold: 0,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
exchangeInfo = append(exchangeInfo, bitfinexHoldings)
|
||||
|
||||
var bitstampHoldings account.Holdings
|
||||
bitstampHoldings.Exchange = testExchange
|
||||
bitstampHoldings.Accounts = append(bitstampHoldings.Accounts,
|
||||
account.SubAccount{
|
||||
Currencies: []account.Balance{
|
||||
{
|
||||
Currency: currency.LTC,
|
||||
Total: 100,
|
||||
Hold: 0,
|
||||
},
|
||||
{
|
||||
Currency: currency.BTC,
|
||||
Total: 100,
|
||||
Hold: 0,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
exchangeInfo = append(exchangeInfo, bitstampHoldings)
|
||||
|
||||
result := GetCollatedExchangeAccountInfoByCoin(exchangeInfo)
|
||||
if len(result) == 0 {
|
||||
t.Fatal("Unexpected result")
|
||||
}
|
||||
|
||||
amount, ok := result[currency.BTC]
|
||||
if !ok {
|
||||
t.Fatal("Expected currency was not found in result map")
|
||||
}
|
||||
|
||||
if amount.Total != 200 {
|
||||
t.Fatal("Unexpected result")
|
||||
}
|
||||
|
||||
_, ok = result[currency.ETH]
|
||||
if ok {
|
||||
t.Fatal("Unexpected result")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetExchangeHighestPriceByCurrencyPair(t *testing.T) {
|
||||
t.Parallel()
|
||||
CreateTestBot(t)
|
||||
|
||||
Reference in New Issue
Block a user