mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
Merge pull request #1166 from c9s/c9s/max/api-v3-fix
FIX: [max] replace deprecated max v3 API
This commit is contained in:
commit
24ca1b103b
|
@ -28,7 +28,7 @@ type Exchange struct {
|
|||
key, secret string
|
||||
client *maxapi.RestClient
|
||||
|
||||
v3order *v3.OrderService
|
||||
v3client *v3.Client
|
||||
v3margin *v3.MarginService
|
||||
|
||||
submitOrderLimiter, queryTradeLimiter, accountQueryLimiter, closedOrderQueryLimiter, marketDataLimiter *rate.Limiter
|
||||
|
@ -47,7 +47,7 @@ func New(key, secret string) *Exchange {
|
|||
key: key,
|
||||
// pragma: allowlist nextline secret
|
||||
secret: secret,
|
||||
v3order: &v3.OrderService{Client: client},
|
||||
v3client: &v3.Client{Client: client},
|
||||
v3margin: &v3.MarginService{Client: client},
|
||||
|
||||
queryTradeLimiter: rate.NewLimiter(rate.Every(1*time.Second), 2),
|
||||
|
@ -182,7 +182,7 @@ func (e *Exchange) QueryOrderTrades(ctx context.Context, q types.OrderQuery) ([]
|
|||
return nil, err
|
||||
}
|
||||
|
||||
maxTrades, err := e.v3order.NewGetOrderTradesRequest().OrderID(uint64(orderID)).Do(ctx)
|
||||
maxTrades, err := e.v3client.NewGetOrderTradesRequest().OrderID(uint64(orderID)).Do(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ func (e *Exchange) QueryOrder(ctx context.Context, q types.OrderQuery) (*types.O
|
|||
return nil, errors.New("max.QueryOrder: only accept one parameter of OrderID/ClientOrderID")
|
||||
}
|
||||
|
||||
request := e.v3order.NewGetOrderRequest()
|
||||
request := e.v3client.NewGetOrderRequest()
|
||||
|
||||
if len(q.OrderID) != 0 {
|
||||
orderID, err := strconv.ParseInt(q.OrderID, 10, 64)
|
||||
|
@ -248,7 +248,7 @@ func (e *Exchange) QueryOpenOrders(ctx context.Context, symbol string) (orders [
|
|||
walletType = maxapi.WalletTypeMargin
|
||||
}
|
||||
|
||||
maxOrders, err := e.v3order.NewGetWalletOpenOrdersRequest(walletType).Market(market).Do(ctx)
|
||||
maxOrders, err := e.v3client.NewGetWalletOpenOrdersRequest(walletType).Market(market).Do(ctx)
|
||||
if err != nil {
|
||||
return orders, err
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ func (e *Exchange) queryClosedOrdersByLastOrderID(ctx context.Context, symbol st
|
|||
walletType = maxapi.WalletTypeMargin
|
||||
}
|
||||
|
||||
req := e.v3order.NewGetWalletOrderHistoryRequest(walletType).Market(market)
|
||||
req := e.v3client.NewGetWalletOrderHistoryRequest(walletType).Market(market)
|
||||
if lastOrderID == 0 {
|
||||
lastOrderID = 1
|
||||
}
|
||||
|
@ -315,7 +315,7 @@ func (e *Exchange) CancelAllOrders(ctx context.Context) ([]types.Order, error) {
|
|||
walletType = maxapi.WalletTypeMargin
|
||||
}
|
||||
|
||||
req := e.v3order.NewCancelWalletOrderAllRequest(walletType)
|
||||
req := e.v3client.NewCancelWalletOrderAllRequest(walletType)
|
||||
var orderResponses, err = req.Do(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -338,7 +338,7 @@ func (e *Exchange) CancelOrdersBySymbol(ctx context.Context, symbol string) ([]t
|
|||
walletType = maxapi.WalletTypeMargin
|
||||
}
|
||||
|
||||
req := e.v3order.NewCancelWalletOrderAllRequest(walletType)
|
||||
req := e.v3client.NewCancelWalletOrderAllRequest(walletType)
|
||||
req.Market(market)
|
||||
|
||||
var orderResponses, err = req.Do(ctx)
|
||||
|
@ -362,7 +362,7 @@ func (e *Exchange) CancelOrdersByGroupID(ctx context.Context, groupID uint32) ([
|
|||
walletType = maxapi.WalletTypeMargin
|
||||
}
|
||||
|
||||
req := e.v3order.NewCancelWalletOrderAllRequest(walletType)
|
||||
req := e.v3client.NewCancelWalletOrderAllRequest(walletType)
|
||||
req.GroupID(groupID)
|
||||
|
||||
var orderResponses, err = req.Do(ctx)
|
||||
|
@ -398,7 +398,7 @@ func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) (err
|
|||
|
||||
if len(groupIDs) > 0 {
|
||||
for groupID := range groupIDs {
|
||||
req := e.v3order.NewCancelWalletOrderAllRequest(walletType)
|
||||
req := e.v3client.NewCancelWalletOrderAllRequest(walletType)
|
||||
req.GroupID(groupID)
|
||||
|
||||
if _, err := req.Do(ctx); err != nil {
|
||||
|
@ -409,7 +409,7 @@ func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) (err
|
|||
}
|
||||
|
||||
for _, o := range orphanOrders {
|
||||
req := e.v3order.NewCancelOrderRequest()
|
||||
req := e.v3client.NewCancelOrderRequest()
|
||||
if o.OrderID > 0 {
|
||||
req.Id(o.OrderID)
|
||||
} else if len(o.ClientOrderID) > 0 && o.ClientOrderID != types.NoClientOrderID {
|
||||
|
@ -498,7 +498,7 @@ func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) (cr
|
|||
|
||||
clientOrderID := NewClientOrderID(o.ClientOrderID)
|
||||
|
||||
req := e.v3order.NewCreateWalletOrderRequest(walletType)
|
||||
req := e.v3client.NewCreateWalletOrderRequest(walletType)
|
||||
req.Market(toLocalSymbol(o.Symbol)).
|
||||
Side(toLocalSideType(o.Side)).
|
||||
Volume(quantityString).
|
||||
|
@ -590,7 +590,7 @@ func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error) {
|
|||
if e.MarginSettings.IsMargin {
|
||||
a.AccountType = types.AccountTypeMargin
|
||||
|
||||
req := e.v3margin.NewGetMarginADRatioRequest()
|
||||
req := e.v3client.NewGetMarginADRatioRequest()
|
||||
adRatio, err := req.Do(ctx)
|
||||
if err != nil {
|
||||
return a, err
|
||||
|
@ -613,7 +613,7 @@ func (e *Exchange) QueryAccountBalances(ctx context.Context) (types.BalanceMap,
|
|||
walletType = maxapi.WalletTypeMargin
|
||||
}
|
||||
|
||||
req := e.v3order.NewGetWalletAccountsRequest(walletType)
|
||||
req := e.v3client.NewGetWalletAccountsRequest(walletType)
|
||||
accounts, err := req.Do(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -818,7 +818,7 @@ func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *type
|
|||
walletType = maxapi.WalletTypeMargin
|
||||
}
|
||||
|
||||
req := e.v3order.NewGetWalletTradesRequest(walletType)
|
||||
req := e.v3client.NewGetWalletTradesRequest(walletType)
|
||||
req.Market(market)
|
||||
|
||||
if options.Limit > 0 {
|
||||
|
@ -977,7 +977,7 @@ func (e *Exchange) QueryAveragePrice(ctx context.Context, symbol string) (fixedp
|
|||
}
|
||||
|
||||
func (e *Exchange) RepayMarginAsset(ctx context.Context, asset string, amount fixedpoint.Value) error {
|
||||
req := e.v3margin.NewMarginRepayRequest()
|
||||
req := e.v3client.NewMarginRepayRequest()
|
||||
req.Currency(toLocalCurrency(asset))
|
||||
req.Amount(amount.String())
|
||||
resp, err := req.Do(ctx)
|
||||
|
@ -990,7 +990,7 @@ func (e *Exchange) RepayMarginAsset(ctx context.Context, asset string, amount fi
|
|||
}
|
||||
|
||||
func (e *Exchange) BorrowMarginAsset(ctx context.Context, asset string, amount fixedpoint.Value) error {
|
||||
req := e.v3margin.NewMarginLoanRequest()
|
||||
req := e.v3client.NewMarginLoanRequest()
|
||||
req.Currency(toLocalCurrency(asset))
|
||||
req.Amount(amount.String())
|
||||
resp, err := req.Do(ctx)
|
||||
|
@ -1003,7 +1003,7 @@ func (e *Exchange) BorrowMarginAsset(ctx context.Context, asset string, amount f
|
|||
}
|
||||
|
||||
func (e *Exchange) QueryMarginAssetMaxBorrowable(ctx context.Context, asset string) (amount fixedpoint.Value, err error) {
|
||||
req := e.v3margin.NewGetMarginBorrowingLimitsRequest()
|
||||
req := e.v3client.NewGetMarginBorrowingLimitsRequest()
|
||||
resp, err := req.Do(ctx)
|
||||
if err != nil {
|
||||
return fixedpoint.Zero, err
|
||||
|
|
|
@ -6,10 +6,6 @@ package v3
|
|||
|
||||
import "github.com/c9s/requestgen"
|
||||
|
||||
func (s *OrderService) NewCancelOrderRequest() *CancelOrderRequest {
|
||||
return &CancelOrderRequest{client: s.Client}
|
||||
}
|
||||
|
||||
//go:generate DeleteRequest -url "/api/v3/order" -type CancelOrderRequest -responseType .Order
|
||||
type CancelOrderRequest struct {
|
||||
client requestgen.AuthenticatedAPIClient
|
||||
|
@ -17,3 +13,7 @@ type CancelOrderRequest struct {
|
|||
id *uint64 `param:"id,omitempty"`
|
||||
clientOrderID *string `param:"client_oid,omitempty"`
|
||||
}
|
||||
|
||||
func (s *Client) NewCancelOrderRequest() *CancelOrderRequest {
|
||||
return &CancelOrderRequest{client: s.Client}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ type OrderCancelResponse struct {
|
|||
Error *string
|
||||
}
|
||||
|
||||
func (s *OrderService) NewCancelWalletOrderAllRequest(walletType WalletType) *CancelWalletOrderAllRequest {
|
||||
func (s *Client) NewCancelWalletOrderAllRequest(walletType WalletType) *CancelWalletOrderAllRequest {
|
||||
return &CancelWalletOrderAllRequest{client: s.Client, walletType: walletType}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,6 @@ type CreateWalletOrderRequest struct {
|
|||
groupID *string `param:"group_id"`
|
||||
}
|
||||
|
||||
func (s *OrderService) NewCreateWalletOrderRequest(walletType WalletType) *CreateWalletOrderRequest {
|
||||
func (s *Client) NewCreateWalletOrderRequest(walletType WalletType) *CreateWalletOrderRequest {
|
||||
return &CreateWalletOrderRequest{client: s.Client, walletType: walletType}
|
||||
}
|
||||
|
|
|
@ -10,10 +10,6 @@ import (
|
|||
//go:generate -command PostRequest requestgen -method POST
|
||||
//go:generate -command DeleteRequest requestgen -method DELETE
|
||||
|
||||
func (s *MarginService) NewGetMarginADRatioRequest() *GetMarginADRatioRequest {
|
||||
return &GetMarginADRatioRequest{client: s.Client}
|
||||
}
|
||||
|
||||
type ADRatio struct {
|
||||
AdRatio fixedpoint.Value `json:"ad_ratio"`
|
||||
AssetInUsdt fixedpoint.Value `json:"asset_in_usdt"`
|
||||
|
@ -24,3 +20,7 @@ type ADRatio struct {
|
|||
type GetMarginADRatioRequest struct {
|
||||
client requestgen.AuthenticatedAPIClient
|
||||
}
|
||||
|
||||
func (s *Client) NewGetMarginADRatioRequest() *GetMarginADRatioRequest {
|
||||
return &GetMarginADRatioRequest{client: s.Client}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package v3
|
||||
|
||||
//go:generate -command GetRequest requestgen -method GET
|
||||
//go:generate -command PostRequest requestgen -method POST
|
||||
//go:generate -command DeleteRequest requestgen -method DELETE
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/c9s/requestgen"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
type MarginInterestRecord struct {
|
||||
Currency string `json:"currency"`
|
||||
Amount fixedpoint.Value `json:"amount"`
|
||||
InterestRate fixedpoint.Value `json:"interest_rate"`
|
||||
CreatedAt types.MillisecondTimestamp `json:"created_at"`
|
||||
}
|
||||
|
||||
//go:generate GetRequest -url "/api/v3/wallet/m/interests" -type GetMarginInterestHistoryRequest -responseType []MarginInterestRecord
|
||||
type GetMarginInterestHistoryRequest struct {
|
||||
client requestgen.AuthenticatedAPIClient
|
||||
|
||||
currency string `param:"currency,required"`
|
||||
startTime *time.Time `param:"startTime,milliseconds"`
|
||||
endTime *time.Time `param:"endTime,milliseconds"`
|
||||
limit *int `param:"limit"`
|
||||
}
|
||||
|
||||
func (s *Client) NewGetMarginInterestHistoryRequest(currency string) *GetMarginInterestHistoryRequest {
|
||||
return &GetMarginInterestHistoryRequest{client: s.Client, currency: currency}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by "requestgen -method GET -url /api/v3/wallet/m/interests/history/:currency -type GetMarginInterestHistoryRequest -responseType []MarginInterestRecord"; DO NOT EDIT.
|
||||
// Code generated by "requestgen -method GET -url /api/v3/wallet/m/interests -type GetMarginInterestHistoryRequest -responseType []MarginInterestRecord"; DO NOT EDIT.
|
||||
|
||||
package v3
|
||||
|
||||
|
@ -13,6 +13,11 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func (g *GetMarginInterestHistoryRequest) Currency(currency string) *GetMarginInterestHistoryRequest {
|
||||
g.currency = currency
|
||||
return g
|
||||
}
|
||||
|
||||
func (g *GetMarginInterestHistoryRequest) StartTime(startTime time.Time) *GetMarginInterestHistoryRequest {
|
||||
g.startTime = &startTime
|
||||
return g
|
||||
|
@ -28,11 +33,6 @@ func (g *GetMarginInterestHistoryRequest) Limit(limit int) *GetMarginInterestHis
|
|||
return g
|
||||
}
|
||||
|
||||
func (g *GetMarginInterestHistoryRequest) Currency(currency string) *GetMarginInterestHistoryRequest {
|
||||
g.currency = currency
|
||||
return g
|
||||
}
|
||||
|
||||
// GetQueryParameters builds and checks the query parameters and returns url.Values
|
||||
func (g *GetMarginInterestHistoryRequest) GetQueryParameters() (url.Values, error) {
|
||||
var params = map[string]interface{}{}
|
||||
|
@ -48,6 +48,17 @@ func (g *GetMarginInterestHistoryRequest) GetQueryParameters() (url.Values, erro
|
|||
// GetParameters builds and checks the parameters and return the result in a map object
|
||||
func (g *GetMarginInterestHistoryRequest) GetParameters() (map[string]interface{}, error) {
|
||||
var params = map[string]interface{}{}
|
||||
// check currency field -> json key currency
|
||||
currency := g.currency
|
||||
|
||||
// TEMPLATE check-required
|
||||
if len(currency) == 0 {
|
||||
return nil, fmt.Errorf("currency is required, empty string given")
|
||||
}
|
||||
// END TEMPLATE check-required
|
||||
|
||||
// assign parameter of currency
|
||||
params["currency"] = currency
|
||||
// check startTime field -> json key startTime
|
||||
if g.startTime != nil {
|
||||
startTime := *g.startTime
|
||||
|
@ -113,17 +124,6 @@ func (g *GetMarginInterestHistoryRequest) GetParametersJSON() ([]byte, error) {
|
|||
// GetSlugParameters builds and checks the slug parameters and return the result in a map object
|
||||
func (g *GetMarginInterestHistoryRequest) GetSlugParameters() (map[string]interface{}, error) {
|
||||
var params = map[string]interface{}{}
|
||||
// check currency field -> json key currency
|
||||
currency := g.currency
|
||||
|
||||
// TEMPLATE check-required
|
||||
if len(currency) == 0 {
|
||||
return nil, fmt.Errorf("currency is required, empty string given")
|
||||
}
|
||||
// END TEMPLATE check-required
|
||||
|
||||
// assign parameter of currency
|
||||
params["currency"] = currency
|
||||
|
||||
return params, nil
|
||||
}
|
||||
|
@ -177,13 +177,7 @@ func (g *GetMarginInterestHistoryRequest) Do(ctx context.Context) ([]MarginInter
|
|||
return nil, err
|
||||
}
|
||||
|
||||
apiURL := "/api/v3/wallet/m/interests/history/:currency"
|
||||
slugs, err := g.GetSlugsMap()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
apiURL = g.applySlugsToUrl(apiURL, slugs)
|
||||
apiURL := "/api/v3/wallet/m/interests"
|
||||
|
||||
req, err := g.client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params)
|
||||
if err != nil {
|
||||
|
|
|
@ -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}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package v3
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/c9s/requestgen"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
func (s *Client) NewGetMarginLiquidationHistoryRequest() *GetMarginLiquidationHistoryRequest {
|
||||
return &GetMarginLiquidationHistoryRequest{client: s.Client}
|
||||
}
|
||||
|
||||
type LiquidationRecord struct {
|
||||
SN string `json:"sn"`
|
||||
AdRatio fixedpoint.Value `json:"ad_ratio"`
|
||||
ExpectedAdRatio fixedpoint.Value `json:"expected_ad_ratio"`
|
||||
CreatedAt types.MillisecondTimestamp `json:"created_at"`
|
||||
State LiquidationState `json:"state"`
|
||||
}
|
||||
|
||||
type LiquidationState string
|
||||
|
||||
const (
|
||||
LiquidationStateProcessing LiquidationState = "processing"
|
||||
LiquidationStateDebt LiquidationState = "debt"
|
||||
LiquidationStateLiquidated LiquidationState = "liquidated"
|
||||
)
|
||||
|
||||
//go:generate GetRequest -url "/api/v3/wallet/m/liquidations" -type GetMarginLiquidationHistoryRequest -responseType []LiquidationRecord
|
||||
type GetMarginLiquidationHistoryRequest struct {
|
||||
client requestgen.AuthenticatedAPIClient
|
||||
startTime *time.Time `param:"startTime,milliseconds"`
|
||||
endTime *time.Time `param:"endTime,milliseconds"`
|
||||
limit *int `param:"limit"`
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package v3
|
||||
|
||||
//go:generate -command GetRequest requestgen -method GET
|
||||
//go:generate -command PostRequest requestgen -method POST
|
||||
//go:generate -command DeleteRequest requestgen -method DELETE
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/c9s/requestgen"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
func (s *Client) NewGetMarginLoanHistoryRequest() *GetMarginLoanHistoryRequest {
|
||||
return &GetMarginLoanHistoryRequest{client: s.Client}
|
||||
}
|
||||
|
||||
type LoanRecord struct {
|
||||
SN string `json:"sn"`
|
||||
Currency string `json:"currency"`
|
||||
Amount fixedpoint.Value `json:"amount"`
|
||||
State string `json:"state"`
|
||||
CreatedAt types.MillisecondTimestamp `json:"created_at"`
|
||||
InterestRate fixedpoint.Value `json:"interest_rate"`
|
||||
}
|
||||
|
||||
//go:generate GetRequest -url "/api/v3/wallet/m/loans" -type GetMarginLoanHistoryRequest -responseType []LoanRecord
|
||||
type GetMarginLoanHistoryRequest struct {
|
||||
client requestgen.AuthenticatedAPIClient
|
||||
|
||||
currency string `param:"currency,required"`
|
||||
|
||||
startTime *time.Time `param:"startTime,milliseconds"`
|
||||
endTime *time.Time `param:"endTime,milliseconds"`
|
||||
limit *int `param:"limit"`
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by "requestgen -method GET -url /api/v3/wallet/m/loans/:currency -type GetMarginLoanHistoryRequest -responseType []LoanRecord"; DO NOT EDIT.
|
||||
// Code generated by "requestgen -method GET -url /api/v3/wallet/m/loans -type GetMarginLoanHistoryRequest -responseType []LoanRecord"; DO NOT EDIT.
|
||||
|
||||
package v3
|
||||
|
||||
|
@ -13,6 +13,11 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func (g *GetMarginLoanHistoryRequest) Currency(currency string) *GetMarginLoanHistoryRequest {
|
||||
g.currency = currency
|
||||
return g
|
||||
}
|
||||
|
||||
func (g *GetMarginLoanHistoryRequest) StartTime(startTime time.Time) *GetMarginLoanHistoryRequest {
|
||||
g.startTime = &startTime
|
||||
return g
|
||||
|
@ -28,11 +33,6 @@ func (g *GetMarginLoanHistoryRequest) Limit(limit int) *GetMarginLoanHistoryRequ
|
|||
return g
|
||||
}
|
||||
|
||||
func (g *GetMarginLoanHistoryRequest) Currency(currency string) *GetMarginLoanHistoryRequest {
|
||||
g.currency = currency
|
||||
return g
|
||||
}
|
||||
|
||||
// GetQueryParameters builds and checks the query parameters and returns url.Values
|
||||
func (g *GetMarginLoanHistoryRequest) GetQueryParameters() (url.Values, error) {
|
||||
var params = map[string]interface{}{}
|
||||
|
@ -48,6 +48,17 @@ func (g *GetMarginLoanHistoryRequest) GetQueryParameters() (url.Values, error) {
|
|||
// GetParameters builds and checks the parameters and return the result in a map object
|
||||
func (g *GetMarginLoanHistoryRequest) GetParameters() (map[string]interface{}, error) {
|
||||
var params = map[string]interface{}{}
|
||||
// check currency field -> json key currency
|
||||
currency := g.currency
|
||||
|
||||
// TEMPLATE check-required
|
||||
if len(currency) == 0 {
|
||||
return nil, fmt.Errorf("currency is required, empty string given")
|
||||
}
|
||||
// END TEMPLATE check-required
|
||||
|
||||
// assign parameter of currency
|
||||
params["currency"] = currency
|
||||
// check startTime field -> json key startTime
|
||||
if g.startTime != nil {
|
||||
startTime := *g.startTime
|
||||
|
@ -113,17 +124,6 @@ func (g *GetMarginLoanHistoryRequest) GetParametersJSON() ([]byte, error) {
|
|||
// GetSlugParameters builds and checks the slug parameters and return the result in a map object
|
||||
func (g *GetMarginLoanHistoryRequest) GetSlugParameters() (map[string]interface{}, error) {
|
||||
var params = map[string]interface{}{}
|
||||
// check currency field -> json key currency
|
||||
currency := g.currency
|
||||
|
||||
// TEMPLATE check-required
|
||||
if len(currency) == 0 {
|
||||
return nil, fmt.Errorf("currency is required, empty string given")
|
||||
}
|
||||
// END TEMPLATE check-required
|
||||
|
||||
// assign parameter of currency
|
||||
params["currency"] = currency
|
||||
|
||||
return params, nil
|
||||
}
|
||||
|
@ -177,13 +177,7 @@ func (g *GetMarginLoanHistoryRequest) Do(ctx context.Context) ([]LoanRecord, err
|
|||
return nil, err
|
||||
}
|
||||
|
||||
apiURL := "/api/v3/wallet/m/loans/:currency"
|
||||
slugs, err := g.GetSlugsMap()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
apiURL = g.applySlugsToUrl(apiURL, slugs)
|
||||
apiURL := "/api/v3/wallet/m/loans"
|
||||
|
||||
req, err := g.client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params)
|
||||
if err != nil {
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package v3
|
||||
|
||||
//go:generate -command GetRequest requestgen -method GET
|
||||
//go:generate -command PostRequest requestgen -method POST
|
||||
//go:generate -command DeleteRequest requestgen -method DELETE
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/c9s/requestgen"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
type RepaymentRecord struct {
|
||||
SN string `json:"sn"`
|
||||
Currency string `json:"currency"`
|
||||
Amount fixedpoint.Value `json:"amount"`
|
||||
Principal fixedpoint.Value `json:"principal"`
|
||||
Interest fixedpoint.Value `json:"interest"`
|
||||
CreatedAt types.MillisecondTimestamp `json:"created_at"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
|
||||
//go:generate GetRequest -url "/api/v3/wallet/m/repayments" -type GetMarginRepaymentHistoryRequest -responseType []RepaymentRecord
|
||||
type GetMarginRepaymentHistoryRequest struct {
|
||||
client requestgen.AuthenticatedAPIClient
|
||||
|
||||
currency string `param:"currency,required"`
|
||||
startTime *time.Time `param:"startTime,milliseconds"`
|
||||
endTime *time.Time `param:"endTime,milliseconds"`
|
||||
limit *int `param:"limit"`
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by "requestgen -method GET -url /api/v3/wallet/m/repayments/:currency -type GetMarginRepaymentHistoryRequest -responseType []RepaymentRecord"; DO NOT EDIT.
|
||||
// Code generated by "requestgen -method GET -url /api/v3/wallet/m/repayments -type GetMarginRepaymentHistoryRequest -responseType []RepaymentRecord"; DO NOT EDIT.
|
||||
|
||||
package v3
|
||||
|
||||
|
@ -13,6 +13,11 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func (g *GetMarginRepaymentHistoryRequest) Currency(currency string) *GetMarginRepaymentHistoryRequest {
|
||||
g.currency = currency
|
||||
return g
|
||||
}
|
||||
|
||||
func (g *GetMarginRepaymentHistoryRequest) StartTime(startTime time.Time) *GetMarginRepaymentHistoryRequest {
|
||||
g.startTime = &startTime
|
||||
return g
|
||||
|
@ -28,11 +33,6 @@ func (g *GetMarginRepaymentHistoryRequest) Limit(limit int) *GetMarginRepaymentH
|
|||
return g
|
||||
}
|
||||
|
||||
func (g *GetMarginRepaymentHistoryRequest) Currency(currency string) *GetMarginRepaymentHistoryRequest {
|
||||
g.currency = currency
|
||||
return g
|
||||
}
|
||||
|
||||
// GetQueryParameters builds and checks the query parameters and returns url.Values
|
||||
func (g *GetMarginRepaymentHistoryRequest) GetQueryParameters() (url.Values, error) {
|
||||
var params = map[string]interface{}{}
|
||||
|
@ -48,6 +48,17 @@ func (g *GetMarginRepaymentHistoryRequest) GetQueryParameters() (url.Values, err
|
|||
// GetParameters builds and checks the parameters and return the result in a map object
|
||||
func (g *GetMarginRepaymentHistoryRequest) GetParameters() (map[string]interface{}, error) {
|
||||
var params = map[string]interface{}{}
|
||||
// check currency field -> json key currency
|
||||
currency := g.currency
|
||||
|
||||
// TEMPLATE check-required
|
||||
if len(currency) == 0 {
|
||||
return nil, fmt.Errorf("currency is required, empty string given")
|
||||
}
|
||||
// END TEMPLATE check-required
|
||||
|
||||
// assign parameter of currency
|
||||
params["currency"] = currency
|
||||
// check startTime field -> json key startTime
|
||||
if g.startTime != nil {
|
||||
startTime := *g.startTime
|
||||
|
@ -113,17 +124,6 @@ func (g *GetMarginRepaymentHistoryRequest) GetParametersJSON() ([]byte, error) {
|
|||
// GetSlugParameters builds and checks the slug parameters and return the result in a map object
|
||||
func (g *GetMarginRepaymentHistoryRequest) GetSlugParameters() (map[string]interface{}, error) {
|
||||
var params = map[string]interface{}{}
|
||||
// check currency field -> json key currency
|
||||
currency := g.currency
|
||||
|
||||
// TEMPLATE check-required
|
||||
if len(currency) == 0 {
|
||||
return nil, fmt.Errorf("currency is required, empty string given")
|
||||
}
|
||||
// END TEMPLATE check-required
|
||||
|
||||
// assign parameter of currency
|
||||
params["currency"] = currency
|
||||
|
||||
return params, nil
|
||||
}
|
||||
|
@ -177,13 +177,7 @@ func (g *GetMarginRepaymentHistoryRequest) Do(ctx context.Context) ([]RepaymentR
|
|||
return nil, err
|
||||
}
|
||||
|
||||
apiURL := "/api/v3/wallet/m/repayments/:currency"
|
||||
slugs, err := g.GetSlugsMap()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
apiURL = g.applySlugsToUrl(apiURL, slugs)
|
||||
apiURL := "/api/v3/wallet/m/repayments"
|
||||
|
||||
req, err := g.client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params)
|
||||
if err != nil {
|
||||
|
|
|
@ -6,7 +6,7 @@ package v3
|
|||
|
||||
import "github.com/c9s/requestgen"
|
||||
|
||||
func (s *OrderService) NewGetOrderRequest() *GetOrderRequest {
|
||||
func (s *Client) NewGetOrderRequest() *GetOrderRequest {
|
||||
return &GetOrderRequest{client: s.Client}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ package v3
|
|||
|
||||
import "github.com/c9s/requestgen"
|
||||
|
||||
func (s *OrderService) NewGetOrderTradesRequest() *GetOrderTradesRequest {
|
||||
func (s *Client) NewGetOrderTradesRequest() *GetOrderTradesRequest {
|
||||
return &GetOrderTradesRequest{client: s.Client}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,13 +6,14 @@ import "github.com/c9s/requestgen"
|
|||
//go:generate -command PostRequest requestgen -method POST
|
||||
//go:generate -command DeleteRequest requestgen -method DELETE
|
||||
|
||||
func (s *OrderService) NewGetWalletAccountsRequest(walletType WalletType) *GetWalletAccountsRequest {
|
||||
return &GetWalletAccountsRequest{client: s.Client, walletType: walletType}
|
||||
}
|
||||
|
||||
//go:generate GetRequest -url "/api/v3/wallet/:walletType/accounts" -type GetWalletAccountsRequest -responseType []Account
|
||||
type GetWalletAccountsRequest struct {
|
||||
client requestgen.AuthenticatedAPIClient
|
||||
|
||||
walletType WalletType `param:"walletType,slug,required"`
|
||||
currency string `param:"currency"`
|
||||
}
|
||||
|
||||
func (s *Client) NewGetWalletAccountsRequest(walletType WalletType) *GetWalletAccountsRequest {
|
||||
return &GetWalletAccountsRequest{client: s.Client, walletType: walletType}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,11 @@ import (
|
|||
"regexp"
|
||||
)
|
||||
|
||||
func (g *GetWalletAccountsRequest) Currency(currency string) *GetWalletAccountsRequest {
|
||||
g.currency = currency
|
||||
return g
|
||||
}
|
||||
|
||||
func (g *GetWalletAccountsRequest) WalletType(walletType max.WalletType) *GetWalletAccountsRequest {
|
||||
g.walletType = walletType
|
||||
return g
|
||||
|
@ -32,6 +37,11 @@ func (g *GetWalletAccountsRequest) GetQueryParameters() (url.Values, error) {
|
|||
// GetParameters builds and checks the parameters and return the result in a map object
|
||||
func (g *GetWalletAccountsRequest) GetParameters() (map[string]interface{}, error) {
|
||||
var params = map[string]interface{}{}
|
||||
// check currency field -> json key currency
|
||||
currency := g.currency
|
||||
|
||||
// assign parameter of currency
|
||||
params["currency"] = currency
|
||||
|
||||
return params, nil
|
||||
}
|
||||
|
@ -128,9 +138,12 @@ func (g *GetWalletAccountsRequest) GetSlugsMap() (map[string]string, error) {
|
|||
|
||||
func (g *GetWalletAccountsRequest) Do(ctx context.Context) ([]max.Account, error) {
|
||||
|
||||
// no body params
|
||||
// empty params for GET operation
|
||||
var params interface{}
|
||||
query := url.Values{}
|
||||
query, err := g.GetParametersQuery()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
apiURL := "/api/v3/wallet/:walletType/accounts"
|
||||
slugs, err := g.GetSlugsMap()
|
||||
|
|
|
@ -6,7 +6,7 @@ import "github.com/c9s/requestgen"
|
|||
//go:generate -command PostRequest requestgen -method POST
|
||||
//go:generate -command DeleteRequest requestgen -method DELETE
|
||||
|
||||
func (s *OrderService) NewGetWalletOpenOrdersRequest(walletType WalletType) *GetWalletOpenOrdersRequest {
|
||||
func (s *Client) NewGetWalletOpenOrdersRequest(walletType WalletType) *GetWalletOpenOrdersRequest {
|
||||
return &GetWalletOpenOrdersRequest{client: s.Client, walletType: walletType}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import "github.com/c9s/requestgen"
|
|||
//go:generate -command PostRequest requestgen -method POST
|
||||
//go:generate -command DeleteRequest requestgen -method DELETE
|
||||
|
||||
func (s *OrderService) NewGetWalletOrderHistoryRequest(walletType WalletType) *GetWalletOrderHistoryRequest {
|
||||
func (s *Client) NewGetWalletOrderHistoryRequest(walletType WalletType) *GetWalletOrderHistoryRequest {
|
||||
return &GetWalletOrderHistoryRequest{client: s.Client, walletType: walletType}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/c9s/requestgen"
|
||||
)
|
||||
|
||||
func (s *OrderService) NewGetWalletTradesRequest(walletType WalletType) *GetWalletTradesRequest {
|
||||
func (s *Client) NewGetWalletTradesRequest(walletType WalletType) *GetWalletTradesRequest {
|
||||
return &GetWalletTradesRequest{client: s.Client, walletType: walletType}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,156 +5,23 @@ package v3
|
|||
//go:generate -command DeleteRequest requestgen -method DELETE
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/c9s/requestgen"
|
||||
|
||||
maxapi "github.com/c9s/bbgo/pkg/exchange/max/maxapi"
|
||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
type MarginService struct {
|
||||
Client *maxapi.RestClient
|
||||
}
|
||||
|
||||
func (s *MarginService) NewGetMarginInterestRatesRequest() *GetMarginInterestRatesRequest {
|
||||
return &GetMarginInterestRatesRequest{client: s.Client}
|
||||
}
|
||||
|
||||
func (s *MarginService) NewGetMarginBorrowingLimitsRequest() *GetMarginBorrowingLimitsRequest {
|
||||
func (s *Client) NewGetMarginBorrowingLimitsRequest() *GetMarginBorrowingLimitsRequest {
|
||||
return &GetMarginBorrowingLimitsRequest{client: s.Client}
|
||||
}
|
||||
|
||||
func (s *MarginService) NewGetMarginInterestHistoryRequest(currency string) *GetMarginInterestHistoryRequest {
|
||||
return &GetMarginInterestHistoryRequest{client: s.Client, currency: currency}
|
||||
}
|
||||
|
||||
func (s *MarginService) NewGetMarginLiquidationHistoryRequest() *GetMarginLiquidationHistoryRequest {
|
||||
return &GetMarginLiquidationHistoryRequest{client: s.Client}
|
||||
}
|
||||
|
||||
func (s *MarginService) NewGetMarginLoanHistoryRequest() *GetMarginLoanHistoryRequest {
|
||||
return &GetMarginLoanHistoryRequest{client: s.Client}
|
||||
}
|
||||
|
||||
func (s *MarginService) NewMarginRepayRequest() *MarginRepayRequest {
|
||||
return &MarginRepayRequest{client: s.Client}
|
||||
}
|
||||
|
||||
func (s *MarginService) NewMarginLoanRequest() *MarginLoanRequest {
|
||||
return &MarginLoanRequest{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
|
||||
type GetMarginBorrowingLimitsRequest struct {
|
||||
client requestgen.APIClient
|
||||
}
|
||||
|
||||
type MarginInterestRecord struct {
|
||||
Currency string `json:"currency"`
|
||||
Amount fixedpoint.Value `json:"amount"`
|
||||
InterestRate fixedpoint.Value `json:"interest_rate"`
|
||||
CreatedAt types.MillisecondTimestamp `json:"created_at"`
|
||||
}
|
||||
|
||||
//go:generate GetRequest -url "/api/v3/wallet/m/interests/history/:currency" -type GetMarginInterestHistoryRequest -responseType []MarginInterestRecord
|
||||
type GetMarginInterestHistoryRequest struct {
|
||||
client requestgen.AuthenticatedAPIClient
|
||||
|
||||
currency string `param:"currency,slug,required"`
|
||||
startTime *time.Time `param:"startTime,milliseconds"`
|
||||
endTime *time.Time `param:"endTime,milliseconds"`
|
||||
limit *int `param:"limit"`
|
||||
}
|
||||
|
||||
type LiquidationRecord struct {
|
||||
SN string `json:"sn"`
|
||||
AdRatio fixedpoint.Value `json:"ad_ratio"`
|
||||
ExpectedAdRatio fixedpoint.Value `json:"expected_ad_ratio"`
|
||||
CreatedAt types.MillisecondTimestamp `json:"created_at"`
|
||||
State LiquidationState `json:"state"`
|
||||
}
|
||||
|
||||
type LiquidationState string
|
||||
|
||||
const (
|
||||
LiquidationStateProcessing LiquidationState = "processing"
|
||||
LiquidationStateDebt LiquidationState = "debt"
|
||||
LiquidationStateLiquidated LiquidationState = "liquidated"
|
||||
)
|
||||
|
||||
//go:generate GetRequest -url "/api/v3/wallet/m/liquidations" -type GetMarginLiquidationHistoryRequest -responseType []LiquidationRecord
|
||||
type GetMarginLiquidationHistoryRequest struct {
|
||||
client requestgen.AuthenticatedAPIClient
|
||||
startTime *time.Time `param:"startTime,milliseconds"`
|
||||
endTime *time.Time `param:"endTime,milliseconds"`
|
||||
limit *int `param:"limit"`
|
||||
}
|
||||
|
||||
type RepaymentRecord struct {
|
||||
SN string `json:"sn"`
|
||||
Currency string `json:"currency"`
|
||||
Amount fixedpoint.Value `json:"amount"`
|
||||
Principal fixedpoint.Value `json:"principal"`
|
||||
Interest fixedpoint.Value `json:"interest"`
|
||||
CreatedAt types.MillisecondTimestamp `json:"created_at"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
|
||||
//go:generate GetRequest -url "/api/v3/wallet/m/repayments/:currency" -type GetMarginRepaymentHistoryRequest -responseType []RepaymentRecord
|
||||
type GetMarginRepaymentHistoryRequest struct {
|
||||
client requestgen.AuthenticatedAPIClient
|
||||
currency string `param:"currency,slug,required"`
|
||||
|
||||
startTime *time.Time `param:"startTime,milliseconds"`
|
||||
endTime *time.Time `param:"endTime,milliseconds"`
|
||||
limit *int `param:"limit"`
|
||||
}
|
||||
|
||||
type LoanRecord struct {
|
||||
SN string `json:"sn"`
|
||||
Currency string `json:"currency"`
|
||||
Amount fixedpoint.Value `json:"amount"`
|
||||
State string `json:"state"`
|
||||
CreatedAt types.MillisecondTimestamp `json:"created_at"`
|
||||
InterestRate fixedpoint.Value `json:"interest_rate"`
|
||||
}
|
||||
|
||||
//go:generate GetRequest -url "/api/v3/wallet/m/loans/:currency" -type GetMarginLoanHistoryRequest -responseType []LoanRecord
|
||||
type GetMarginLoanHistoryRequest struct {
|
||||
client requestgen.AuthenticatedAPIClient
|
||||
currency string `param:"currency,slug,required"`
|
||||
|
||||
startTime *time.Time `param:"startTime,milliseconds"`
|
||||
endTime *time.Time `param:"endTime,milliseconds"`
|
||||
limit *int `param:"limit"`
|
||||
}
|
||||
|
||||
//go:generate PostRequest -url "/api/v3/wallet/m/loan/:currency" -type MarginLoanRequest -responseType .LoanRecord
|
||||
type MarginLoanRequest struct {
|
||||
client requestgen.AuthenticatedAPIClient
|
||||
currency string `param:"currency,slug,required"`
|
||||
amount string `param:"amount"`
|
||||
}
|
||||
|
||||
//go:generate PostRequest -url "/api/v3/wallet/m/repayment/:currency" -type MarginRepayRequest -responseType .RepaymentRecord
|
||||
type MarginRepayRequest struct {
|
||||
client requestgen.AuthenticatedAPIClient
|
||||
currency string `param:"currency,slug,required"`
|
||||
amount string `param:"amount"`
|
||||
}
|
||||
|
|
19
pkg/exchange/max/maxapi/v3/margin_loan_request.go
Normal file
19
pkg/exchange/max/maxapi/v3/margin_loan_request.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
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"
|
||||
|
||||
func (s *Client) NewMarginLoanRequest() *MarginLoanRequest {
|
||||
return &MarginLoanRequest{client: s.Client}
|
||||
}
|
||||
|
||||
//go:generate PostRequest -url "/api/v3/wallet/m/loan" -type MarginLoanRequest -responseType .LoanRecord
|
||||
type MarginLoanRequest struct {
|
||||
client requestgen.AuthenticatedAPIClient
|
||||
|
||||
currency string `param:"currency,required"`
|
||||
amount string `param:"amount"`
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by "requestgen -method POST -url /api/v3/wallet/m/loan/:currency -type MarginLoanRequest -responseType .LoanRecord"; DO NOT EDIT.
|
||||
// Code generated by "requestgen -method POST -url /api/v3/wallet/m/loan -type MarginLoanRequest -responseType .LoanRecord"; DO NOT EDIT.
|
||||
|
||||
package v3
|
||||
|
||||
|
@ -11,13 +11,13 @@ import (
|
|||
"regexp"
|
||||
)
|
||||
|
||||
func (m *MarginLoanRequest) Amount(amount string) *MarginLoanRequest {
|
||||
m.amount = amount
|
||||
func (m *MarginLoanRequest) Currency(currency string) *MarginLoanRequest {
|
||||
m.currency = currency
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *MarginLoanRequest) Currency(currency string) *MarginLoanRequest {
|
||||
m.currency = currency
|
||||
func (m *MarginLoanRequest) Amount(amount string) *MarginLoanRequest {
|
||||
m.amount = amount
|
||||
return m
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,17 @@ func (m *MarginLoanRequest) GetQueryParameters() (url.Values, error) {
|
|||
// GetParameters builds and checks the parameters and return the result in a map object
|
||||
func (m *MarginLoanRequest) GetParameters() (map[string]interface{}, error) {
|
||||
var params = map[string]interface{}{}
|
||||
// check currency field -> json key currency
|
||||
currency := m.currency
|
||||
|
||||
// TEMPLATE check-required
|
||||
if len(currency) == 0 {
|
||||
return nil, fmt.Errorf("currency is required, empty string given")
|
||||
}
|
||||
// END TEMPLATE check-required
|
||||
|
||||
// assign parameter of currency
|
||||
params["currency"] = currency
|
||||
// check amount field -> json key amount
|
||||
amount := m.amount
|
||||
|
||||
|
@ -80,17 +91,6 @@ func (m *MarginLoanRequest) GetParametersJSON() ([]byte, error) {
|
|||
// GetSlugParameters builds and checks the slug parameters and return the result in a map object
|
||||
func (m *MarginLoanRequest) GetSlugParameters() (map[string]interface{}, error) {
|
||||
var params = map[string]interface{}{}
|
||||
// check currency field -> json key currency
|
||||
currency := m.currency
|
||||
|
||||
// TEMPLATE check-required
|
||||
if len(currency) == 0 {
|
||||
return nil, fmt.Errorf("currency is required, empty string given")
|
||||
}
|
||||
// END TEMPLATE check-required
|
||||
|
||||
// assign parameter of currency
|
||||
params["currency"] = currency
|
||||
|
||||
return params, nil
|
||||
}
|
||||
|
@ -143,13 +143,7 @@ func (m *MarginLoanRequest) Do(ctx context.Context) (*LoanRecord, error) {
|
|||
}
|
||||
query := url.Values{}
|
||||
|
||||
apiURL := "/api/v3/wallet/m/loan/:currency"
|
||||
slugs, err := m.GetSlugsMap()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
apiURL = m.applySlugsToUrl(apiURL, slugs)
|
||||
apiURL := "/api/v3/wallet/m/loan"
|
||||
|
||||
req, err := m.client.NewAuthenticatedRequest(ctx, "POST", apiURL, query, params)
|
||||
if err != nil {
|
||||
|
|
19
pkg/exchange/max/maxapi/v3/margin_repay_request.go
Normal file
19
pkg/exchange/max/maxapi/v3/margin_repay_request.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
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"
|
||||
|
||||
//go:generate PostRequest -url "/api/v3/wallet/m/repayment" -type MarginRepayRequest -responseType .RepaymentRecord
|
||||
type MarginRepayRequest struct {
|
||||
client requestgen.AuthenticatedAPIClient
|
||||
|
||||
currency string `param:"currency,required"`
|
||||
amount string `param:"amount"`
|
||||
}
|
||||
|
||||
func (s *Client) NewMarginRepayRequest() *MarginRepayRequest {
|
||||
return &MarginRepayRequest{client: s.Client}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by "requestgen -method POST -url /api/v3/wallet/m/repayment/:currency -type MarginRepayRequest -responseType .RepaymentRecord"; DO NOT EDIT.
|
||||
// Code generated by "requestgen -method POST -url /api/v3/wallet/m/repayment -type MarginRepayRequest -responseType .RepaymentRecord"; DO NOT EDIT.
|
||||
|
||||
package v3
|
||||
|
||||
|
@ -11,13 +11,13 @@ import (
|
|||
"regexp"
|
||||
)
|
||||
|
||||
func (m *MarginRepayRequest) Amount(amount string) *MarginRepayRequest {
|
||||
m.amount = amount
|
||||
func (m *MarginRepayRequest) Currency(currency string) *MarginRepayRequest {
|
||||
m.currency = currency
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *MarginRepayRequest) Currency(currency string) *MarginRepayRequest {
|
||||
m.currency = currency
|
||||
func (m *MarginRepayRequest) Amount(amount string) *MarginRepayRequest {
|
||||
m.amount = amount
|
||||
return m
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,17 @@ func (m *MarginRepayRequest) GetQueryParameters() (url.Values, error) {
|
|||
// GetParameters builds and checks the parameters and return the result in a map object
|
||||
func (m *MarginRepayRequest) GetParameters() (map[string]interface{}, error) {
|
||||
var params = map[string]interface{}{}
|
||||
// check currency field -> json key currency
|
||||
currency := m.currency
|
||||
|
||||
// TEMPLATE check-required
|
||||
if len(currency) == 0 {
|
||||
return nil, fmt.Errorf("currency is required, empty string given")
|
||||
}
|
||||
// END TEMPLATE check-required
|
||||
|
||||
// assign parameter of currency
|
||||
params["currency"] = currency
|
||||
// check amount field -> json key amount
|
||||
amount := m.amount
|
||||
|
||||
|
@ -80,17 +91,6 @@ func (m *MarginRepayRequest) GetParametersJSON() ([]byte, error) {
|
|||
// GetSlugParameters builds and checks the slug parameters and return the result in a map object
|
||||
func (m *MarginRepayRequest) GetSlugParameters() (map[string]interface{}, error) {
|
||||
var params = map[string]interface{}{}
|
||||
// check currency field -> json key currency
|
||||
currency := m.currency
|
||||
|
||||
// TEMPLATE check-required
|
||||
if len(currency) == 0 {
|
||||
return nil, fmt.Errorf("currency is required, empty string given")
|
||||
}
|
||||
// END TEMPLATE check-required
|
||||
|
||||
// assign parameter of currency
|
||||
params["currency"] = currency
|
||||
|
||||
return params, nil
|
||||
}
|
||||
|
@ -143,13 +143,7 @@ func (m *MarginRepayRequest) Do(ctx context.Context) (*RepaymentRecord, error) {
|
|||
}
|
||||
query := url.Values{}
|
||||
|
||||
apiURL := "/api/v3/wallet/m/repayment/:currency"
|
||||
slugs, err := m.GetSlugsMap()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
apiURL = m.applySlugsToUrl(apiURL, slugs)
|
||||
apiURL := "/api/v3/wallet/m/repayment"
|
||||
|
||||
req, err := m.client.NewAuthenticatedRequest(ctx, "POST", apiURL, query, params)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
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"
|
||||
|
||||
|
@ -17,7 +13,6 @@ type OrderType = maxapi.OrderType
|
|||
type Order = maxapi.Order
|
||||
type Account = maxapi.Account
|
||||
|
||||
// OrderService manages the Order endpoint.
|
||||
type OrderService struct {
|
||||
type Client struct {
|
||||
Client requestgen.AuthenticatedAPIClient
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user