codebase: Cleanup various things (#1935)

* codebase: Rid base64/hex to string common funcs

* codebase: Rid local scope variable usage and other improvements

* codebase: Refactor currency pair usage across multiple exchanges

- Updated HitBTC tests to use the new currency pair format.
- Modified Kraken futures types to use currency.Pair instead of string for Symbol.
- Adjusted Kraken wrapper methods to handle currency pairs correctly.
- Refined OKX tests and types to utilize currency.Pair for instrument IDs.
- Enhanced Poloniex tests to consistently use predefined currency pairs.
- Streamlined order and orderbook tests to replace string pairs with currency.NewBTCUSD().
- Improved Yobit tests to utilize a standardized currency pair format.
- Updated validator wrapper to use currency pairs directly instead of string conversions.

* codebase: Use types.Number where possible

* refactor: update PayoutFee type to types.Number for consistency

* Refactor: Remove crypto functions to use standard library and other minor changes

- Removed custom crypto functions for SHA256, SHA512, and MD5 from the common/crypto package.
- Replaced usages of removed functions with standard library implementations in various files including:
  - cmd/websocket_client/main.go
  - engine/apiserver.go
  - exchanges/kraken/kraken.go
  - exchanges/lbank/lbank.go
  - exchanges/okx/okx_business_websocket.go
  - exchanges/kucoin/kucoin_websocket.go
  - gctscript/vm/vm.go
- Updated tests to reflect changes in the crypto functions.
- Renamed several functions for clarity, particularly in the context of order book updates across multiple exchanges.

* refactor: replace assert with require for consistency in test assertions

* refactor: Improve Binance futures candlestick test, standardise orderbook update function names and improve test parallelism

* refactor: Replace require.Len with require.Equal for better output in TestGetFuturesKlineData
This commit is contained in:
Adrian Gallagher
2025-06-12 14:12:36 +10:00
committed by GitHub
parent ce134a0a1d
commit d5ba674fc4
115 changed files with 1327 additions and 3112 deletions

View File

@@ -114,12 +114,8 @@ func TestVerify(t *testing.T) {
func TestCalculateTotalBids(t *testing.T) {
t.Parallel()
curr, err := currency.NewPairFromStrings("BTC", "USD")
if err != nil {
t.Fatal(err)
}
base := Base{
Pair: curr,
Pair: currency.NewBTCUSD(),
Bids: []Tranche{{Price: 100, Amount: 10}},
LastUpdated: time.Now(),
}
@@ -132,12 +128,8 @@ func TestCalculateTotalBids(t *testing.T) {
func TestCalculateTotalAsks(t *testing.T) {
t.Parallel()
curr, err := currency.NewPairFromStrings("BTC", "USD")
if err != nil {
t.Fatal(err)
}
base := Base{
Pair: curr,
Pair: currency.NewBTCUSD(),
Asks: []Tranche{{Price: 100, Amount: 10}},
}
@@ -150,9 +142,7 @@ func TestCalculateTotalAsks(t *testing.T) {
func TestGetOrderbook(t *testing.T) {
t.Parallel()
c, err := currency.NewPairFromStrings("BTC", "USD")
require.NoError(t, err, "NewPairFromStrings must not error")
c := currency.NewBTCUSD()
base := &Base{
Pair: c,
Asks: []Tranche{{Price: 100, Amount: 10}},
@@ -174,9 +164,7 @@ func TestGetOrderbook(t *testing.T) {
_, err = Get("Exchange", c, asset.Spot)
assert.ErrorIs(t, err, ErrOrderbookNotFound)
newCurrency, err := currency.NewPairFromStrings("BTC", "AUD")
require.NoError(t, err, "NewPairFromStrings must not error")
newCurrency := currency.NewPair(currency.BTC, currency.AUD)
_, err = Get("Exchange", newCurrency, asset.Spot)
assert.ErrorIs(t, err, ErrOrderbookNotFound)
@@ -191,9 +179,7 @@ func TestGetOrderbook(t *testing.T) {
func TestGetDepth(t *testing.T) {
t.Parallel()
c, err := currency.NewPairFromStrings("BTC", "USD")
require.NoError(t, err, "NewPairFromStrings must not error")
c := currency.NewBTCUSD()
base := &Base{
Pair: c,
Asks: []Tranche{{Price: 100, Amount: 10}},
@@ -215,9 +201,7 @@ func TestGetDepth(t *testing.T) {
_, err = GetDepth("Exchange", c, asset.Spot)
assert.ErrorIs(t, err, ErrOrderbookNotFound)
newCurrency, err := currency.NewPairFromStrings("BTC", "DOGE")
require.NoError(t, err, "NewPairFromStrings must not error")
newCurrency := currency.NewPair(currency.BTC, currency.DOGE)
_, err = GetDepth("Exchange", newCurrency, asset.Futures)
assert.ErrorIs(t, err, ErrOrderbookNotFound)
@@ -231,9 +215,7 @@ func TestGetDepth(t *testing.T) {
func TestBaseGetDepth(t *testing.T) {
t.Parallel()
c, err := currency.NewPairFromStrings("BTC", "UST")
require.NoError(t, err, "NewPairFromStrings must not error")
c := currency.NewPair(currency.BTC, currency.UST)
base := &Base{
Pair: c,
Asks: []Tranche{{Price: 100, Amount: 10}},
@@ -242,7 +224,7 @@ func TestBaseGetDepth(t *testing.T) {
Asset: asset.Spot,
}
_, err = base.GetDepth()
_, err := base.GetDepth()
assert.ErrorIs(t, err, ErrOrderbookNotFound)
require.NoError(t, base.Process(), "Process must not error")
@@ -253,9 +235,8 @@ func TestBaseGetDepth(t *testing.T) {
}
func TestDeployDepth(t *testing.T) {
c, err := currency.NewPairFromStrings("BTC", "USD")
require.NoError(t, err)
_, err = DeployDepth("", c, asset.Spot)
c := currency.NewBTCUSD()
_, err := DeployDepth("", c, asset.Spot)
require.ErrorIs(t, err, errExchangeNameUnset)
_, err = DeployDepth("test", currency.EMPTYPAIR, asset.Spot)
require.ErrorIs(t, err, errPairNotSet)
@@ -269,10 +250,7 @@ func TestDeployDepth(t *testing.T) {
}
func TestCreateNewOrderbook(t *testing.T) {
c, err := currency.NewPairFromStrings("BTC", "USD")
if err != nil {
t.Fatal(err)
}
c := currency.NewBTCUSD()
base := &Base{
Pair: c,
Asks: []Tranche{{Price: 100, Amount: 10}},
@@ -281,10 +259,8 @@ func TestCreateNewOrderbook(t *testing.T) {
Asset: asset.Spot,
}
err = base.Process()
if err != nil {
t.Fatal(err)
}
err := base.Process()
require.NoError(t, err, "Process must not error")
result, err := Get("testCreateNewOrderbook", c, asset.Spot)
if err != nil {
@@ -307,10 +283,6 @@ func TestCreateNewOrderbook(t *testing.T) {
}
func TestProcessOrderbook(t *testing.T) {
c, err := currency.NewPairFromStrings("BTC", "USD")
if err != nil {
t.Fatal(err)
}
base := Base{
Asks: []Tranche{{Price: 100, Amount: 10}},
Bids: []Tranche{{Price: 200, Amount: 10}},
@@ -319,12 +291,11 @@ func TestProcessOrderbook(t *testing.T) {
// test for empty pair
base.Pair = currency.EMPTYPAIR
err = base.Process()
if err == nil {
t.Error("empty pair should throw an err")
}
err := base.Process()
assert.ErrorIs(t, err, errPairNotSet)
// test for empty asset type
c := currency.NewBTCUSD()
base.Pair = c
err = base.Process()
if err == nil {