mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
use requestgen to generate the accessor methods
This commit is contained in:
parent
1d6891b112
commit
22972953d0
132
pkg/exchange/kucoin/kucoinapi/place_order_request_accessors.go
Normal file
132
pkg/exchange/kucoin/kucoinapi/place_order_request_accessors.go
Normal file
|
@ -0,0 +1,132 @@
|
|||
// Code generated by "requestgen -type PlaceOrderRequest"; DO NOT EDIT.
|
||||
|
||||
package kucoinapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func (p *PlaceOrderRequest) ClientOrderID(clientOrderID string) *PlaceOrderRequest {
|
||||
p.clientOrderID = &clientOrderID
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *PlaceOrderRequest) Symbol(symbol string) *PlaceOrderRequest {
|
||||
p.symbol = symbol
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *PlaceOrderRequest) Tag(tag string) *PlaceOrderRequest {
|
||||
p.tag = &tag
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *PlaceOrderRequest) Side(side SideType) *PlaceOrderRequest {
|
||||
p.side = side
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *PlaceOrderRequest) OrdType(ordType OrderType) *PlaceOrderRequest {
|
||||
p.ordType = ordType
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *PlaceOrderRequest) Size(size string) *PlaceOrderRequest {
|
||||
p.size = size
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *PlaceOrderRequest) Price(price string) *PlaceOrderRequest {
|
||||
p.price = &price
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *PlaceOrderRequest) TimeInForce(timeInForce TimeInForceType) *PlaceOrderRequest {
|
||||
p.timeInForce = &timeInForce
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *PlaceOrderRequest) getParameters() (map[string]interface{}, error) {
|
||||
var params = map[string]interface{}{}
|
||||
|
||||
// check clientOrderID field -> json key clientOid
|
||||
if p.clientOrderID != nil {
|
||||
clientOrderID := *p.clientOrderID
|
||||
|
||||
if len(clientOrderID) == 0 {
|
||||
return params, fmt.Errorf("clientOid is required, empty string given")
|
||||
}
|
||||
|
||||
params["clientOid"] = clientOrderID
|
||||
}
|
||||
|
||||
// check symbol field -> json key symbol
|
||||
symbol := p.symbol
|
||||
|
||||
if len(symbol) == 0 {
|
||||
return params, fmt.Errorf("symbol is required, empty string given")
|
||||
}
|
||||
|
||||
params["symbol"] = symbol
|
||||
|
||||
// check tag field -> json key tag
|
||||
if p.tag != nil {
|
||||
tag := *p.tag
|
||||
|
||||
params["tag"] = tag
|
||||
}
|
||||
|
||||
// check side field -> json key side
|
||||
side := p.side
|
||||
|
||||
params["side"] = side
|
||||
|
||||
// check ordType field -> json key ordType
|
||||
ordType := p.ordType
|
||||
|
||||
params["ordType"] = ordType
|
||||
|
||||
// check size field -> json key size
|
||||
size := p.size
|
||||
|
||||
if len(size) == 0 {
|
||||
return params, fmt.Errorf("size is required, empty string given")
|
||||
}
|
||||
|
||||
params["size"] = size
|
||||
|
||||
// check price field -> json key price
|
||||
if p.price != nil {
|
||||
price := *p.price
|
||||
|
||||
params["price"] = price
|
||||
}
|
||||
|
||||
// check timeInForce field -> json key timeInForce
|
||||
if p.timeInForce != nil {
|
||||
timeInForce := *p.timeInForce
|
||||
|
||||
if len(timeInForce) == 0 {
|
||||
return params, fmt.Errorf("timeInForce is required, empty string given")
|
||||
}
|
||||
|
||||
params["timeInForce"] = timeInForce
|
||||
}
|
||||
return params, nil
|
||||
}
|
||||
|
||||
func (p *PlaceOrderRequest) getQuery() (url.Values, error) {
|
||||
query := url.Values{}
|
||||
|
||||
params, err := p.getParameters()
|
||||
if err != nil {
|
||||
return query, err
|
||||
}
|
||||
|
||||
for k, v := range params {
|
||||
query.Add(k, fmt.Sprintf("%v", v))
|
||||
}
|
||||
|
||||
return query, nil
|
||||
}
|
|
@ -186,93 +186,29 @@ func (c *TradeService) NewListOrdersRequest() *ListOrdersRequest {
|
|||
return &ListOrdersRequest{client: c.client}
|
||||
}
|
||||
|
||||
//go:generate requestgen -type PlaceOrderRequest
|
||||
type PlaceOrderRequest struct {
|
||||
client *RestClient
|
||||
|
||||
// A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 32 characters.
|
||||
clientOrderID *string
|
||||
clientOrderID *string `param:"clientOid,required"`
|
||||
|
||||
symbol string
|
||||
symbol string `param:"symbol,required"`
|
||||
|
||||
// A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 8 characters.
|
||||
tag *string
|
||||
tag *string `param:"tag"`
|
||||
|
||||
// "buy" or "sell"
|
||||
side SideType
|
||||
side SideType `param:"side"`
|
||||
|
||||
ordType OrderType
|
||||
ordType OrderType `param:"ordType"`
|
||||
|
||||
// limit order parameters
|
||||
size string
|
||||
size string `param:"size,required"`
|
||||
|
||||
price *string
|
||||
price *string `param:"price"`
|
||||
|
||||
timeInForce *TimeInForceType
|
||||
}
|
||||
|
||||
func (r *PlaceOrderRequest) Symbol(symbol string) *PlaceOrderRequest {
|
||||
r.symbol = symbol
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *PlaceOrderRequest) ClientOrderID(clientOrderID string) *PlaceOrderRequest {
|
||||
r.clientOrderID = &clientOrderID
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *PlaceOrderRequest) Side(side SideType) *PlaceOrderRequest {
|
||||
r.side = side
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *PlaceOrderRequest) Size(size string) *PlaceOrderRequest {
|
||||
r.size = size
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *PlaceOrderRequest) Price(price string) *PlaceOrderRequest {
|
||||
r.price = &price
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *PlaceOrderRequest) TimeInForce(timeInForce TimeInForceType) *PlaceOrderRequest {
|
||||
r.timeInForce = &timeInForce
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *PlaceOrderRequest) OrderType(orderType OrderType) *PlaceOrderRequest {
|
||||
r.ordType = orderType
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *PlaceOrderRequest) getParameters() (map[string]interface{}, error) {
|
||||
payload := map[string]interface{}{}
|
||||
|
||||
payload["symbol"] = r.symbol
|
||||
|
||||
if r.clientOrderID != nil {
|
||||
payload["clientOid"] = r.clientOrderID
|
||||
} else {
|
||||
payload["clientOid"] = uuid.New().String()
|
||||
}
|
||||
|
||||
if len(r.side) == 0 {
|
||||
return nil, errors.New("order side is required")
|
||||
}
|
||||
|
||||
payload["side"] = r.side
|
||||
payload["type"] = r.ordType
|
||||
payload["size"] = r.size
|
||||
|
||||
if r.price != nil {
|
||||
payload["price"] = r.price
|
||||
}
|
||||
|
||||
if r.timeInForce != nil {
|
||||
payload["timeInForce"] = r.timeInForce
|
||||
}
|
||||
|
||||
return payload, nil
|
||||
timeInForce *TimeInForceType `param:"timeInForce,required"`
|
||||
}
|
||||
|
||||
func (r *PlaceOrderRequest) Do(ctx context.Context) (*OrderResponse, error) {
|
||||
|
@ -281,6 +217,10 @@ 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
|
||||
|
@ -441,6 +381,10 @@ func (r *BatchPlaceOrderRequest) Do(ctx context.Context) ([]OrderResponse, error
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if _, ok := params["clientOid"] ; !ok {
|
||||
params["clientOid"] = uuid.New().String()
|
||||
}
|
||||
|
||||
orderList = append(orderList, params)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user