mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-20 15:10:10 +00:00
* 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
75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
//go:build mock_test_off
|
|
|
|
// This will build if build tag mock_test_off is parsed and will do live testing
|
|
// using all tests in (exchange)_test.go
|
|
package bybit
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
|
testexch "github.com/thrasher-corp/gocryptotrader/internal/testing/exchange"
|
|
)
|
|
|
|
var mockTests = false
|
|
|
|
func TestMain(m *testing.M) {
|
|
e = testInstance()
|
|
|
|
if e.API.AuthenticatedSupport {
|
|
if _, err := e.FetchAccountType(context.Background()); err != nil {
|
|
log.Printf("%s unable to FetchAccountType: %v", e.Name, err)
|
|
}
|
|
}
|
|
|
|
instantiateTradablePairs()
|
|
|
|
os.Exit(m.Run())
|
|
}
|
|
|
|
func testInstance() *Bybit {
|
|
e := new(Exchange)
|
|
if err := testexch.Setup(e); err != nil {
|
|
log.Fatalf("Bybit Setup error: %s", err)
|
|
}
|
|
|
|
if apiKey != "" && apiSecret != "" {
|
|
e.API.AuthenticatedSupport = true
|
|
e.API.AuthenticatedWebsocketSupport = true
|
|
e.SetCredentials(apiKey, apiSecret, "", "", "", "")
|
|
e.Websocket.SetCanUseAuthenticatedEndpoints(true)
|
|
}
|
|
return e
|
|
}
|
|
|
|
func instantiateTradablePairs() {
|
|
handleError := func(msg string, err error) {
|
|
if err != nil {
|
|
log.Fatalf("Bybit %s: %v", msg, err)
|
|
}
|
|
}
|
|
|
|
err := e.UpdateTradablePairs(context.Background())
|
|
handleError("unable to UpdateTradablePairs", err)
|
|
|
|
setTradablePair := func(assetType asset.Item, p *currency.Pair) {
|
|
tradables, err := e.GetEnabledPairs(assetType)
|
|
handleError("unable to GetEnabledPairs", err)
|
|
|
|
format, err := e.GetPairFormat(assetType, true)
|
|
handleError("unable to GetPairFormat", err)
|
|
|
|
*p = tradables[0].Format(format)
|
|
}
|
|
|
|
setTradablePair(asset.Spot, &spotTradablePair)
|
|
setTradablePair(asset.USDTMarginedFutures, &usdtMarginedTradablePair)
|
|
setTradablePair(asset.USDCMarginedFutures, &usdcMarginedTradablePair)
|
|
setTradablePair(asset.CoinMarginedFutures, &inverseTradablePair)
|
|
setTradablePair(asset.Options, &optionsTradablePair)
|
|
}
|