From 0aa606ebcb13e97faf201690b02899796f53df6b Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 16 Jun 2022 16:03:12 +0800 Subject: [PATCH 1/2] maxapi: drop unused v2 api --- pkg/exchange/max/maxapi/account.go | 10 - .../maxapi/create_order_request_requestgen.go | 247 ------------------ .../max/maxapi/get_me_request_requestgen.go | 135 ---------- .../maxapi/get_order_request_requestgen.go | 164 ------------ .../maxapi/get_orders_request_requestgen.go | 240 ----------------- pkg/exchange/max/maxapi/order.go | 76 ------ .../order_cancel_all_request_requestgen.go | 176 ------------- .../maxapi/order_cancel_request_requestgen.go | 163 ------------ pkg/exchange/max/maxapi/order_test.go | 77 ------ 9 files changed, 1288 deletions(-) delete mode 100644 pkg/exchange/max/maxapi/create_order_request_requestgen.go delete mode 100644 pkg/exchange/max/maxapi/get_me_request_requestgen.go delete mode 100644 pkg/exchange/max/maxapi/get_order_request_requestgen.go delete mode 100644 pkg/exchange/max/maxapi/get_orders_request_requestgen.go delete mode 100644 pkg/exchange/max/maxapi/order_cancel_all_request_requestgen.go delete mode 100644 pkg/exchange/max/maxapi/order_cancel_request_requestgen.go diff --git a/pkg/exchange/max/maxapi/account.go b/pkg/exchange/max/maxapi/account.go index a4aed9e50..bdefd4c60 100644 --- a/pkg/exchange/max/maxapi/account.go +++ b/pkg/exchange/max/maxapi/account.go @@ -101,16 +101,6 @@ func (s *AccountService) NewGetAccountsRequest() *GetAccountsRequest { return &GetAccountsRequest{client: s.client} } -//go:generate GetRequest -url "v2/members/me" -type GetMeRequest -responseType .UserInfo -type GetMeRequest struct { - client requestgen.AuthenticatedAPIClient -} - -// NewGetMeRequest returns the current user info by the current used MAX key and secret -func (s *AccountService) NewGetMeRequest() *GetMeRequest { - return &GetMeRequest{client: s.client} -} - type Deposit struct { Currency string `json:"currency"` CurrencyVersion string `json:"currency_version"` // "eth" diff --git a/pkg/exchange/max/maxapi/create_order_request_requestgen.go b/pkg/exchange/max/maxapi/create_order_request_requestgen.go deleted file mode 100644 index 62d0572d6..000000000 --- a/pkg/exchange/max/maxapi/create_order_request_requestgen.go +++ /dev/null @@ -1,247 +0,0 @@ -// Code generated by "requestgen -method POST -url v2/orders -type CreateOrderRequest -responseType .Order"; DO NOT EDIT. - -package max - -import ( - "context" - "encoding/json" - "fmt" - "net/url" - "reflect" - "regexp" -) - -func (c *CreateOrderRequest) Market(market string) *CreateOrderRequest { - c.market = market - return c -} - -func (c *CreateOrderRequest) Side(side string) *CreateOrderRequest { - c.side = side - return c -} - -func (c *CreateOrderRequest) Volume(volume string) *CreateOrderRequest { - c.volume = volume - return c -} - -func (c *CreateOrderRequest) OrderType(orderType string) *CreateOrderRequest { - c.orderType = orderType - return c -} - -func (c *CreateOrderRequest) Price(price string) *CreateOrderRequest { - c.price = &price - return c -} - -func (c *CreateOrderRequest) StopPrice(stopPrice string) *CreateOrderRequest { - c.stopPrice = &stopPrice - return c -} - -func (c *CreateOrderRequest) ClientOrderID(clientOrderID string) *CreateOrderRequest { - c.clientOrderID = &clientOrderID - return c -} - -func (c *CreateOrderRequest) GroupID(groupID string) *CreateOrderRequest { - c.groupID = &groupID - return c -} - -// GetQueryParameters builds and checks the query parameters and returns url.Values -func (c *CreateOrderRequest) GetQueryParameters() (url.Values, error) { - var params = map[string]interface{}{} - - query := url.Values{} - for _k, _v := range params { - query.Add(_k, fmt.Sprintf("%v", _v)) - } - - return query, nil -} - -// GetParameters builds and checks the parameters and return the result in a map object -func (c *CreateOrderRequest) GetParameters() (map[string]interface{}, error) { - var params = map[string]interface{}{} - // check market field -> json key market - market := c.market - - // TEMPLATE check-required - if len(market) == 0 { - return nil, fmt.Errorf("market is required, empty string given") - } - // END TEMPLATE check-required - - // assign parameter of market - params["market"] = market - // check side field -> json key side - side := c.side - - // TEMPLATE check-required - if len(side) == 0 { - return nil, fmt.Errorf("side is required, empty string given") - } - // END TEMPLATE check-required - - // assign parameter of side - params["side"] = side - // check volume field -> json key volume - volume := c.volume - - // TEMPLATE check-required - if len(volume) == 0 { - return nil, fmt.Errorf("volume is required, empty string given") - } - // END TEMPLATE check-required - - // assign parameter of volume - params["volume"] = volume - // check orderType field -> json key ord_type - orderType := c.orderType - - // assign parameter of orderType - params["ord_type"] = orderType - // check price field -> json key price - if c.price != nil { - price := *c.price - - // assign parameter of price - params["price"] = price - } else { - } - // check stopPrice field -> json key stop_price - if c.stopPrice != nil { - stopPrice := *c.stopPrice - - // assign parameter of stopPrice - params["stop_price"] = stopPrice - } else { - } - // check clientOrderID field -> json key client_oid - if c.clientOrderID != nil { - clientOrderID := *c.clientOrderID - - // assign parameter of clientOrderID - params["client_oid"] = clientOrderID - } else { - } - // check groupID field -> json key group_id - if c.groupID != nil { - groupID := *c.groupID - - // assign parameter of groupID - params["group_id"] = groupID - } else { - } - - return params, nil -} - -// GetParametersQuery converts the parameters from GetParameters into the url.Values format -func (c *CreateOrderRequest) GetParametersQuery() (url.Values, error) { - query := url.Values{} - - params, err := c.GetParameters() - if err != nil { - return query, err - } - - for _k, _v := range params { - if c.isVarSlice(_v) { - c.iterateSlice(_v, func(it interface{}) { - query.Add(_k+"[]", fmt.Sprintf("%v", it)) - }) - } else { - query.Add(_k, fmt.Sprintf("%v", _v)) - } - } - - return query, nil -} - -// GetParametersJSON converts the parameters from GetParameters into the JSON format -func (c *CreateOrderRequest) GetParametersJSON() ([]byte, error) { - params, err := c.GetParameters() - if err != nil { - return nil, err - } - - return json.Marshal(params) -} - -// GetSlugParameters builds and checks the slug parameters and return the result in a map object -func (c *CreateOrderRequest) GetSlugParameters() (map[string]interface{}, error) { - var params = map[string]interface{}{} - - return params, nil -} - -func (c *CreateOrderRequest) applySlugsToUrl(url string, slugs map[string]string) string { - for _k, _v := range slugs { - needleRE := regexp.MustCompile(":" + _k + "\\b") - url = needleRE.ReplaceAllString(url, _v) - } - - return url -} - -func (c *CreateOrderRequest) iterateSlice(slice interface{}, _f func(it interface{})) { - sliceValue := reflect.ValueOf(slice) - for _i := 0; _i < sliceValue.Len(); _i++ { - it := sliceValue.Index(_i).Interface() - _f(it) - } -} - -func (c *CreateOrderRequest) isVarSlice(_v interface{}) bool { - rt := reflect.TypeOf(_v) - switch rt.Kind() { - case reflect.Slice: - return true - } - return false -} - -func (c *CreateOrderRequest) GetSlugsMap() (map[string]string, error) { - slugs := map[string]string{} - params, err := c.GetSlugParameters() - if err != nil { - return slugs, nil - } - - for _k, _v := range params { - slugs[_k] = fmt.Sprintf("%v", _v) - } - - return slugs, nil -} - -func (c *CreateOrderRequest) Do(ctx context.Context) (*Order, error) { - - params, err := c.GetParameters() - if err != nil { - return nil, err - } - query := url.Values{} - - apiURL := "v2/orders" - - req, err := c.client.NewAuthenticatedRequest(ctx, "POST", apiURL, query, params) - if err != nil { - return nil, err - } - - response, err := c.client.SendRequest(req) - if err != nil { - return nil, err - } - - var apiResponse Order - if err := response.DecodeJSON(&apiResponse); err != nil { - return nil, err - } - return &apiResponse, nil -} diff --git a/pkg/exchange/max/maxapi/get_me_request_requestgen.go b/pkg/exchange/max/maxapi/get_me_request_requestgen.go deleted file mode 100644 index 1d7317843..000000000 --- a/pkg/exchange/max/maxapi/get_me_request_requestgen.go +++ /dev/null @@ -1,135 +0,0 @@ -// Code generated by "requestgen -method GET -url v2/members/me -type GetMeRequest -responseType .UserInfo"; DO NOT EDIT. - -package max - -import ( - "context" - "encoding/json" - "fmt" - "net/url" - "reflect" - "regexp" -) - -// GetQueryParameters builds and checks the query parameters and returns url.Values -func (g *GetMeRequest) GetQueryParameters() (url.Values, error) { - var params = map[string]interface{}{} - - query := url.Values{} - for k, v := range params { - query.Add(k, fmt.Sprintf("%v", v)) - } - - return query, nil -} - -// GetParameters builds and checks the parameters and return the result in a map object -func (g *GetMeRequest) GetParameters() (map[string]interface{}, error) { - var params = map[string]interface{}{} - - return params, nil -} - -// GetParametersQuery converts the parameters from GetParameters into the url.Values format -func (g *GetMeRequest) GetParametersQuery() (url.Values, error) { - query := url.Values{} - - params, err := g.GetParameters() - if err != nil { - return query, err - } - - for k, v := range params { - if g.isVarSlice(v) { - g.iterateSlice(v, func(it interface{}) { - query.Add(k+"[]", fmt.Sprintf("%v", it)) - }) - } else { - query.Add(k, fmt.Sprintf("%v", v)) - } - } - - return query, nil -} - -// GetParametersJSON converts the parameters from GetParameters into the JSON format -func (g *GetMeRequest) GetParametersJSON() ([]byte, error) { - params, err := g.GetParameters() - if err != nil { - return nil, err - } - - return json.Marshal(params) -} - -// GetSlugParameters builds and checks the slug parameters and return the result in a map object -func (g *GetMeRequest) GetSlugParameters() (map[string]interface{}, error) { - var params = map[string]interface{}{} - - return params, nil -} - -func (g *GetMeRequest) applySlugsToUrl(url string, slugs map[string]string) string { - for k, v := range slugs { - needleRE := regexp.MustCompile(":" + k + "\\b") - url = needleRE.ReplaceAllString(url, v) - } - - return url -} - -func (g *GetMeRequest) iterateSlice(slice interface{}, f func(it interface{})) { - sliceValue := reflect.ValueOf(slice) - for i := 0; i < sliceValue.Len(); i++ { - it := sliceValue.Index(i).Interface() - f(it) - } -} - -func (g *GetMeRequest) isVarSlice(v interface{}) bool { - rt := reflect.TypeOf(v) - switch rt.Kind() { - case reflect.Slice: - return true - } - return false -} - -func (g *GetMeRequest) GetSlugsMap() (map[string]string, error) { - slugs := map[string]string{} - params, err := g.GetSlugParameters() - if err != nil { - return slugs, nil - } - - for k, v := range params { - slugs[k] = fmt.Sprintf("%v", v) - } - - return slugs, nil -} - -func (g *GetMeRequest) Do(ctx context.Context) (*UserInfo, error) { - - // no body params - var params interface{} - query := url.Values{} - - apiURL := "v2/members/me" - - req, err := g.client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params) - if err != nil { - return nil, err - } - - response, err := g.client.SendRequest(req) - if err != nil { - return nil, err - } - - var apiResponse UserInfo - if err := response.DecodeJSON(&apiResponse); err != nil { - return nil, err - } - return &apiResponse, nil -} diff --git a/pkg/exchange/max/maxapi/get_order_request_requestgen.go b/pkg/exchange/max/maxapi/get_order_request_requestgen.go deleted file mode 100644 index c29ef52cd..000000000 --- a/pkg/exchange/max/maxapi/get_order_request_requestgen.go +++ /dev/null @@ -1,164 +0,0 @@ -// Code generated by "requestgen -method GET -url v2/order -type GetOrderRequest -responseType .Order"; DO NOT EDIT. - -package max - -import ( - "context" - "encoding/json" - "fmt" - "net/url" - "reflect" - "regexp" -) - -func (g *GetOrderRequest) Id(id uint64) *GetOrderRequest { - g.id = &id - return g -} - -func (g *GetOrderRequest) ClientOrderID(clientOrderID string) *GetOrderRequest { - g.clientOrderID = &clientOrderID - return g -} - -// GetQueryParameters builds and checks the query parameters and returns url.Values -func (g *GetOrderRequest) GetQueryParameters() (url.Values, error) { - var params = map[string]interface{}{} - - query := url.Values{} - for _k, _v := range params { - query.Add(_k, fmt.Sprintf("%v", _v)) - } - - return query, nil -} - -// GetParameters builds and checks the parameters and return the result in a map object -func (g *GetOrderRequest) GetParameters() (map[string]interface{}, error) { - var params = map[string]interface{}{} - // check id field -> json key id - if g.id != nil { - id := *g.id - - // assign parameter of id - params["id"] = id - } else { - } - // check clientOrderID field -> json key client_oid - if g.clientOrderID != nil { - clientOrderID := *g.clientOrderID - - // assign parameter of clientOrderID - params["client_oid"] = clientOrderID - } else { - } - - return params, nil -} - -// GetParametersQuery converts the parameters from GetParameters into the url.Values format -func (g *GetOrderRequest) GetParametersQuery() (url.Values, error) { - query := url.Values{} - - params, err := g.GetParameters() - if err != nil { - return query, err - } - - for _k, _v := range params { - if g.isVarSlice(_v) { - g.iterateSlice(_v, func(it interface{}) { - query.Add(_k+"[]", fmt.Sprintf("%v", it)) - }) - } else { - query.Add(_k, fmt.Sprintf("%v", _v)) - } - } - - return query, nil -} - -// GetParametersJSON converts the parameters from GetParameters into the JSON format -func (g *GetOrderRequest) GetParametersJSON() ([]byte, error) { - params, err := g.GetParameters() - if err != nil { - return nil, err - } - - return json.Marshal(params) -} - -// GetSlugParameters builds and checks the slug parameters and return the result in a map object -func (g *GetOrderRequest) GetSlugParameters() (map[string]interface{}, error) { - var params = map[string]interface{}{} - - return params, nil -} - -func (g *GetOrderRequest) applySlugsToUrl(url string, slugs map[string]string) string { - for _k, _v := range slugs { - needleRE := regexp.MustCompile(":" + _k + "\\b") - url = needleRE.ReplaceAllString(url, _v) - } - - return url -} - -func (g *GetOrderRequest) iterateSlice(slice interface{}, _f func(it interface{})) { - sliceValue := reflect.ValueOf(slice) - for _i := 0; _i < sliceValue.Len(); _i++ { - it := sliceValue.Index(_i).Interface() - _f(it) - } -} - -func (g *GetOrderRequest) isVarSlice(_v interface{}) bool { - rt := reflect.TypeOf(_v) - switch rt.Kind() { - case reflect.Slice: - return true - } - return false -} - -func (g *GetOrderRequest) GetSlugsMap() (map[string]string, error) { - slugs := map[string]string{} - params, err := g.GetSlugParameters() - if err != nil { - return slugs, nil - } - - for _k, _v := range params { - slugs[_k] = fmt.Sprintf("%v", _v) - } - - return slugs, nil -} - -func (g *GetOrderRequest) Do(ctx context.Context) (*Order, error) { - - // empty params for GET operation - var params interface{} - query, err := g.GetParametersQuery() - if err != nil { - return nil, err - } - - apiURL := "v2/order" - - req, err := g.client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params) - if err != nil { - return nil, err - } - - response, err := g.client.SendRequest(req) - if err != nil { - return nil, err - } - - var apiResponse Order - if err := response.DecodeJSON(&apiResponse); err != nil { - return nil, err - } - return &apiResponse, nil -} diff --git a/pkg/exchange/max/maxapi/get_orders_request_requestgen.go b/pkg/exchange/max/maxapi/get_orders_request_requestgen.go deleted file mode 100644 index de914deb9..000000000 --- a/pkg/exchange/max/maxapi/get_orders_request_requestgen.go +++ /dev/null @@ -1,240 +0,0 @@ -// Code generated by "requestgen -method GET -url v2/orders -type GetOrdersRequest -responseType []Order"; DO NOT EDIT. - -package max - -import ( - "context" - "encoding/json" - "fmt" - "net/url" - "reflect" - "regexp" -) - -func (g *GetOrdersRequest) Market(market string) *GetOrdersRequest { - g.market = market - return g -} - -func (g *GetOrdersRequest) Side(side string) *GetOrdersRequest { - g.side = &side - return g -} - -func (g *GetOrdersRequest) GroupID(groupID uint32) *GetOrdersRequest { - g.groupID = &groupID - return g -} - -func (g *GetOrdersRequest) Offset(offset int) *GetOrdersRequest { - g.offset = &offset - return g -} - -func (g *GetOrdersRequest) Limit(limit int) *GetOrdersRequest { - g.limit = &limit - return g -} - -func (g *GetOrdersRequest) Page(page int) *GetOrdersRequest { - g.page = &page - return g -} - -func (g *GetOrdersRequest) OrderBy(orderBy string) *GetOrdersRequest { - g.orderBy = &orderBy - return g -} - -func (g *GetOrdersRequest) State(state []OrderState) *GetOrdersRequest { - g.state = state - return g -} - -// GetQueryParameters builds and checks the query parameters and returns url.Values -func (g *GetOrdersRequest) GetQueryParameters() (url.Values, error) { - var params = map[string]interface{}{} - - query := url.Values{} - for _k, _v := range params { - query.Add(_k, fmt.Sprintf("%v", _v)) - } - - return query, nil -} - -// GetParameters builds and checks the parameters and return the result in a map object -func (g *GetOrdersRequest) GetParameters() (map[string]interface{}, error) { - var params = map[string]interface{}{} - // check market field -> json key market - market := g.market - - // assign parameter of market - params["market"] = market - // check side field -> json key side - if g.side != nil { - side := *g.side - - // assign parameter of side - params["side"] = side - } else { - } - // check groupID field -> json key groupID - if g.groupID != nil { - groupID := *g.groupID - - // assign parameter of groupID - params["groupID"] = groupID - } else { - } - // check offset field -> json key offset - if g.offset != nil { - offset := *g.offset - - // assign parameter of offset - params["offset"] = offset - } else { - } - // check limit field -> json key limit - if g.limit != nil { - limit := *g.limit - - // assign parameter of limit - params["limit"] = limit - } else { - } - // check page field -> json key page - if g.page != nil { - page := *g.page - - // assign parameter of page - params["page"] = page - } else { - } - // check orderBy field -> json key order_by - if g.orderBy != nil { - orderBy := *g.orderBy - - // assign parameter of orderBy - params["order_by"] = orderBy - } else { - orderBy := "desc" - - // assign parameter of orderBy - params["order_by"] = orderBy - } - // check state field -> json key state - state := g.state - - // assign parameter of state - params["state"] = state - - return params, nil -} - -// GetParametersQuery converts the parameters from GetParameters into the url.Values format -func (g *GetOrdersRequest) GetParametersQuery() (url.Values, error) { - query := url.Values{} - - params, err := g.GetParameters() - if err != nil { - return query, err - } - - for _k, _v := range params { - if g.isVarSlice(_v) { - g.iterateSlice(_v, func(it interface{}) { - query.Add(_k+"[]", fmt.Sprintf("%v", it)) - }) - } else { - query.Add(_k, fmt.Sprintf("%v", _v)) - } - } - - return query, nil -} - -// GetParametersJSON converts the parameters from GetParameters into the JSON format -func (g *GetOrdersRequest) GetParametersJSON() ([]byte, error) { - params, err := g.GetParameters() - if err != nil { - return nil, err - } - - return json.Marshal(params) -} - -// GetSlugParameters builds and checks the slug parameters and return the result in a map object -func (g *GetOrdersRequest) GetSlugParameters() (map[string]interface{}, error) { - var params = map[string]interface{}{} - - return params, nil -} - -func (g *GetOrdersRequest) applySlugsToUrl(url string, slugs map[string]string) string { - for _k, _v := range slugs { - needleRE := regexp.MustCompile(":" + _k + "\\b") - url = needleRE.ReplaceAllString(url, _v) - } - - return url -} - -func (g *GetOrdersRequest) iterateSlice(slice interface{}, _f func(it interface{})) { - sliceValue := reflect.ValueOf(slice) - for _i := 0; _i < sliceValue.Len(); _i++ { - it := sliceValue.Index(_i).Interface() - _f(it) - } -} - -func (g *GetOrdersRequest) isVarSlice(_v interface{}) bool { - rt := reflect.TypeOf(_v) - switch rt.Kind() { - case reflect.Slice: - return true - } - return false -} - -func (g *GetOrdersRequest) GetSlugsMap() (map[string]string, error) { - slugs := map[string]string{} - params, err := g.GetSlugParameters() - if err != nil { - return slugs, nil - } - - for _k, _v := range params { - slugs[_k] = fmt.Sprintf("%v", _v) - } - - return slugs, nil -} - -func (g *GetOrdersRequest) Do(ctx context.Context) ([]Order, error) { - - // empty params for GET operation - var params interface{} - query, err := g.GetParametersQuery() - if err != nil { - return nil, err - } - - apiURL := "v2/orders" - - req, err := g.client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params) - if err != nil { - return nil, err - } - - response, err := g.client.SendRequest(req) - if err != nil { - return nil, err - } - - var apiResponse []Order - if err := response.DecodeJSON(&apiResponse); err != nil { - return nil, err - } - return apiResponse, nil -} diff --git a/pkg/exchange/max/maxapi/order.go b/pkg/exchange/max/maxapi/order.go index 41e47bb24..f6df3dea2 100644 --- a/pkg/exchange/max/maxapi/order.go +++ b/pkg/exchange/max/maxapi/order.go @@ -7,7 +7,6 @@ import ( "context" "net/url" - "github.com/c9s/requestgen" "github.com/pkg/errors" "github.com/c9s/bbgo/pkg/fixedpoint" @@ -115,26 +114,6 @@ type Order struct { CreatedAt types.MillisecondTimestamp `json:"created_at"` } -//go:generate GetRequest -url "v2/orders" -type GetOrdersRequest -responseType []Order -type GetOrdersRequest struct { - client requestgen.AuthenticatedAPIClient - - market string `param:"market"` - side *string `param:"side"` - groupID *uint32 `param:"groupID"` - offset *int `param:"offset"` - limit *int `param:"limit"` - page *int `param:"page"` - orderBy *string `param:"order_by" default:"desc"` - state []OrderState `param:"state"` -} - -func (s *OrderService) NewGetOrdersRequest() *GetOrdersRequest { - return &GetOrdersRequest{ - client: s.client, - } -} - // All returns all orders for the authenticated account. func (s *OrderService) All(market string, limit, page int, states ...OrderState) ([]Order, error) { payload := map[string]interface{}{ @@ -174,43 +153,6 @@ func (s *OrderService) CreateMulti(market string, orders []SubmitOrder) (*MultiO return req.Do(context.Background()) } -//go:generate PostRequest -url "v2/orders/clear" -type OrderCancelAllRequest -responseType []Order -type OrderCancelAllRequest struct { - client requestgen.AuthenticatedAPIClient - - side *string `param:"side"` - market *string `param:"market"` - groupID *uint32 `param:"groupID"` -} - -func (s *OrderService) NewOrderCancelAllRequest() *OrderCancelAllRequest { - return &OrderCancelAllRequest{client: s.client} -} - -//go:generate PostRequest -url "v2/order/delete" -type OrderCancelRequest -responseType .Order -type OrderCancelRequest struct { - client requestgen.AuthenticatedAPIClient - - id *uint64 `param:"id,omitempty"` - clientOrderID *string `param:"client_oid,omitempty"` -} - -func (s *OrderService) NewOrderCancelRequest() *OrderCancelRequest { - return &OrderCancelRequest{client: s.client} -} - -//go:generate GetRequest -url "v2/order" -type GetOrderRequest -responseType .Order -type GetOrderRequest struct { - client requestgen.AuthenticatedAPIClient - - id *uint64 `param:"id,omitempty"` - clientOrderID *string `param:"client_oid,omitempty"` -} - -func (s *OrderService) NewGetOrderRequest() *GetOrderRequest { - return &GetOrderRequest{client: s.client} -} - type MultiOrderRequestParams struct { *PrivateRequestParams @@ -292,21 +234,3 @@ func (s *OrderService) NewCreateMultiOrderRequest() *CreateMultiOrderRequest { return &CreateMultiOrderRequest{client: s.client} } -//go:generate PostRequest -url "v2/orders" -type CreateOrderRequest -responseType .Order -type CreateOrderRequest struct { - client requestgen.AuthenticatedAPIClient - - market string `param:"market,required"` - side string `param:"side,required"` - volume string `param:"volume,required"` - orderType string `param:"ord_type"` - - price *string `param:"price"` - stopPrice *string `param:"stop_price"` - clientOrderID *string `param:"client_oid"` - groupID *string `param:"group_id"` -} - -func (s *OrderService) NewCreateOrderRequest() *CreateOrderRequest { - return &CreateOrderRequest{client: s.client} -} diff --git a/pkg/exchange/max/maxapi/order_cancel_all_request_requestgen.go b/pkg/exchange/max/maxapi/order_cancel_all_request_requestgen.go deleted file mode 100644 index ec160f80c..000000000 --- a/pkg/exchange/max/maxapi/order_cancel_all_request_requestgen.go +++ /dev/null @@ -1,176 +0,0 @@ -// Code generated by "requestgen -method POST -url v2/orders/clear -type OrderCancelAllRequest -responseType []Order"; DO NOT EDIT. - -package max - -import ( - "context" - "encoding/json" - "fmt" - "net/url" - "reflect" - "regexp" -) - -func (o *OrderCancelAllRequest) Side(side string) *OrderCancelAllRequest { - o.side = &side - return o -} - -func (o *OrderCancelAllRequest) Market(market string) *OrderCancelAllRequest { - o.market = &market - return o -} - -func (o *OrderCancelAllRequest) GroupID(groupID uint32) *OrderCancelAllRequest { - o.groupID = &groupID - return o -} - -// GetQueryParameters builds and checks the query parameters and returns url.Values -func (o *OrderCancelAllRequest) GetQueryParameters() (url.Values, error) { - var params = map[string]interface{}{} - - query := url.Values{} - for _k, _v := range params { - query.Add(_k, fmt.Sprintf("%v", _v)) - } - - return query, nil -} - -// GetParameters builds and checks the parameters and return the result in a map object -func (o *OrderCancelAllRequest) GetParameters() (map[string]interface{}, error) { - var params = map[string]interface{}{} - // check side field -> json key side - if o.side != nil { - side := *o.side - - // assign parameter of side - params["side"] = side - } else { - } - // check market field -> json key market - if o.market != nil { - market := *o.market - - // assign parameter of market - params["market"] = market - } else { - } - // check groupID field -> json key groupID - if o.groupID != nil { - groupID := *o.groupID - - // assign parameter of groupID - params["groupID"] = groupID - } else { - } - - return params, nil -} - -// GetParametersQuery converts the parameters from GetParameters into the url.Values format -func (o *OrderCancelAllRequest) GetParametersQuery() (url.Values, error) { - query := url.Values{} - - params, err := o.GetParameters() - if err != nil { - return query, err - } - - for _k, _v := range params { - if o.isVarSlice(_v) { - o.iterateSlice(_v, func(it interface{}) { - query.Add(_k+"[]", fmt.Sprintf("%v", it)) - }) - } else { - query.Add(_k, fmt.Sprintf("%v", _v)) - } - } - - return query, nil -} - -// GetParametersJSON converts the parameters from GetParameters into the JSON format -func (o *OrderCancelAllRequest) GetParametersJSON() ([]byte, error) { - params, err := o.GetParameters() - if err != nil { - return nil, err - } - - return json.Marshal(params) -} - -// GetSlugParameters builds and checks the slug parameters and return the result in a map object -func (o *OrderCancelAllRequest) GetSlugParameters() (map[string]interface{}, error) { - var params = map[string]interface{}{} - - return params, nil -} - -func (o *OrderCancelAllRequest) applySlugsToUrl(url string, slugs map[string]string) string { - for _k, _v := range slugs { - needleRE := regexp.MustCompile(":" + _k + "\\b") - url = needleRE.ReplaceAllString(url, _v) - } - - return url -} - -func (o *OrderCancelAllRequest) iterateSlice(slice interface{}, _f func(it interface{})) { - sliceValue := reflect.ValueOf(slice) - for _i := 0; _i < sliceValue.Len(); _i++ { - it := sliceValue.Index(_i).Interface() - _f(it) - } -} - -func (o *OrderCancelAllRequest) isVarSlice(_v interface{}) bool { - rt := reflect.TypeOf(_v) - switch rt.Kind() { - case reflect.Slice: - return true - } - return false -} - -func (o *OrderCancelAllRequest) GetSlugsMap() (map[string]string, error) { - slugs := map[string]string{} - params, err := o.GetSlugParameters() - if err != nil { - return slugs, nil - } - - for _k, _v := range params { - slugs[_k] = fmt.Sprintf("%v", _v) - } - - return slugs, nil -} - -func (o *OrderCancelAllRequest) Do(ctx context.Context) ([]Order, error) { - - params, err := o.GetParameters() - if err != nil { - return nil, err - } - query := url.Values{} - - apiURL := "v2/orders/clear" - - req, err := o.client.NewAuthenticatedRequest(ctx, "POST", apiURL, query, params) - if err != nil { - return nil, err - } - - response, err := o.client.SendRequest(req) - if err != nil { - return nil, err - } - - var apiResponse []Order - if err := response.DecodeJSON(&apiResponse); err != nil { - return nil, err - } - return apiResponse, nil -} diff --git a/pkg/exchange/max/maxapi/order_cancel_request_requestgen.go b/pkg/exchange/max/maxapi/order_cancel_request_requestgen.go deleted file mode 100644 index 552bad901..000000000 --- a/pkg/exchange/max/maxapi/order_cancel_request_requestgen.go +++ /dev/null @@ -1,163 +0,0 @@ -// Code generated by "requestgen -method POST -url v2/order/delete -type OrderCancelRequest -responseType .Order"; DO NOT EDIT. - -package max - -import ( - "context" - "encoding/json" - "fmt" - "net/url" - "reflect" - "regexp" -) - -func (o *OrderCancelRequest) Id(id uint64) *OrderCancelRequest { - o.id = &id - return o -} - -func (o *OrderCancelRequest) ClientOrderID(clientOrderID string) *OrderCancelRequest { - o.clientOrderID = &clientOrderID - return o -} - -// GetQueryParameters builds and checks the query parameters and returns url.Values -func (o *OrderCancelRequest) GetQueryParameters() (url.Values, error) { - var params = map[string]interface{}{} - - query := url.Values{} - for _k, _v := range params { - query.Add(_k, fmt.Sprintf("%v", _v)) - } - - return query, nil -} - -// GetParameters builds and checks the parameters and return the result in a map object -func (o *OrderCancelRequest) GetParameters() (map[string]interface{}, error) { - var params = map[string]interface{}{} - // check id field -> json key id - if o.id != nil { - id := *o.id - - // assign parameter of id - params["id"] = id - } else { - } - // check clientOrderID field -> json key client_oid - if o.clientOrderID != nil { - clientOrderID := *o.clientOrderID - - // assign parameter of clientOrderID - params["client_oid"] = clientOrderID - } else { - } - - return params, nil -} - -// GetParametersQuery converts the parameters from GetParameters into the url.Values format -func (o *OrderCancelRequest) GetParametersQuery() (url.Values, error) { - query := url.Values{} - - params, err := o.GetParameters() - if err != nil { - return query, err - } - - for _k, _v := range params { - if o.isVarSlice(_v) { - o.iterateSlice(_v, func(it interface{}) { - query.Add(_k+"[]", fmt.Sprintf("%v", it)) - }) - } else { - query.Add(_k, fmt.Sprintf("%v", _v)) - } - } - - return query, nil -} - -// GetParametersJSON converts the parameters from GetParameters into the JSON format -func (o *OrderCancelRequest) GetParametersJSON() ([]byte, error) { - params, err := o.GetParameters() - if err != nil { - return nil, err - } - - return json.Marshal(params) -} - -// GetSlugParameters builds and checks the slug parameters and return the result in a map object -func (o *OrderCancelRequest) GetSlugParameters() (map[string]interface{}, error) { - var params = map[string]interface{}{} - - return params, nil -} - -func (o *OrderCancelRequest) applySlugsToUrl(url string, slugs map[string]string) string { - for _k, _v := range slugs { - needleRE := regexp.MustCompile(":" + _k + "\\b") - url = needleRE.ReplaceAllString(url, _v) - } - - return url -} - -func (o *OrderCancelRequest) iterateSlice(slice interface{}, _f func(it interface{})) { - sliceValue := reflect.ValueOf(slice) - for _i := 0; _i < sliceValue.Len(); _i++ { - it := sliceValue.Index(_i).Interface() - _f(it) - } -} - -func (o *OrderCancelRequest) isVarSlice(_v interface{}) bool { - rt := reflect.TypeOf(_v) - switch rt.Kind() { - case reflect.Slice: - return true - } - return false -} - -func (o *OrderCancelRequest) GetSlugsMap() (map[string]string, error) { - slugs := map[string]string{} - params, err := o.GetSlugParameters() - if err != nil { - return slugs, nil - } - - for _k, _v := range params { - slugs[_k] = fmt.Sprintf("%v", _v) - } - - return slugs, nil -} - -func (o *OrderCancelRequest) Do(ctx context.Context) (*Order, error) { - - params, err := o.GetParameters() - if err != nil { - return nil, err - } - query := url.Values{} - - apiURL := "v2/order/delete" - - req, err := o.client.NewAuthenticatedRequest(ctx, "POST", apiURL, query, params) - if err != nil { - return nil, err - } - - response, err := o.client.SendRequest(req) - if err != nil { - return nil, err - } - - var apiResponse Order - if err := response.DecodeJSON(&apiResponse); err != nil { - return nil, err - } - return &apiResponse, nil -} diff --git a/pkg/exchange/max/maxapi/order_test.go b/pkg/exchange/max/maxapi/order_test.go index 49d6c6e4c..778912916 100644 --- a/pkg/exchange/max/maxapi/order_test.go +++ b/pkg/exchange/max/maxapi/order_test.go @@ -1,12 +1,9 @@ package max import ( - "context" "os" "regexp" "testing" - - "github.com/stretchr/testify/assert" ) func maskSecret(s string) string { @@ -26,78 +23,4 @@ func integrationTestConfigured(t *testing.T, prefix string) (key, secret string, return key, secret, ok } -func TestOrderService_GetOrdersRequest(t *testing.T) { - key, secret, ok := integrationTestConfigured(t, "MAX") - if !ok { - t.SkipNow() - } - ctx := context.Background() - - client := NewRestClient(ProductionAPIURL) - client.Auth(key, secret) - - req3 := client.OrderService.NewGetOrdersRequest() - req3.State([]OrderState{OrderStateDone, OrderStateFinalizing}) - // req3.State([]OrderState{OrderStateDone}) - req3.Market("btcusdt") - orders, err := req3.Do(ctx) - if assert.NoError(t, err) { - t.Logf("orders: %+v", orders) - - assert.NotNil(t, orders) - if assert.NotEmptyf(t, orders, "got %d orders", len(orders)) { - for _, order := range orders { - assert.Contains(t, []OrderState{OrderStateDone, OrderStateFinalizing}, order.State) - } - } - } -} - -func TestOrderService_GetOrdersRequest_SingleState(t *testing.T) { - key, secret, ok := integrationTestConfigured(t, "MAX") - if !ok { - t.SkipNow() - } - - ctx := context.Background() - - client := NewRestClient(ProductionAPIURL) - client.Auth(key, secret) - - req3 := client.OrderService.NewGetOrdersRequest() - req3.State([]OrderState{OrderStateDone}) - req3.Market("btcusdt") - orders, err := req3.Do(ctx) - assert.NoError(t, err) - assert.NotNil(t, orders) -} - - -func TestOrderService(t *testing.T) { - key, secret, ok := integrationTestConfigured(t, "MAX") - if !ok { - t.SkipNow() - } - - ctx := context.Background() - - client := NewRestClient(ProductionAPIURL) - client.Auth(key, secret) - req := client.OrderService.NewCreateOrderRequest() - order, err := req.Market("btcusdt"). - Price("10000"). - Volume("0.001"). - OrderType("limit"). - Side("buy").Do(ctx) - - if assert.NoError(t, err) { - assert.NotNil(t, order) - req2 := client.OrderService.NewOrderCancelRequest() - req2.Id(order.ID) - cancelResp, err := req2.Do(ctx) - assert.NoError(t, err) - t.Logf("cancelResponse: %+v", cancelResp) - } - -} From 500dc64ed413db185539d019bca2fea2d2690e25 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 16 Jun 2022 16:05:21 +0800 Subject: [PATCH 2/2] maxapi: drop unused v2 order api --- pkg/exchange/max/maxapi/order.go | 92 -------------------------------- 1 file changed, 92 deletions(-) diff --git a/pkg/exchange/max/maxapi/order.go b/pkg/exchange/max/maxapi/order.go index f6df3dea2..1f83a46d8 100644 --- a/pkg/exchange/max/maxapi/order.go +++ b/pkg/exchange/max/maxapi/order.go @@ -7,8 +7,6 @@ import ( "context" "net/url" - "github.com/pkg/errors" - "github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/types" ) @@ -144,93 +142,3 @@ func (s *OrderService) All(market string, limit, page int, states ...OrderState) // Options carry the option fields for REST API type Options map[string]interface{} - -// Create multiple order in a single request -func (s *OrderService) CreateMulti(market string, orders []SubmitOrder) (*MultiOrderResponse, error) { - req := s.NewCreateMultiOrderRequest() - req.Market(market) - req.AddOrders(orders...) - return req.Do(context.Background()) -} - -type MultiOrderRequestParams struct { - *PrivateRequestParams - - Market string `json:"market"` - Orders []Order `json:"orders"` -} - -type MultiOrderResponse []struct { - Error string `json:"error,omitempty"` - Order Order `json:"order,omitempty"` -} - -type CreateMultiOrderRequest struct { - client *RestClient - - market *string - groupID *uint32 - orders []SubmitOrder -} - -func (r *CreateMultiOrderRequest) GroupID(groupID uint32) *CreateMultiOrderRequest { - r.groupID = &groupID - return r -} - -func (r *CreateMultiOrderRequest) Market(market string) *CreateMultiOrderRequest { - r.market = &market - return r -} - -func (r *CreateMultiOrderRequest) AddOrders(orders ...SubmitOrder) *CreateMultiOrderRequest { - r.orders = append(r.orders, orders...) - return r -} - -func (r *CreateMultiOrderRequest) Do(ctx context.Context) (multiOrderResponse *MultiOrderResponse, err error) { - var payload = map[string]interface{}{} - - if r.market != nil { - payload["market"] = r.market - } else { - return nil, errors.New("parameter market is required") - } - - if r.groupID != nil { - payload["group_id"] = r.groupID - } - - if len(r.orders) == 0 { - return nil, errors.New("parameter orders can not be empty") - } - - // clear group id - for i := range r.orders { - r.orders[i].GroupID = 0 - } - - payload["orders"] = r.orders - - req, err := r.client.newAuthenticatedRequest(context.Background(), "POST", "v2/orders/multi/onebyone", nil, payload, relUrlV2OrdersMultiOneByOne) - if err != nil { - return multiOrderResponse, errors.Wrapf(err, "order create error") - } - - response, err := r.client.SendRequest(req) - if err != nil { - return multiOrderResponse, err - } - - multiOrderResponse = &MultiOrderResponse{} - if errJson := response.DecodeJSON(multiOrderResponse); errJson != nil { - return multiOrderResponse, errJson - } - - return multiOrderResponse, err -} - -func (s *OrderService) NewCreateMultiOrderRequest() *CreateMultiOrderRequest { - return &CreateMultiOrderRequest{client: s.client} -} -