From c510121853e98a1828e41d2b54d499dfa6a2e907 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Sep 2025 14:05:34 +1000 Subject: [PATCH] exchanges: Fix strconv.Itoa(...) overflow issues on 32-bit systems (#2064) * Initial plan * Fix BinanceUS strconv.Itoa timestamp overflow issues on 32-bit systems Co-authored-by: thrasher- <4685270+thrasher-@users.noreply.github.com> * Fix additional strconv.Itoa timestamp overflow issues in Bitstamp and Huobi Co-authored-by: gloriousCode <9261323+gloriousCode@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: thrasher- <4685270+thrasher-@users.noreply.github.com> Co-authored-by: gloriousCode <9261323+gloriousCode@users.noreply.github.com> --- exchanges/binanceus/binanceus.go | 18 +++++++++--------- exchanges/bitstamp/bitstamp_websocket.go | 2 +- exchanges/huobi/huobi_websocket.go | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/exchanges/binanceus/binanceus.go b/exchanges/binanceus/binanceus.go index 4790f4b8..5da78607 100644 --- a/exchanges/binanceus/binanceus.go +++ b/exchanges/binanceus/binanceus.go @@ -883,7 +883,7 @@ func (e *Exchange) GetSubaccountStatusList(ctx context.Context, email string) ([ func (e *Exchange) GetOrderRateLimits(ctx context.Context, recvWindow uint) ([]OrderRateLimit, error) { params := url.Values{} timestamp := time.Now().UnixMilli() - params.Set("timestamp", strconv.Itoa(int(timestamp))) + params.Set("timestamp", strconv.FormatInt(timestamp, 10)) if recvWindow > 1000 && recvWindow < 60000 { params.Set("recvWindow", strconv.Itoa(int(recvWindow))) } else { @@ -963,7 +963,7 @@ func (e *Exchange) GetOrder(ctx context.Context, arg *OrderRequestParams) (*Orde params.Set("orderId", strconv.FormatUint(arg.OrderID, 10)) } timestamp := time.Now().UnixMilli() - params.Set("timestamp", strconv.Itoa(int(timestamp))) + params.Set("timestamp", strconv.FormatInt(timestamp, 10)) if arg.OrigClientOrderID != "" { params.Set("origClientOrderId", arg.OrigClientOrderID) } @@ -986,7 +986,7 @@ func (e *Exchange) GetAllOpenOrders(ctx context.Context, symbol string) ([]Order if symbol != "" { params.Set("symbol", symbol) } - params.Set("timestamp", strconv.Itoa(int(timestamp))) + params.Set("timestamp", strconv.FormatInt(timestamp, 10)) params.Set("recvWindow", recvWindowSize5000String) var rateLimit request.EndpointLimit if symbol != "" { @@ -1032,7 +1032,7 @@ func (e *Exchange) CancelOpenOrdersForSymbol(ctx context.Context, symbol string) return nil, errMissingCurrencySymbol } params.Set("symbol", symbol) - params.Set("timestamp", strconv.Itoa(int(time.Now().UnixMilli()))) + params.Set("timestamp", strconv.FormatInt(time.Now().UnixMilli(), 10)) params.Set("recvWindow", "5000") var response []Order return response, e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, @@ -1048,7 +1048,7 @@ func (e *Exchange) GetTrades(ctx context.Context, arg *GetTradesParams) ([]Trade return nil, errIncompleteArguments } params.Set("symbol", arg.Symbol) - params.Set("timestamp", strconv.Itoa(int(time.Now().UnixMilli()))) + params.Set("timestamp", strconv.FormatInt(time.Now().UnixMilli(), 10)) if arg.RecvWindow > 3000 { params.Set("recvWindow", strconv.FormatUint(arg.RecvWindow, 10)) } @@ -1427,10 +1427,10 @@ func (e *Exchange) FiatWithdrawalHistory(ctx context.Context, arg *FiatWithdrawa var response FiatAssetsHistory params := url.Values{} if !(arg.EndTime.IsZero()) && !(arg.EndTime.Before(time.Now())) { - params.Set("endTime", strconv.Itoa(int(arg.EndTime.UnixMilli()))) + params.Set("endTime", strconv.FormatInt(arg.EndTime.UnixMilli(), 10)) } if !arg.StartTime.IsZero() && !(arg.StartTime.After(time.Now())) { - params.Set("startTime", strconv.Itoa(int(arg.StartTime.UnixMilli()))) + params.Set("startTime", strconv.FormatInt(arg.StartTime.UnixMilli(), 10)) } if arg.FiatCurrency != "" { params.Set("fiatCurrency", arg.FiatCurrency) @@ -1444,7 +1444,7 @@ func (e *Exchange) FiatWithdrawalHistory(ctx context.Context, arg *FiatWithdrawa if arg.PaymentMethod != "" { params.Set("paymentMethod", arg.PaymentMethod) } - params.Set("timestamp", strconv.Itoa(int(time.Now().UnixMilli()))) + params.Set("timestamp", strconv.FormatInt(time.Now().UnixMilli(), 10)) return response, e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, fiatWithdrawalHistory, @@ -1455,7 +1455,7 @@ func (e *Exchange) FiatWithdrawalHistory(ctx context.Context, arg *FiatWithdrawa // returns the Order ID as string func (e *Exchange) WithdrawFiat(ctx context.Context, arg *WithdrawFiatRequestParams) (string, error) { params := url.Values{} - timestamp := strconv.Itoa(int(time.Now().UnixMilli())) + timestamp := strconv.FormatInt(time.Now().UnixMilli(), 10) if arg == nil { return "", errIncompleteArguments } diff --git a/exchanges/bitstamp/bitstamp_websocket.go b/exchanges/bitstamp/bitstamp_websocket.go index c38f6f11..6401eb73 100644 --- a/exchanges/bitstamp/bitstamp_websocket.go +++ b/exchanges/bitstamp/bitstamp_websocket.go @@ -269,7 +269,7 @@ func (e *Exchange) manageSubs(ctx context.Context, subs subscription.List, op st if creds == nil { return request.ErrAuthRequestFailed } - req.Data.Channel = "private-" + req.Data.Channel + "-" + strconv.Itoa(int(creds.UserID)) + req.Data.Channel = "private-" + req.Data.Channel + "-" + strconv.FormatInt(creds.UserID, 10) req.Data.Auth = creds.Token } _, err := e.Websocket.Conn.SendMessageReturnResponse(ctx, request.Unset, op+":"+req.Data.Channel, req) diff --git a/exchanges/huobi/huobi_websocket.go b/exchanges/huobi/huobi_websocket.go index 0c7192e4..79234d77 100644 --- a/exchanges/huobi/huobi_websocket.go +++ b/exchanges/huobi/huobi_websocket.go @@ -168,7 +168,7 @@ func (e *Exchange) wsHandleV2ping(ctx context.Context, respRaw []byte) error { if err != nil { return fmt.Errorf("error getting ts from auth ping: %w", err) } - if err := e.Websocket.AuthConn.SendJSONMessage(ctx, request.Unset, json.RawMessage(`{"action":"pong","data":{"ts":`+strconv.Itoa(int(ts))+`}}`)); err != nil { + if err := e.Websocket.AuthConn.SendJSONMessage(ctx, request.Unset, json.RawMessage(`{"action":"pong","data":{"ts":`+strconv.FormatInt(ts, 10)+`}}`)); err != nil { return fmt.Errorf("error sending auth pong response: %w", err) } return nil