mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-14 19:13:52 +00:00
Merge pull request #1762 from c9s/edwin/bybit/adjust-rate-limit
MINOR: [bybit] use individual rate limit on wallet-balance API
This commit is contained in:
commit
0ba1fc5215
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user