modernise: Run new gopls modernise tool against the codebase and fix minor issues (#1826)

* modernise: Run new gopls modernise tool against codebase

* Address shazbert's nits

* apichecker, gctcli: Simplify HTML scraping functions and improve depth limit handling

* refactor: Create minSyncInterval const and update order book limit handling for binance and binanceUS

* refactor: Various slice usage improvements and rename TODO

* tranches: Revert deleteByID changes due to performance decrease

Shazbert was a F1 driver in a past lifetime 🏎️

* tranches: Simply retrieve copy

Thanks to shazbert

* documentation: Sort contributors list by contributions

* tranches: Remove deadcode in deleteByID
This commit is contained in:
Adrian Gallagher
2025-03-21 09:17:10 +11:00
committed by GitHub
parent d857d704e3
commit 4651af5767
223 changed files with 1504 additions and 1752 deletions

View File

@@ -25,7 +25,6 @@ import (
// Binanceus is the overarching type across this package
type Binanceus struct {
validLimits []int64
exchange.Base
obm *orderbookManager
}
@@ -114,7 +113,7 @@ const (
recvWindowSize5000 = 5000
)
var recvWindowSize5000String = strconv.Itoa(recvWindowSize5000)
const recvWindowSize5000String = "5000"
// This is a list of error Messages to be returned by binanceus endpoint methods.
var (
@@ -125,7 +124,6 @@ var (
errInvalidAssetAmount = errors.New("invalid asset amount")
errIncompleteArguments = errors.New("missing required argument")
errStartTimeOrFromIDNotSet = errors.New("please set StartTime or FromId, but not both")
errIncorrectLimitValues = errors.New("incorrect limit values - valid values are 5, 10, 20, 50, 100, 500, 1000")
errUnexpectedKlineDataLength = errors.New("unexpected kline data length")
errMissingRequiredArgumentCoin = errors.New("missing required argument,coin")
errMissingRequiredArgumentNetwork = errors.New("missing required argument,network")
@@ -147,11 +145,6 @@ var (
errInvalidRowNumber = errors.New("invalid row number")
)
// SetValues sets the default valid values
func (bi *Binanceus) SetValues() {
bi.validLimits = []int64{5, 10, 20, 50, 100, 500, 1000, 5000}
}
// General Data Endpoints
// GetServerTime this endpoint returns the exchange server time.
@@ -338,9 +331,6 @@ func (bi *Binanceus) batchAggregateTrades(ctx context.Context, arg *AggregatedTr
// GetOrderBookDepth to get the order book depth. Please note the limits in the table below.
func (bi *Binanceus) GetOrderBookDepth(ctx context.Context, arg *OrderBookDataRequestParams) (*OrderBook, error) {
if err := bi.CheckLimit(arg.Limit); err != nil {
return nil, err
}
params := url.Values{}
symbol, err := bi.FormatSymbol(arg.Symbol, asset.Spot)
if err != nil {
@@ -391,16 +381,6 @@ func (bi *Binanceus) GetOrderBookDepth(ctx context.Context, arg *OrderBookDataRe
return &orderbook, nil
}
// CheckLimit checks value against a variable list
func (bi *Binanceus) CheckLimit(limit int64) error {
for x := range bi.validLimits {
if bi.validLimits[x] == limit {
return nil
}
}
return errIncorrectLimitValues
}
// GetIntervalEnum allowed interval params by Binanceus
func (bi *Binanceus) GetIntervalEnum(interval kline.Interval) string {
switch interval {
@@ -458,7 +438,7 @@ func (bi *Binanceus) GetSpotKline(ctx context.Context, arg *KlinesRequestParams)
params.Set("endTime", strconv.FormatInt((arg.EndTime).UnixMilli(), 10))
}
path := common.EncodeURLValues(candleStick, params)
var resp interface{}
var resp any
err = bi.SendHTTPRequest(ctx,
exchange.RestSpotSupplementary,
path,
@@ -467,16 +447,16 @@ func (bi *Binanceus) GetSpotKline(ctx context.Context, arg *KlinesRequestParams)
if err != nil {
return nil, err
}
responseData, ok := resp.([]interface{})
responseData, ok := resp.([]any)
if !ok {
return nil, common.GetTypeAssertError("[]interface{}", resp, "responseData")
return nil, common.GetTypeAssertError("[]any", resp, "responseData")
}
klineData := make([]CandleStick, len(responseData))
for x := range responseData {
individualData, ok := responseData[x].([]interface{})
individualData, ok := responseData[x].([]any)
if !ok {
return nil, common.GetTypeAssertError("[]interface{}", responseData[x], "individualData")
return nil, common.GetTypeAssertError("[]any", responseData[x], "individualData")
}
if len(individualData) != 12 {
return nil, errUnexpectedKlineDataLength
@@ -805,7 +785,7 @@ func (bi *Binanceus) GetAssetDistributionHistory(ctx context.Context, asset stri
func (bi *Binanceus) QuickEnableCryptoWithdrawal(ctx context.Context) error {
params := url.Values{}
response := struct {
Data interface{}
Data any
}{}
params.Set("timestamp", strconv.FormatInt(time.Now().UnixMilli(), 10))
return bi.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary,
@@ -1485,14 +1465,13 @@ func (bi *Binanceus) WithdrawCrypto(ctx context.Context, arg *withdraw.Request)
}
params.Set("amount", strconv.FormatFloat(arg.Amount, 'f', 0, 64))
var response WithdrawalResponse
er := bi.SendAuthHTTPRequest(ctx,
if err := bi.SendAuthHTTPRequest(ctx,
exchange.RestSpotSupplementary,
http.MethodPost, applyWithdrawal,
params, spotDefaultRate, &response)
if er != nil {
return "", er
params, spotDefaultRate, &response); err != nil {
return "", err
}
return response.ID, er
return response.ID, nil
}
// WithdrawalHistory gets the status of recent withdrawals
@@ -1765,7 +1744,7 @@ func (bi *Binanceus) GetReferralRewardHistory(ctx context.Context, userBusinessT
}
// SendHTTPRequest sends an unauthenticated request
func (bi *Binanceus) SendHTTPRequest(ctx context.Context, ePath exchange.URL, path string, f request.EndpointLimit, result interface{}) error {
func (bi *Binanceus) SendHTTPRequest(ctx context.Context, ePath exchange.URL, path string, f request.EndpointLimit, result any) error {
endpointPath, err := bi.API.Endpoints.GetURL(ePath)
if err != nil {
return err
@@ -1785,7 +1764,7 @@ func (bi *Binanceus) SendHTTPRequest(ctx context.Context, ePath exchange.URL, pa
// SendAPIKeyHTTPRequest is a special API request where the api key is
// appended to the headers without a secret
func (bi *Binanceus) SendAPIKeyHTTPRequest(ctx context.Context, ePath exchange.URL, path string, f request.EndpointLimit, result interface{}) error {
func (bi *Binanceus) SendAPIKeyHTTPRequest(ctx context.Context, ePath exchange.URL, path string, f request.EndpointLimit, result any) error {
endpointPath, err := bi.API.Endpoints.GetURL(ePath)
if err != nil {
return err
@@ -1813,7 +1792,7 @@ func (bi *Binanceus) SendAPIKeyHTTPRequest(ctx context.Context, ePath exchange.U
}
// SendAuthHTTPRequest sends an authenticated HTTP request
func (bi *Binanceus) SendAuthHTTPRequest(ctx context.Context, ePath exchange.URL, method, path string, params url.Values, f request.EndpointLimit, result interface{}) error {
func (bi *Binanceus) SendAuthHTTPRequest(ctx context.Context, ePath exchange.URL, method, path string, params url.Values, f request.EndpointLimit, result any) error {
creds, err := bi.GetCredentials(ctx)
if err != nil {
return err

View File

@@ -51,7 +51,7 @@ type ExchangeInfo struct {
Interval string `json:"interval"`
Limit int64 `json:"limit"`
} `json:"rateLimits"`
ExchangeFilters interface{} `json:"exchangeFilters"`
ExchangeFilters any `json:"exchangeFilters"`
Symbols []struct {
Symbol string `json:"symbol"`
Status string `json:"status"`
@@ -162,7 +162,7 @@ func (a *AggregatedTrade) toTradeData(p currency.Pair, exchange string, aType as
// OrderBookDataRequestParams represents Klines request data.
type OrderBookDataRequestParams struct {
Symbol currency.Pair `json:"symbol"` // Required field; example LTCBTC,BTCUSDT
Limit int64 `json:"limit"` // Default 100; max 1000. Valid limits:[5, 10, 20, 50, 100, 500, 1000]
Limit int64 `json:"limit"` // Default 100; max 5000. If limit > 5000, then the response will truncate to 5000
}
// OrderbookItem stores an individual orderbook item
@@ -809,9 +809,9 @@ type UserAccountStream struct {
// WebsocketPayload defines the payload through the websocket connection
type WebsocketPayload struct {
Method string `json:"method"`
Params []interface{} `json:"params"`
ID int64 `json:"id"`
Method string `json:"method"`
Params []any `json:"params"`
ID int64 `json:"id"`
}
// orderbookManager defines a way of managing and maintaining synchronisation

View File

@@ -162,7 +162,7 @@ func stringToOrderStatus(status string) (order.Status, error) {
}
func (bi *Binanceus) wsHandleData(respRaw []byte) error {
var multiStreamData map[string]interface{}
var multiStreamData map[string]any
err := json.Unmarshal(respRaw, &multiStreamData)
if err != nil {
return err
@@ -182,7 +182,7 @@ func (bi *Binanceus) wsHandleData(respRaw []byte) error {
return nil
}
}
if newData, ok := multiStreamData["data"].(map[string]interface{}); ok {
if newData, ok := multiStreamData["data"].(map[string]any); ok {
if e, ok := newData["e"].(string); ok {
switch e {
case "outboundAccountPosition":
@@ -581,7 +581,7 @@ func (bi *Binanceus) Subscribe(channelsToSubscribe subscription.List) error {
if err != nil {
return err
}
payload.Params = []interface{}{}
payload.Params = []any{}
}
}
if len(payload.Params) > 0 {
@@ -605,7 +605,7 @@ func (bi *Binanceus) Unsubscribe(channelsToUnsubscribe subscription.List) error
if err != nil {
return err
}
payload.Params = []interface{}{}
payload.Params = []any{}
}
}
if len(payload.Params) > 0 {

View File

@@ -37,7 +37,6 @@ func (bi *Binanceus) SetDefaults() {
bi.Verbose = true
bi.API.CredentialsValidator.RequiresKey = true
bi.API.CredentialsValidator.RequiresSecret = true
bi.SetValues()
fmt1 := currency.PairStore{
AssetEnabled: true,