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

@@ -3,6 +3,7 @@ package huobi
import (
"bytes"
"context"
"encoding/base64"
"errors"
"fmt"
"net/http"
@@ -949,16 +950,12 @@ func (h *HUOBI) SendAuthenticatedHTTPRequest(ctx context.Context, ep exchange.UR
headers["Content-Type"] = "application/json"
}
var hmac []byte
hmac, err = crypto.GetHMAC(crypto.HashSHA256,
[]byte(payload),
[]byte(creds.Secret))
hmac, err := crypto.GetHMAC(crypto.HashSHA256, []byte(payload), []byte(creds.Secret))
if err != nil {
return nil, err
}
values.Set("Signature", crypto.Base64Encode(hmac))
urlPath := ePoint + common.EncodeURLValues(endpoint, values)
values.Set("Signature", base64.StdEncoding.EncodeToString(hmac))
var body []byte
if data != nil {
@@ -970,7 +967,7 @@ func (h *HUOBI) SendAuthenticatedHTTPRequest(ctx context.Context, ep exchange.UR
return &request.Item{
Method: method,
Path: urlPath,
Path: ePoint + common.EncodeURLValues(endpoint, values),
Headers: headers,
Body: bytes.NewReader(body),
Result: &interim,

View File

@@ -3,6 +3,7 @@ package huobi
import (
"bytes"
"context"
"encoding/base64"
"errors"
"fmt"
"io"
@@ -1167,15 +1168,12 @@ func (h *HUOBI) FuturesAuthenticatedHTTPRequest(ctx context.Context, ep exchange
headers["Content-Type"] = "application/json"
}
var hmac []byte
hmac, err = crypto.GetHMAC(crypto.HashSHA256,
[]byte(sigPath),
[]byte(creds.Secret))
hmac, err := crypto.GetHMAC(crypto.HashSHA256, []byte(sigPath), []byte(creds.Secret))
if err != nil {
return nil, err
}
values.Add("Signature", crypto.Base64Encode(hmac))
urlPath := common.EncodeURLValues(ePoint+endpoint, values)
values.Add("Signature", base64.StdEncoding.EncodeToString(hmac))
var body io.Reader
var payload []byte
if data != nil {
@@ -1188,7 +1186,7 @@ func (h *HUOBI) FuturesAuthenticatedHTTPRequest(ctx context.Context, ep exchange
return &request.Item{
Method: method,
Path: urlPath,
Path: common.EncodeURLValues(ePoint+endpoint, values),
Headers: headers,
Body: body,
Result: &tempResp,

View File

@@ -493,9 +493,7 @@ func TestGetOrderHistory(t *testing.T) {
_, err := h.GetOrderHistory(t.Context(), &getOrdersRequest)
require.NoError(t, err)
cp1, err := currency.NewPairFromString("ADA-USD")
require.NoError(t, err)
getOrdersRequest.Pairs = []currency.Pair{cp1}
getOrdersRequest.Pairs = []currency.Pair{btcusdPair}
getOrdersRequest.AssetType = asset.CoinMarginedFutures
_, err = h.GetOrderHistory(t.Context(), &getOrdersRequest)
require.NoError(t, err)
@@ -959,9 +957,7 @@ func TestGetCurrencies(t *testing.T) {
func TestGet24HrMarketSummary(t *testing.T) {
t.Parallel()
cp, err := currency.NewPairFromString("ethusdt")
require.NoError(t, err)
_, err = h.Get24HrMarketSummary(t.Context(), cp)
_, err := h.Get24HrMarketSummary(t.Context(), btcusdtPair)
require.NoError(t, err)
}
@@ -1620,7 +1616,7 @@ func TestStringToOrderType(t *testing.T) {
}
}
func Test_FormatExchangeKlineInterval(t *testing.T) {
func TestFormatExchangeKlineInterval(t *testing.T) {
t.Parallel()
for _, tt := range []struct {
interval kline.Interval

View File

@@ -2,6 +2,7 @@ package huobi
import (
"context"
"encoding/base64"
"errors"
"fmt"
"net/http"
@@ -579,7 +580,6 @@ func (h *HUOBI) wsLogin(ctx context.Context) error {
return err
}
c := h.Websocket.AuthConn
ts := time.Now().UTC().Format(wsDateTimeFormatting)
hmac, err := h.wsGenerateSignature(creds, ts)
if err != nil {
@@ -593,12 +593,12 @@ func (h *HUOBI) wsLogin(ctx context.Context) error {
AccessKey: creds.Key,
SignatureMethod: signatureMethod,
SignatureVersion: signatureVersion,
Signature: crypto.Base64Encode(hmac),
Signature: base64.StdEncoding.EncodeToString(hmac),
Timestamp: ts,
},
}
err = c.SendJSONMessage(context.Background(), request.Unset, req)
if err != nil {
c := h.Websocket.AuthConn
if err := c.SendJSONMessage(context.Background(), request.Unset, req); err != nil {
return err
}
resp := c.ReadMessage()