From 52f32e0ad0180a011c1b0d8d8f2b695c5325df47 Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 11 Sep 2024 16:38:35 +0800 Subject: [PATCH] upgrade github.com/c9s/requestgen to 1.4.3 --- go.mod | 2 +- go.sum | 4 +- ...cel_wallet_order_all_request_requestgen.go | 3 +- .../create_wallet_order_request_requestgen.go | 38 +++++++++++++++++-- .../get_margin_ad_ratio_request_requestgen.go | 38 +++++++++++++++++-- .../maxapi/v3/get_order_request_requestgen.go | 38 +++++++++++++++++-- .../v3/get_order_trades_request_requestgen.go | 38 +++++++++++++++++-- 7 files changed, 145 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index 4edbe6630..ecca03b6d 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/Masterminds/squirrel v1.5.3 github.com/adshao/go-binance/v2 v2.6.0 github.com/c-bata/goptuna v0.8.1 - github.com/c9s/requestgen v1.4.2 + github.com/c9s/requestgen v1.4.3 github.com/c9s/rockhopper/v2 v2.0.4 github.com/cenkalti/backoff/v4 v4.2.0 github.com/cheggaaa/pb/v3 v3.0.8 diff --git a/go.sum b/go.sum index 5eea84618..b7a2a1366 100644 --- a/go.sum +++ b/go.sum @@ -86,8 +86,8 @@ github.com/bytedance/sonic/loader v0.2.0 h1:zNprn+lsIP06C/IqCHs3gPQIvnvpKbbxyXQP github.com/bytedance/sonic/loader v0.2.0/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= github.com/c-bata/goptuna v0.8.1 h1:25+n1MLv0yvCsD56xv4nqIus3oLHL9GuPAZDLIqmX1U= github.com/c-bata/goptuna v0.8.1/go.mod h1:knmS8+Iyq5PPy1YUeIEq0pMFR4Y6x7z/CySc9HlZTCY= -github.com/c9s/requestgen v1.4.2 h1:pGffzvrX9K3NmuEecOHT5+tV9DqZterJGULSC9seLnk= -github.com/c9s/requestgen v1.4.2/go.mod h1:3gk1M2ihvNU2wWl7WLUc09myp7XpHMP33Dx96+Vr8A0= +github.com/c9s/requestgen v1.4.3 h1:0QZ27RVBLb9QuBKfiSBTOB5zSUuasrJm2p6/GZZHZZw= +github.com/c9s/requestgen v1.4.3/go.mod h1:3gk1M2ihvNU2wWl7WLUc09myp7XpHMP33Dx96+Vr8A0= github.com/c9s/rockhopper/v2 v2.0.4 h1:1cQEzU7rzCSz09B2RYdyPWwBW9gZ/DoFqD1b2xLLmAk= github.com/c9s/rockhopper/v2 v2.0.4/go.mod h1:x0XuYI2Su3kS/74UYu/3Cqc9m5Dtzqh7j7JZarczfss= github.com/cenkalti/backoff/v4 v4.2.0 h1:HN5dHm3WBOgndBH6E8V0q2jIYIR3s9yglV8k/+MN3u4= diff --git a/pkg/exchange/max/maxapi/v3/cancel_wallet_order_all_request_requestgen.go b/pkg/exchange/max/maxapi/v3/cancel_wallet_order_all_request_requestgen.go index 5f623157f..e3860505c 100644 --- a/pkg/exchange/max/maxapi/v3/cancel_wallet_order_all_request_requestgen.go +++ b/pkg/exchange/max/maxapi/v3/cancel_wallet_order_all_request_requestgen.go @@ -6,6 +6,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/c9s/bbgo/pkg/exchange/max/maxapi" "net/url" "reflect" "regexp" @@ -26,7 +27,7 @@ func (c *CancelWalletOrderAllRequest) GroupID(groupID uint32) *CancelWalletOrder return c } -func (c *CancelWalletOrderAllRequest) WalletType(walletType WalletType) *CancelWalletOrderAllRequest { +func (c *CancelWalletOrderAllRequest) WalletType(walletType max.WalletType) *CancelWalletOrderAllRequest { c.walletType = walletType return c } diff --git a/pkg/exchange/max/maxapi/v3/create_wallet_order_request_requestgen.go b/pkg/exchange/max/maxapi/v3/create_wallet_order_request_requestgen.go index 79bd83a20..3b882cd34 100644 --- a/pkg/exchange/max/maxapi/v3/create_wallet_order_request_requestgen.go +++ b/pkg/exchange/max/maxapi/v3/create_wallet_order_request_requestgen.go @@ -236,6 +236,12 @@ func (c *CreateWalletOrderRequest) GetSlugsMap() (map[string]string, error) { return slugs, nil } +// GetPath returns the request path of the API +func (c *CreateWalletOrderRequest) GetPath() string { + return "/api/v3/wallet/:walletType/order" +} + +// Do generates the request object and send the request object to the API endpoint func (c *CreateWalletOrderRequest) Do(ctx context.Context) (*max.Order, error) { params, err := c.GetParameters() @@ -244,7 +250,9 @@ func (c *CreateWalletOrderRequest) Do(ctx context.Context) (*max.Order, error) { } query := url.Values{} - apiURL := "/api/v3/wallet/:walletType/order" + var apiURL string + + apiURL = c.GetPath() slugs, err := c.GetSlugsMap() if err != nil { return nil, err @@ -263,8 +271,32 @@ func (c *CreateWalletOrderRequest) Do(ctx context.Context) (*max.Order, error) { } var apiResponse max.Order - 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 + } + + if validator, ok := interface{}(&apiResponse).(responseValidator); ok { + if err := validator.Validate(); err != nil { + return nil, err + } } return &apiResponse, nil } diff --git a/pkg/exchange/max/maxapi/v3/get_margin_ad_ratio_request_requestgen.go b/pkg/exchange/max/maxapi/v3/get_margin_ad_ratio_request_requestgen.go index cf54325a9..3c101c04f 100644 --- a/pkg/exchange/max/maxapi/v3/get_margin_ad_ratio_request_requestgen.go +++ b/pkg/exchange/max/maxapi/v3/get_margin_ad_ratio_request_requestgen.go @@ -109,13 +109,21 @@ func (g *GetMarginADRatioRequest) GetSlugsMap() (map[string]string, error) { return slugs, nil } +// GetPath returns the request path of the API +func (g *GetMarginADRatioRequest) GetPath() string { + return "/api/v3/wallet/m/ad_ratio" +} + +// Do generates the request object and send the request object to the API endpoint func (g *GetMarginADRatioRequest) Do(ctx context.Context) (*ADRatio, error) { // no body params var params interface{} query := url.Values{} - apiURL := "/api/v3/wallet/m/ad_ratio" + var apiURL string + + apiURL = g.GetPath() req, err := g.client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params) if err != nil { @@ -128,8 +136,32 @@ func (g *GetMarginADRatioRequest) Do(ctx context.Context) (*ADRatio, error) { } var apiResponse ADRatio - 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 + } + + if validator, ok := interface{}(&apiResponse).(responseValidator); ok { + if err := validator.Validate(); err != nil { + return nil, err + } } return &apiResponse, nil } diff --git a/pkg/exchange/max/maxapi/v3/get_order_request_requestgen.go b/pkg/exchange/max/maxapi/v3/get_order_request_requestgen.go index ae8c39e01..5e0888f0f 100644 --- a/pkg/exchange/max/maxapi/v3/get_order_request_requestgen.go +++ b/pkg/exchange/max/maxapi/v3/get_order_request_requestgen.go @@ -136,6 +136,12 @@ func (g *GetOrderRequest) GetSlugsMap() (map[string]string, error) { return slugs, nil } +// GetPath returns the request path of the API +func (g *GetOrderRequest) GetPath() string { + return "/api/v3/order" +} + +// Do generates the request object and send the request object to the API endpoint func (g *GetOrderRequest) Do(ctx context.Context) (*max.Order, error) { // empty params for GET operation @@ -145,7 +151,9 @@ func (g *GetOrderRequest) Do(ctx context.Context) (*max.Order, error) { return nil, err } - apiURL := "/api/v3/order" + var apiURL string + + apiURL = g.GetPath() req, err := g.client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params) if err != nil { @@ -158,8 +166,32 @@ func (g *GetOrderRequest) Do(ctx context.Context) (*max.Order, error) { } var apiResponse max.Order - 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 + } + + if validator, ok := interface{}(&apiResponse).(responseValidator); ok { + if err := validator.Validate(); err != nil { + return nil, err + } } return &apiResponse, nil } diff --git a/pkg/exchange/max/maxapi/v3/get_order_trades_request_requestgen.go b/pkg/exchange/max/maxapi/v3/get_order_trades_request_requestgen.go index e739f3396..cbfc60c3d 100644 --- a/pkg/exchange/max/maxapi/v3/get_order_trades_request_requestgen.go +++ b/pkg/exchange/max/maxapi/v3/get_order_trades_request_requestgen.go @@ -135,6 +135,12 @@ func (g *GetOrderTradesRequest) GetSlugsMap() (map[string]string, error) { return slugs, nil } +// GetPath returns the request path of the API +func (g *GetOrderTradesRequest) GetPath() string { + return "/api/v3/order/trades" +} + +// Do generates the request object and send the request object to the API endpoint func (g *GetOrderTradesRequest) Do(ctx context.Context) ([]Trade, error) { // empty params for GET operation @@ -144,7 +150,9 @@ func (g *GetOrderTradesRequest) Do(ctx context.Context) ([]Trade, error) { return nil, err } - apiURL := "/api/v3/order/trades" + var apiURL string + + apiURL = g.GetPath() req, err := g.client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params) if err != nil { @@ -157,8 +165,32 @@ func (g *GetOrderTradesRequest) Do(ctx context.Context) ([]Trade, error) { } var apiResponse []Trade - 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 + } + + if validator, ok := interface{}(&apiResponse).(responseValidator); ok { + if err := validator.Validate(); err != nil { + return nil, err + } } return apiResponse, nil }