diff --git a/pkg/exchange/kucoin/exchange.go b/pkg/exchange/kucoin/exchange.go index 133136904..4283d5f23 100644 --- a/pkg/exchange/kucoin/exchange.go +++ b/pkg/exchange/kucoin/exchange.go @@ -223,7 +223,7 @@ func (e *Exchange) SubmitOrders(ctx context.Context, orders ...types.SubmitOrder // set price field for limit orders switch order.Type { - case types.OrderTypeStopLimit, types.OrderTypeLimit: + case types.OrderTypeStopLimit, types.OrderTypeLimit, types.OrderTypeLimitMaker: if order.Market.Symbol != "" { req.Price(order.Market.FormatPrice(order.Price)) } else { @@ -232,6 +232,10 @@ func (e *Exchange) SubmitOrders(ctx context.Context, orders ...types.SubmitOrder } } + if order.Type == types.OrderTypeLimitMaker { + req.PostOnly(true) + } + switch order.TimeInForce { case "FOK": req.TimeInForce(kucoinapi.TimeInForceFOK) @@ -242,6 +246,17 @@ func (e *Exchange) SubmitOrders(ctx context.Context, orders ...types.SubmitOrder req.TimeInForce(kucoinapi.TimeInForceGTC) } + switch order.Type { + case types.OrderTypeStopLimit: + req.OrderType(kucoinapi.OrderTypeStopLimit) + + case types.OrderTypeLimit, types.OrderTypeLimitMaker: + req.OrderType(kucoinapi.OrderTypeLimit) + + case types.OrderTypeMarket: + req.OrderType(kucoinapi.OrderTypeMarket) + } + orderResponse, err := req.Do(ctx) if err != nil { return createdOrders, err diff --git a/pkg/exchange/kucoin/kucoinapi/cancel_all_order_request_requestgen.go b/pkg/exchange/kucoin/kucoinapi/cancel_all_order_request_requestgen.go index 86148258c..d6ad72225 100644 --- a/pkg/exchange/kucoin/kucoinapi/cancel_all_order_request_requestgen.go +++ b/pkg/exchange/kucoin/kucoinapi/cancel_all_order_request_requestgen.go @@ -41,7 +41,7 @@ func (r *CancelAllOrderRequest) GetParameters() (map[string]interface{}, error) // assign parameter of symbol params["symbol"] = symbol - + } else { } // check tradeType field -> json key tradeType if r.tradeType != nil { @@ -49,7 +49,7 @@ func (r *CancelAllOrderRequest) GetParameters() (map[string]interface{}, error) // assign parameter of tradeType params["tradeType"] = tradeType - + } else { } return params, nil diff --git a/pkg/exchange/kucoin/kucoinapi/cancel_order_request_requestgen.go b/pkg/exchange/kucoin/kucoinapi/cancel_order_request_requestgen.go index e5a7250f5..e53a6cbe9 100644 --- a/pkg/exchange/kucoin/kucoinapi/cancel_order_request_requestgen.go +++ b/pkg/exchange/kucoin/kucoinapi/cancel_order_request_requestgen.go @@ -40,7 +40,7 @@ func (r *CancelOrderRequest) GetParameters() (map[string]interface{}, error) { // assign parameter of orderID params["orderID"] = orderID - + } else { } // check clientOrderID field -> json key clientOrderID if r.clientOrderID != nil { @@ -48,7 +48,7 @@ func (r *CancelOrderRequest) GetParameters() (map[string]interface{}, error) { // assign parameter of clientOrderID params["clientOrderID"] = clientOrderID - + } else { } return params, nil diff --git a/pkg/exchange/kucoin/kucoinapi/get_fills_request_requestgen.go b/pkg/exchange/kucoin/kucoinapi/get_fills_request_requestgen.go index 20f3e305e..27ac7969a 100644 --- a/pkg/exchange/kucoin/kucoinapi/get_fills_request_requestgen.go +++ b/pkg/exchange/kucoin/kucoinapi/get_fills_request_requestgen.go @@ -68,7 +68,7 @@ func (r *GetFillsRequest) GetParameters() (map[string]interface{}, error) { // assign parameter of orderID params["orderId"] = orderID - + } else { } // check tradeType field -> json key tradeType if r.tradeType != nil { @@ -76,7 +76,11 @@ func (r *GetFillsRequest) GetParameters() (map[string]interface{}, error) { // assign parameter of tradeType params["tradeType"] = tradeType + } else { + tradeType := "TRADE" + // assign parameter of tradeType + params["tradeType"] = tradeType } // check symbol field -> json key symbol if r.symbol != nil { @@ -84,7 +88,7 @@ func (r *GetFillsRequest) GetParameters() (map[string]interface{}, error) { // assign parameter of symbol params["symbol"] = symbol - + } else { } // check side field -> json key side if r.side != nil { @@ -96,14 +100,14 @@ func (r *GetFillsRequest) GetParameters() (map[string]interface{}, error) { params["side"] = side default: - return params, fmt.Errorf("side value %v is invalid", side) + return nil, fmt.Errorf("side value %v is invalid", side) } // END TEMPLATE check-valid-values // assign parameter of side params["side"] = side - + } else { } // check orderType field -> json key type if r.orderType != nil { @@ -115,14 +119,14 @@ func (r *GetFillsRequest) GetParameters() (map[string]interface{}, error) { params["type"] = orderType default: - return params, fmt.Errorf("type value %v is invalid", orderType) + return nil, fmt.Errorf("type value %v is invalid", orderType) } // END TEMPLATE check-valid-values // assign parameter of orderType params["type"] = orderType - + } else { } // check startAt field -> json key startAt if r.startAt != nil { @@ -131,7 +135,7 @@ func (r *GetFillsRequest) GetParameters() (map[string]interface{}, error) { // assign parameter of startAt // convert time.Time to milliseconds time stamp params["startAt"] = strconv.FormatInt(startAt.UnixNano()/int64(time.Millisecond), 10) - + } else { } // check endAt field -> json key endAt if r.endAt != nil { @@ -140,7 +144,7 @@ func (r *GetFillsRequest) GetParameters() (map[string]interface{}, error) { // assign parameter of endAt // convert time.Time to milliseconds time stamp params["endAt"] = strconv.FormatInt(endAt.UnixNano()/int64(time.Millisecond), 10) - + } else { } return params, nil diff --git a/pkg/exchange/kucoin/kucoinapi/list_history_orders_request_requestgen.go b/pkg/exchange/kucoin/kucoinapi/list_history_orders_request_requestgen.go index 43ed886d5..2acd54a42 100644 --- a/pkg/exchange/kucoin/kucoinapi/list_history_orders_request_requestgen.go +++ b/pkg/exchange/kucoin/kucoinapi/list_history_orders_request_requestgen.go @@ -48,7 +48,7 @@ func (l *ListHistoryOrdersRequest) GetParameters() (map[string]interface{}, erro // assign parameter of symbol params["symbol"] = symbol - + } else { } // check startAt field -> json key startAt if l.startAt != nil { @@ -57,7 +57,7 @@ func (l *ListHistoryOrdersRequest) GetParameters() (map[string]interface{}, erro // assign parameter of startAt // convert time.Time to milliseconds time stamp params["startAt"] = strconv.FormatInt(startAt.UnixNano()/int64(time.Millisecond), 10) - + } else { } // check endAt field -> json key endAt if l.endAt != nil { @@ -66,7 +66,7 @@ func (l *ListHistoryOrdersRequest) GetParameters() (map[string]interface{}, erro // assign parameter of endAt // convert time.Time to milliseconds time stamp params["endAt"] = strconv.FormatInt(endAt.UnixNano()/int64(time.Millisecond), 10) - + } else { } return params, nil diff --git a/pkg/exchange/kucoin/kucoinapi/list_orders_request_requestgen.go b/pkg/exchange/kucoin/kucoinapi/list_orders_request_requestgen.go index 548820e8e..5ef4f288a 100644 --- a/pkg/exchange/kucoin/kucoinapi/list_orders_request_requestgen.go +++ b/pkg/exchange/kucoin/kucoinapi/list_orders_request_requestgen.go @@ -72,14 +72,14 @@ func (r *ListOrdersRequest) GetParameters() (map[string]interface{}, error) { params["status"] = status default: - return params, fmt.Errorf("status value %v is invalid", status) + return nil, fmt.Errorf("status value %v is invalid", status) } // END TEMPLATE check-valid-values // assign parameter of status params["status"] = status - + } else { } // check symbol field -> json key symbol if r.symbol != nil { @@ -87,7 +87,7 @@ func (r *ListOrdersRequest) GetParameters() (map[string]interface{}, error) { // assign parameter of symbol params["symbol"] = symbol - + } else { } // check side field -> json key side if r.side != nil { @@ -99,14 +99,14 @@ func (r *ListOrdersRequest) GetParameters() (map[string]interface{}, error) { params["side"] = side default: - return params, fmt.Errorf("side value %v is invalid", side) + return nil, fmt.Errorf("side value %v is invalid", side) } // END TEMPLATE check-valid-values // assign parameter of side params["side"] = side - + } else { } // check orderType field -> json key type if r.orderType != nil { @@ -114,7 +114,7 @@ func (r *ListOrdersRequest) GetParameters() (map[string]interface{}, error) { // assign parameter of orderType params["type"] = orderType - + } else { } // check tradeType field -> json key tradeType if r.tradeType != nil { @@ -122,7 +122,11 @@ func (r *ListOrdersRequest) GetParameters() (map[string]interface{}, error) { // assign parameter of tradeType params["tradeType"] = tradeType + } else { + tradeType := "TRADE" + // assign parameter of tradeType + params["tradeType"] = tradeType } // check startAt field -> json key startAt if r.startAt != nil { @@ -131,7 +135,7 @@ func (r *ListOrdersRequest) GetParameters() (map[string]interface{}, error) { // assign parameter of startAt // convert time.Time to milliseconds time stamp params["startAt"] = strconv.FormatInt(startAt.UnixNano()/int64(time.Millisecond), 10) - + } else { } // check endAt field -> json key endAt if r.endAt != nil { @@ -140,7 +144,7 @@ func (r *ListOrdersRequest) GetParameters() (map[string]interface{}, error) { // assign parameter of endAt // convert time.Time to milliseconds time stamp params["endAt"] = strconv.FormatInt(endAt.UnixNano()/int64(time.Millisecond), 10) - + } else { } return params, nil diff --git a/pkg/exchange/kucoin/kucoinapi/place_order_request_requestgen.go b/pkg/exchange/kucoin/kucoinapi/place_order_request_requestgen.go index c0832eb7e..50b7557bc 100644 --- a/pkg/exchange/kucoin/kucoinapi/place_order_request_requestgen.go +++ b/pkg/exchange/kucoin/kucoinapi/place_order_request_requestgen.go @@ -51,6 +51,11 @@ func (r *PlaceOrderRequest) TimeInForce(timeInForce TimeInForceType) *PlaceOrder return r } +func (r *PlaceOrderRequest) PostOnly(postOnly bool) *PlaceOrderRequest { + r.postOnly = &postOnly + return r +} + // GetQueryParameters builds and checks the query parameters and returns url.Values func (r *PlaceOrderRequest) GetQueryParameters() (url.Values, error) { var params = map[string]interface{}{} @@ -72,27 +77,24 @@ func (r *PlaceOrderRequest) GetParameters() (map[string]interface{}, error) { // TEMPLATE check-required if len(clientOrderID) == 0 { - return params, fmt.Errorf("clientOid is required, empty string given") + return nil, fmt.Errorf("clientOid is required, empty string given") } // END TEMPLATE check-required // assign parameter of clientOrderID params["clientOid"] = clientOrderID - } else { - // assign default of clientOrderID clientOrderID := uuid.New().String() // assign parameter of clientOrderID params["clientOid"] = clientOrderID - } // check symbol field -> json key symbol symbol := r.symbol // TEMPLATE check-required if len(symbol) == 0 { - return params, fmt.Errorf("symbol is required, empty string given") + return nil, fmt.Errorf("symbol is required, empty string given") } // END TEMPLATE check-required @@ -104,7 +106,7 @@ func (r *PlaceOrderRequest) GetParameters() (map[string]interface{}, error) { // assign parameter of tag params["tag"] = tag - + } else { } // check side field -> json key side side := r.side @@ -121,7 +123,7 @@ func (r *PlaceOrderRequest) GetParameters() (map[string]interface{}, error) { // TEMPLATE check-required if len(size) == 0 { - return params, fmt.Errorf("size is required, empty string given") + return nil, fmt.Errorf("size is required, empty string given") } // END TEMPLATE check-required @@ -133,7 +135,7 @@ func (r *PlaceOrderRequest) GetParameters() (map[string]interface{}, error) { // assign parameter of price params["price"] = price - + } else { } // check timeInForce field -> json key timeInForce if r.timeInForce != nil { @@ -141,13 +143,21 @@ func (r *PlaceOrderRequest) GetParameters() (map[string]interface{}, error) { // TEMPLATE check-required if len(timeInForce) == 0 { - return params, fmt.Errorf("timeInForce is required, empty string given") + return nil, fmt.Errorf("timeInForce is required, empty string given") } // END TEMPLATE check-required // assign parameter of timeInForce params["timeInForce"] = timeInForce + } else { + } + // check postOnly field -> json key postOnly + if r.postOnly != nil { + postOnly := *r.postOnly + // assign parameter of postOnly + params["postOnly"] = postOnly + } else { } return params, nil diff --git a/pkg/exchange/kucoin/kucoinapi/trade.go b/pkg/exchange/kucoin/kucoinapi/trade.go index efd6ffc11..785a3119a 100644 --- a/pkg/exchange/kucoin/kucoinapi/trade.go +++ b/pkg/exchange/kucoin/kucoinapi/trade.go @@ -206,6 +206,8 @@ type PlaceOrderRequest struct { price *string `param:"price"` timeInForce *TimeInForceType `param:"timeInForce,required"` + + postOnly *bool `param:"postOnly"` } type CancelOrderResponse struct {