apply requestgen for CancelOrderRequest and CancelAllOrderRequest

This commit is contained in:
c9s 2021-12-13 02:08:18 +08:00
parent c28833fba0
commit 34c2b342ba
4 changed files with 125 additions and 26 deletions

View File

@ -0,0 +1,54 @@
// Code generated by "requestgen -type CancelAllOrderRequest"; DO NOT EDIT.
package kucoinapi
import (
"fmt"
"net/url"
)
func (r *CancelAllOrderRequest) Symbol(symbol string) *CancelAllOrderRequest {
r.symbol = &symbol
return r
}
func (r *CancelAllOrderRequest) TradeType(tradeType string) *CancelAllOrderRequest {
r.tradeType = &tradeType
return r
}
func (r *CancelAllOrderRequest) getParameters() (map[string]interface{}, error) {
var params = map[string]interface{}{}
// check symbol field -> json key symbol
if r.symbol != nil {
symbol := *r.symbol
params["symbol"] = symbol
} else {
}
// check tradeType field -> json key tradeType
if r.tradeType != nil {
tradeType := *r.tradeType
params["tradeType"] = tradeType
} else {
}
return params, nil
}
func (r *CancelAllOrderRequest) getQuery() (url.Values, error) {
query := url.Values{}
params, err := r.getParameters()
if err != nil {
return query, err
}
for k, v := range params {
query.Add(k, fmt.Sprintf("%v", v))
}
return query, nil
}

View File

@ -0,0 +1,54 @@
// Code generated by "requestgen -type CancelOrderRequest"; DO NOT EDIT.
package kucoinapi
import (
"fmt"
"net/url"
)
func (c *CancelOrderRequest) OrderID(orderID string) *CancelOrderRequest {
c.orderID = &orderID
return c
}
func (c *CancelOrderRequest) ClientOrderID(clientOrderID string) *CancelOrderRequest {
c.clientOrderID = &clientOrderID
return c
}
func (c *CancelOrderRequest) getParameters() (map[string]interface{}, error) {
var params = map[string]interface{}{}
// check orderID field -> json key orderID
if c.orderID != nil {
orderID := *c.orderID
params["orderID"] = orderID
} else {
}
// check clientOrderID field -> json key clientOrderID
if c.clientOrderID != nil {
clientOrderID := *c.clientOrderID
params["clientOrderID"] = clientOrderID
} else {
}
return params, nil
}
func (c *CancelOrderRequest) getQuery() (url.Values, error) {
query := url.Values{}
params, err := c.getParameters()
if err != nil {
return query, err
}
for k, v := range params {
query.Add(k, fmt.Sprintf("%v", v))
}
return query, nil
}

View File

@ -4,6 +4,7 @@ package kucoinapi
import (
"fmt"
"github.com/google/uuid"
"net/url"
)
@ -60,6 +61,9 @@ func (r *PlaceOrderRequest) getParameters() (map[string]interface{}, error) {
params["clientOid"] = clientOrderID
} else {
clientOrderID := uuid.New().String()
params["clientOid"] = clientOrderID
}
// check symbol field -> json key symbol

View File

@ -143,7 +143,7 @@ type PlaceOrderRequest struct {
client *RestClient
// A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 32 characters.
clientOrderID *string `param:"clientOid,required"`
clientOrderID *string `param:"clientOid,required" defaultValuer:"uuid()"`
symbol string `param:"symbol,required"`
@ -169,10 +169,6 @@ func (r *PlaceOrderRequest) Do(ctx context.Context) (*OrderResponse, error) {
return nil, err
}
if _, ok := payload["clientOid"]; !ok {
payload["clientOid"] = uuid.New().String()
}
req, err := r.client.newAuthenticatedRequest("POST", "/api/v1/orders", nil, payload)
if err != nil {
return nil, err
@ -200,21 +196,12 @@ func (r *PlaceOrderRequest) Do(ctx context.Context) (*OrderResponse, error) {
return orderResponse.Data, nil
}
//go:generate requestgen -type CancelOrderRequest
type CancelOrderRequest struct {
client *RestClient
orderID *string
clientOrderID *string
}
func (r *CancelOrderRequest) OrderID(orderID string) *CancelOrderRequest {
r.orderID = &orderID
return r
}
func (r *CancelOrderRequest) ClientOrderID(clientOrderID string) *CancelOrderRequest {
r.clientOrderID = &clientOrderID
return r
orderID *string `param:"orderID"`
clientOrderID *string `param:"clientOrderID"`
}
type CancelOrderResponse struct {
@ -264,21 +251,21 @@ func (r *CancelOrderRequest) Do(ctx context.Context) (*CancelOrderResponse, erro
return apiResponse.Data, nil
}
//go:generate requestgen -type CancelAllOrderRequest
type CancelAllOrderRequest struct {
client *RestClient
symbol *string
// tradeType string
}
func (r *CancelAllOrderRequest) Symbol(symbol string) *CancelAllOrderRequest {
r.symbol = &symbol
return r
symbol *string `param:"symbol"`
tradeType *string `param:"tradeType"`
}
func (r *CancelAllOrderRequest) Do(ctx context.Context) (*CancelOrderResponse, error) {
req, err := r.client.newAuthenticatedRequest("DELETE", "/api/v1/orders", nil, nil)
params, err := r.getQuery()
if err != nil {
return nil, err
}
req, err := r.client.newAuthenticatedRequest("DELETE", "/api/v1/orders", params, nil)
if err != nil {
return nil, err
}