diff --git a/pkg/exchange/bybit/bybitapi/get_wallet_balances_request.go b/pkg/exchange/bybit/bybitapi/get_wallet_balances_request.go index d2f07fe9c..196de9f09 100644 --- a/pkg/exchange/bybit/bybitapi/get_wallet_balances_request.go +++ b/pkg/exchange/bybit/bybitapi/get_wallet_balances_request.go @@ -70,7 +70,7 @@ type WalletBalances struct { } `json:"coin"` } -//go:generate GetRequest -url "/v5/account/wallet-balance" -type GetWalletBalancesRequest -responseDataType .WalletBalancesResponse +//go:generate GetRequest -url "/v5/account/wallet-balance" -type GetWalletBalancesRequest -responseDataType .WalletBalancesResponse -rateLimiter 1+15/1s type GetWalletBalancesRequest struct { client requestgen.AuthenticatedAPIClient diff --git a/pkg/exchange/bybit/bybitapi/get_wallet_balances_request_requestgen.go b/pkg/exchange/bybit/bybitapi/get_wallet_balances_request_requestgen.go index 601d26ce9..318c0e98c 100644 --- a/pkg/exchange/bybit/bybitapi/get_wallet_balances_request_requestgen.go +++ b/pkg/exchange/bybit/bybitapi/get_wallet_balances_request_requestgen.go @@ -1,4 +1,4 @@ -// Code generated by "requestgen -method GET -responseType .APIResponse -responseDataField Result -url /v5/account/wallet-balance -type GetWalletBalancesRequest -responseDataType .WalletBalancesResponse"; DO NOT EDIT. +// Code generated by "requestgen -method GET -responseType .APIResponse -responseDataField Result -url /v5/account/wallet-balance -type GetWalletBalancesRequest -responseDataType .WalletBalancesResponse -rateLimiter 1+15/1s"; DO NOT EDIT. package bybitapi @@ -6,11 +6,14 @@ import ( "context" "encoding/json" "fmt" + "golang.org/x/time/rate" "net/url" "reflect" "regexp" ) +var GetWalletBalancesRequestLimiter = rate.NewLimiter(15.000000150000002, 1) + func (g *GetWalletBalancesRequest) AccountType(accountType AccountType) *GetWalletBalancesRequest { g.accountType = accountType return g @@ -150,6 +153,9 @@ func (g *GetWalletBalancesRequest) GetPath() string { // Do generates the request object and send the request object to the API endpoint func (g *GetWalletBalancesRequest) Do(ctx context.Context) (*WalletBalancesResponse, error) { + if err := GetWalletBalancesRequestLimiter.Wait(ctx); err != nil { + return nil, err + } // no body params var params interface{} @@ -173,15 +179,29 @@ func (g *GetWalletBalancesRequest) Do(ctx context.Context) (*WalletBalancesRespo } var apiResponse APIResponse - if err := response.DecodeJSON(&apiResponse); err != nil { - return nil, err + + type responseUnmarshaler interface { + Unmarshal(data []byte) error + } + + if unmarshaler, ok := interface{}(&apiResponse).(responseUnmarshaler); ok { + if err := unmarshaler.Unmarshal(response.Body); err != nil { + return nil, err + } + } else { + // The line below checks the content type, however, some API server might not send the correct content type header, + // Hence, this is commented for backward compatibility + // response.IsJSON() + if err := response.DecodeJSON(&apiResponse); err != nil { + return nil, err + } } type responseValidator interface { Validate() error } - validator, ok := interface{}(apiResponse).(responseValidator) - if ok { + + if validator, ok := interface{}(&apiResponse).(responseValidator); ok { if err := validator.Validate(); err != nil { return nil, err } diff --git a/pkg/exchange/bybit/exchange.go b/pkg/exchange/bybit/exchange.go index 629f086db..4dcab329b 100644 --- a/pkg/exchange/bybit/exchange.go +++ b/pkg/exchange/bybit/exchange.go @@ -518,10 +518,6 @@ func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error) { } func (e *Exchange) QueryAccountBalances(ctx context.Context) (types.BalanceMap, error) { - if err := sharedRateLimiter.Wait(ctx); err != nil { - return nil, fmt.Errorf("query account balances rate limiter wait error: %w", err) - } - req := e.client.NewGetWalletBalancesRequest() accounts, err := req.Do(ctx) if err != nil {