mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-30 23:16:52 +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,8 @@ package gemini
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
@@ -428,15 +430,13 @@ func (g *Gemini) SendAuthenticatedHTTPRequest(ctx context.Context, ep exchange.U
|
||||
|
||||
maps.Copy(req, params)
|
||||
|
||||
PayloadJSON, err := json.Marshal(req)
|
||||
payload, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
PayloadBase64 := crypto.Base64Encode(PayloadJSON)
|
||||
hmac, err := crypto.GetHMAC(crypto.HashSHA512_384,
|
||||
[]byte(PayloadBase64),
|
||||
[]byte(creds.Secret))
|
||||
payloadB64 := base64.StdEncoding.EncodeToString(payload)
|
||||
hmac, err := crypto.GetHMAC(crypto.HashSHA512_384, []byte(payloadB64), []byte(creds.Secret))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -445,8 +445,8 @@ func (g *Gemini) SendAuthenticatedHTTPRequest(ctx context.Context, ep exchange.U
|
||||
headers["Content-Length"] = "0"
|
||||
headers["Content-Type"] = "text/plain"
|
||||
headers["X-GEMINI-APIKEY"] = creds.Key
|
||||
headers["X-GEMINI-PAYLOAD"] = PayloadBase64
|
||||
headers["X-GEMINI-SIGNATURE"] = crypto.HexEncodeToString(hmac)
|
||||
headers["X-GEMINI-PAYLOAD"] = payloadB64
|
||||
headers["X-GEMINI-SIGNATURE"] = hex.EncodeToString(hmac)
|
||||
headers["Cache-Control"] = "no-cache"
|
||||
|
||||
return &request.Item{
|
||||
|
||||
@@ -4,6 +4,8 @@ package gemini
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -140,7 +142,7 @@ func (g *Gemini) WsAuth(ctx context.Context, dialer *gws.Dialer) error {
|
||||
Request: "/v1/" + geminiWsOrderEvents,
|
||||
Nonce: time.Now().UnixNano(),
|
||||
}
|
||||
PayloadJSON, err := json.Marshal(payload)
|
||||
payloadJSON, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v sendAuthenticatedHTTPRequest: Unable to JSON request", g.Name)
|
||||
}
|
||||
@@ -149,10 +151,8 @@ func (g *Gemini) WsAuth(ctx context.Context, dialer *gws.Dialer) error {
|
||||
return err
|
||||
}
|
||||
endpoint := wsEndpoint + geminiWsOrderEvents
|
||||
PayloadBase64 := crypto.Base64Encode(PayloadJSON)
|
||||
hmac, err := crypto.GetHMAC(crypto.HashSHA512_384,
|
||||
[]byte(PayloadBase64),
|
||||
[]byte(creds.Secret))
|
||||
payloadB64 := base64.StdEncoding.EncodeToString(payloadJSON)
|
||||
hmac, err := crypto.GetHMAC(crypto.HashSHA512_384, []byte(payloadB64), []byte(creds.Secret))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -160,9 +160,9 @@ func (g *Gemini) WsAuth(ctx context.Context, dialer *gws.Dialer) error {
|
||||
headers := http.Header{}
|
||||
headers.Add("Content-Length", "0")
|
||||
headers.Add("Content-Type", "text/plain")
|
||||
headers.Add("X-GEMINI-PAYLOAD", PayloadBase64)
|
||||
headers.Add("X-GEMINI-PAYLOAD", payloadB64)
|
||||
headers.Add("X-GEMINI-APIKEY", creds.Key)
|
||||
headers.Add("X-GEMINI-SIGNATURE", crypto.HexEncodeToString(hmac))
|
||||
headers.Add("X-GEMINI-SIGNATURE", hex.EncodeToString(hmac))
|
||||
headers.Add("Cache-Control", "no-cache")
|
||||
|
||||
err = g.Websocket.AuthConn.Dial(dialer, headers)
|
||||
|
||||
Reference in New Issue
Block a user