Files
gocryptotrader/exchanges/bybit/bybit_mock_test.go
Samuael A fb6d12ac69 exchanges: Update Bybit exchange to V5 (#1301)
* Adding Bybit public endpoints

* Completed adding market endpoints

* Added trade endpoints

* Adding position endpoints

* completing position endpoints

* Adding Pre-upgrade endpoints

* Completed adding Pre-upgrade and Account endpoints

* Added asset endpoints

* Added user endpoints and unit tests

* Adding spot leverage and margin trade endpoints

* spot margin trade added

* added spot-margin-trade, institutional lending, c2c lending, and broker

* Adding wrapper funnctions

* Working on wrapper public methods

* Added wrapper functions and unit tests

* Added websocket support with unit tests

* Update websocket handlers and added rate-limiter

* wrapper function, websocket handlers, and linter issues fixe

* unit tests fixes and codespell correction

* Update documentation

* Minor websocket handling fix and URL consts merging

* types, unit test other updates

* Updated websocket and methods based on review

* Added GetFeeByType method with unit test and fixes

* add filter for Unified and Normal endpoints

* Mock recording and unit tests update

* minor linter issue fix

* websocket and rest tests and fix

* change asset types and wrapper methods update

* rm: forgotten panic message

* endpoints, websocket  and unit tests update

* Added and updated endpoints and unit test

* linter and spell fix

* unit test and orders update

* Update on endpoints, fields, config pairs and formating, and unit tests

* minor update on responses

* Fix unit test and types

* Unit tests, models, and wrapper issues fix and mock test recording

* rm print statement

* Fix issue, add FundingRate wrapper func, mock record

* minor type and unit test update

* Update on order handling and unit test

* Minor test

* Minor fix in wrapper

* unit tests update, recording, and documentation update

* Unit tests and minor wrapper function update

* minor unit test fix

* Added newly added endpoints, unit tests, and mock recording

* Rename GetInstruments -> GetInstrumentInfo

* doc update

* Minor unit tests update

* Minor unit test and wrapper update

* Fix linter issue

* Add unit test and minor updates

* Revert websocket error declaration

* Revert websocket error declaration

* Balace --> Balance

* Fix config issues

* Added next funding time minor fix

* Update GetLatestFundingRates and record mock test data

* Added LatestFundingRate time

* Fix test issue of TestAllExchangeWrappers

* config pairs update

* configtest spot pairs update

* Minor update on options UpdateOrderExecutionLimits wrapper func

* Linter issue fix and added new currency codes

* Added new currency codes

* Update bybit pairs in config_example

* config assets pair format update
2024-01-11 12:35:46 +11:00

108 lines
3.4 KiB
Go

//go:build !mock_test_off
// This will build if build tag mock_test_off is not parsed and will try to mock
// all tests in _test.go
package bybit
import (
"context"
"log"
"os"
"testing"
"github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/mock"
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
)
const mockfile = "../../testdata/http_mock/bybit/bybit.json"
var mockTests = true
func TestMain(m *testing.M) {
b.SetDefaults()
cfg := config.GetConfig()
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatal(err)
}
bybitConfig, err := cfg.GetExchangeConfig("Bybit")
if err != nil {
log.Fatal("Bybit Setup() init error", err)
}
b.SkipAuthCheck = true
request.MaxRequestJobs = 100
bybitConfig.API.Credentials.Key = apiKey
bybitConfig.API.Credentials.Secret = apiSecret
bybitConfig.API.AuthenticatedSupport = true
bybitConfig.API.AuthenticatedWebsocketSupport = true
b.Websocket = sharedtestvalues.NewTestWebsocket()
err = b.Setup(bybitConfig)
if err != nil {
log.Fatal("Bybit setup error", err)
}
serverDetails, newClient, err := mock.NewVCRServer(mockfile)
if err != nil {
log.Fatalf("Mock server error %s", err)
}
err = b.SetHTTPClient(newClient)
if err != nil {
log.Fatalf("Mock server error %s", err)
}
endpointMap := b.API.Endpoints.GetURLMap()
for k := range endpointMap {
err = b.API.Endpoints.SetRunning(k, serverDetails)
if err != nil {
log.Fatal(err)
}
}
request.MaxRequestJobs = 100
err = b.UpdateTradablePairs(context.Background(), true)
if err != nil {
log.Fatal("Bybit setup error", err)
}
spotTradablePair = currency.Pair{Base: currency.BTC, Quote: currency.USDT}
okay, err := b.IsPairEnabled(spotTradablePair, asset.Spot)
if !okay || err != nil {
err = b.CurrencyPairs.EnablePair(asset.Spot, spotTradablePair)
if err != nil {
log.Fatal(err)
}
}
usdtMarginedTradablePair = currency.Pair{Base: currency.NewCode("10000LADYS"), Quote: currency.USDT}
if okay, err = b.IsPairEnabled(usdtMarginedTradablePair, asset.USDTMarginedFutures); !okay || err != nil {
err = b.CurrencyPairs.EnablePair(asset.USDTMarginedFutures, usdtMarginedTradablePair)
if err != nil {
log.Fatal(err)
}
}
usdcMarginedTradablePair = currency.Pair{Base: currency.ETH, Quote: currency.PERP}
if okay, err = b.IsPairEnabled(usdcMarginedTradablePair, asset.USDCMarginedFutures); !okay || err != nil {
err = b.CurrencyPairs.EnablePair(asset.USDCMarginedFutures, usdcMarginedTradablePair)
if err != nil {
log.Fatal(err)
}
}
inverseTradablePair = currency.Pair{Base: currency.ADA, Quote: currency.USD}
if okay, err = b.IsPairEnabled(inverseTradablePair, asset.CoinMarginedFutures); !okay || err != nil {
err = b.CurrencyPairs.EnablePair(asset.CoinMarginedFutures, inverseTradablePair)
if err != nil {
log.Fatal(err)
}
}
optionsTradablePair = currency.Pair{Base: currency.BTC, Delimiter: currency.DashDelimiter, Quote: currency.NewCode("29DEC23-80000-C")}
if okay, err = b.IsPairEnabled(optionsTradablePair, asset.Options); !okay || err != nil {
err = b.CurrencyPairs.EnablePair(asset.Options, optionsTradablePair)
if err != nil {
log.Fatal(err)
}
}
os.Exit(m.Run())
}