mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-06 15:10:59 +00:00
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:
@@ -2,6 +2,7 @@ package yobit
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -310,16 +311,14 @@ func (y *Yobit) SendAuthenticatedHTTPRequest(ctx context.Context, ep exchange.UR
|
||||
params.Set("method", path)
|
||||
|
||||
encoded := params.Encode()
|
||||
hmac, err := crypto.GetHMAC(crypto.HashSHA512,
|
||||
[]byte(encoded),
|
||||
[]byte(creds.Secret))
|
||||
hmac, err := crypto.GetHMAC(crypto.HashSHA512, []byte(encoded), []byte(creds.Secret))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
headers := make(map[string]string)
|
||||
headers["Key"] = creds.Key
|
||||
headers["Sign"] = crypto.HexEncodeToString(hmac)
|
||||
headers["Sign"] = hex.EncodeToString(hmac)
|
||||
headers["Content-Type"] = "application/x-www-form-urlencoded"
|
||||
|
||||
return &request.Item{
|
||||
|
||||
@@ -30,6 +30,8 @@ const (
|
||||
canManipulateRealOrders = false
|
||||
)
|
||||
|
||||
var testPair = currency.NewBTCUSD().Format(currency.PairFormat{Delimiter: "_"})
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
y.SetDefaults()
|
||||
yobitConfig := config.GetConfig()
|
||||
@@ -71,26 +73,20 @@ func TestGetInfo(t *testing.T) {
|
||||
|
||||
func TestGetTicker(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := y.GetTicker(t.Context(), "btc_usd")
|
||||
if err != nil {
|
||||
t.Error("GetTicker() error", err)
|
||||
}
|
||||
_, err := y.GetTicker(t.Context(), testPair.String())
|
||||
assert.NoError(t, err, "GetTicker should not error")
|
||||
}
|
||||
|
||||
func TestGetDepth(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := y.GetDepth(t.Context(), "btc_usd")
|
||||
if err != nil {
|
||||
t.Error("GetDepth() error", err)
|
||||
}
|
||||
_, err := y.GetDepth(t.Context(), testPair.String())
|
||||
assert.NoError(t, err, "GetDepth should not error")
|
||||
}
|
||||
|
||||
func TestGetTrades(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := y.GetTrades(t.Context(), "btc_usd")
|
||||
if err != nil {
|
||||
t.Error("GetTrades() error", err)
|
||||
}
|
||||
_, err := y.GetTrades(t.Context(), testPair.String())
|
||||
assert.NoError(t, err, "GetTrades should not error")
|
||||
}
|
||||
|
||||
func TestGetAccountInfo(t *testing.T) {
|
||||
@@ -507,38 +503,19 @@ func TestGetDepositAddress(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetRecentTrades(t *testing.T) {
|
||||
currencyPair, err := currency.NewPairFromString("btc_usd")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = y.GetRecentTrades(t.Context(), currencyPair, asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err := y.GetRecentTrades(t.Context(), testPair, asset.Spot)
|
||||
assert.NoError(t, err, "GetRecentTrades should not error")
|
||||
}
|
||||
|
||||
func TestGetHistoricTrades(t *testing.T) {
|
||||
currencyPair, err := currency.NewPairFromString("btc_usd")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = y.GetHistoricTrades(t.Context(),
|
||||
currencyPair, asset.Spot, time.Now().Add(-time.Minute*15), time.Now())
|
||||
if err != nil && err != common.ErrFunctionNotSupported {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err := y.GetHistoricTrades(t.Context(), testPair, asset.Spot, time.Now().Add(-time.Minute*15), time.Now())
|
||||
assert.ErrorIs(t, err, common.ErrFunctionNotSupported)
|
||||
}
|
||||
|
||||
func TestUpdateTicker(t *testing.T) {
|
||||
t.Parallel()
|
||||
cp, err := currency.NewPairFromString("ETH_BTC")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = y.UpdateTicker(t.Context(), cp, asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err := y.UpdateTicker(t.Context(), testPair, asset.Spot)
|
||||
assert.NoError(t, err, "UpdateTicker should not error")
|
||||
}
|
||||
|
||||
func TestUpdateTickers(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user