From 40f6295d9125a638605fc1d30ea24831e7604eaf Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 4 May 2023 17:18:42 +0800 Subject: [PATCH] maxapi: move GetMarginInterestRatesRequest api to a file --- .../v3/get_margin_interest_rates_request.go | 27 +++++++++++++++++++ ...argin_interest_rates_request_requestgen.go | 4 +-- pkg/exchange/max/maxapi/v3/margin.go | 16 ----------- .../max/maxapi/v3/margin_repay_request.go | 8 +++--- 4 files changed, 33 insertions(+), 22 deletions(-) create mode 100644 pkg/exchange/max/maxapi/v3/get_margin_interest_rates_request.go diff --git a/pkg/exchange/max/maxapi/v3/get_margin_interest_rates_request.go b/pkg/exchange/max/maxapi/v3/get_margin_interest_rates_request.go new file mode 100644 index 000000000..e3a8a5d5d --- /dev/null +++ b/pkg/exchange/max/maxapi/v3/get_margin_interest_rates_request.go @@ -0,0 +1,27 @@ +package v3 + +//go:generate -command GetRequest requestgen -method GET +//go:generate -command PostRequest requestgen -method POST +//go:generate -command DeleteRequest requestgen -method DELETE + +import ( + "github.com/c9s/requestgen" + + "github.com/c9s/bbgo/pkg/fixedpoint" +) + +type MarginInterestRate struct { + HourlyInterestRate fixedpoint.Value `json:"hourly_interest_rate"` + NextHourlyInterestRate fixedpoint.Value `json:"next_hourly_interest_rate"` +} + +type MarginInterestRateMap map[string]MarginInterestRate + +//go:generate GetRequest -url "/api/v3/wallet/m/interest_rates" -type GetMarginInterestRatesRequest -responseType .MarginInterestRateMap +type GetMarginInterestRatesRequest struct { + client requestgen.APIClient +} + +func (s *Client) NewGetMarginInterestRatesRequest() *GetMarginInterestRatesRequest { + return &GetMarginInterestRatesRequest{client: s.Client} +} diff --git a/pkg/exchange/max/maxapi/v3/get_margin_interest_rates_request_requestgen.go b/pkg/exchange/max/maxapi/v3/get_margin_interest_rates_request_requestgen.go index 6de0e5eaa..f6c3bf85a 100644 --- a/pkg/exchange/max/maxapi/v3/get_margin_interest_rates_request_requestgen.go +++ b/pkg/exchange/max/maxapi/v3/get_margin_interest_rates_request_requestgen.go @@ -109,7 +109,7 @@ func (g *GetMarginInterestRatesRequest) GetSlugsMap() (map[string]string, error) return slugs, nil } -func (g *GetMarginInterestRatesRequest) Do(ctx context.Context) (*MarginInterestRateMap, error) { +func (g *GetMarginInterestRatesRequest) Do(ctx context.Context) (MarginInterestRateMap, error) { // no body params var params interface{} @@ -131,5 +131,5 @@ func (g *GetMarginInterestRatesRequest) Do(ctx context.Context) (*MarginInterest if err := response.DecodeJSON(&apiResponse); err != nil { return nil, err } - return &apiResponse, nil + return apiResponse, nil } diff --git a/pkg/exchange/max/maxapi/v3/margin.go b/pkg/exchange/max/maxapi/v3/margin.go index 022b9d084..e4d3fa046 100644 --- a/pkg/exchange/max/maxapi/v3/margin.go +++ b/pkg/exchange/max/maxapi/v3/margin.go @@ -15,26 +15,10 @@ type MarginService struct { Client *maxapi.RestClient } -func (s *Client) NewGetMarginInterestRatesRequest() *GetMarginInterestRatesRequest { - return &GetMarginInterestRatesRequest{client: s.Client} -} - func (s *Client) NewGetMarginBorrowingLimitsRequest() *GetMarginBorrowingLimitsRequest { return &GetMarginBorrowingLimitsRequest{client: s.Client} } -type MarginInterestRate struct { - HourlyInterestRate fixedpoint.Value `json:"hourly_interest_rate"` - NextHourlyInterestRate fixedpoint.Value `json:"next_hourly_interest_rate"` -} - -type MarginInterestRateMap map[string]MarginInterestRate - -//go:generate GetRequest -url "/api/v3/wallet/m/interest_rates" -type GetMarginInterestRatesRequest -responseType .MarginInterestRateMap -type GetMarginInterestRatesRequest struct { - client requestgen.APIClient -} - type MarginBorrowingLimitMap map[string]fixedpoint.Value //go:generate GetRequest -url "/api/v3/wallet/m/limits" -type GetMarginBorrowingLimitsRequest -responseType .MarginBorrowingLimitMap diff --git a/pkg/exchange/max/maxapi/v3/margin_repay_request.go b/pkg/exchange/max/maxapi/v3/margin_repay_request.go index 45d1ba663..8d6150f4b 100644 --- a/pkg/exchange/max/maxapi/v3/margin_repay_request.go +++ b/pkg/exchange/max/maxapi/v3/margin_repay_request.go @@ -6,10 +6,6 @@ package v3 import "github.com/c9s/requestgen" -func (s *Client) NewMarginRepayRequest() *MarginRepayRequest { - return &MarginRepayRequest{client: s.Client} -} - //go:generate PostRequest -url "/api/v3/wallet/m/repayment" -type MarginRepayRequest -responseType .RepaymentRecord type MarginRepayRequest struct { client requestgen.AuthenticatedAPIClient @@ -17,3 +13,7 @@ type MarginRepayRequest struct { currency string `param:"currency,required"` amount string `param:"amount"` } + +func (s *Client) NewMarginRepayRequest() *MarginRepayRequest { + return &MarginRepayRequest{client: s.Client} +}