Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ private static void raw(KucoinTradeServiceRaw tradeService) throws Exception {

OrderCreateApiRequest limitOrder =
OrderCreateApiRequest.builder()
.size(AMOUNT)
.price(PRICE)
.size(AMOUNT.toPlainString())
.price(PRICE.toPlainString())
.side("sell")
.symbol(SYMBOL)
.type("limit")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public static UserTrade adaptHistOrder(HistOrdersResponse histOrder) {
public static OrderCreateApiRequest adaptLimitOrder(LimitOrder limitOrder) {
return ((OrderCreateApiRequest.OrderCreateApiRequestBuilder) adaptOrder(limitOrder))
.type("limit")
.price(limitOrder.getLimitPrice())
.price(limitOrder.getLimitPrice().toPlainString())
.postOnly(limitOrder.hasFlag(POST_ONLY))
.hidden(limitOrder.hasFlag(HIDDEN))
.iceberg(limitOrder.hasFlag(ICEBERG))
Expand All @@ -302,9 +302,9 @@ public static OrderCreateApiRequest adaptLimitOrder(LimitOrder limitOrder) {
public static OrderCreateApiRequest adaptStopOrder(StopOrder stopOrder) {
return ((OrderCreateApiRequest.OrderCreateApiRequestBuilder) adaptOrder(stopOrder))
.type(stopOrder.getLimitPrice() == null ? "market" : "limit")
.price(stopOrder.getLimitPrice())
.price(stopOrder.getLimitPrice().toPlainString())
.stop(stopOrder.getType().equals(ASK) ? "loss" : "entry")
.stopPrice(stopOrder.getStopPrice())
.stopPrice(stopOrder.getStopPrice().toPlainString())
.build();
}

Expand All @@ -316,11 +316,11 @@ public static OrderCreateApiRequest adaptMarketOrder(MarketOrder marketOrder) {
// on buy order amount corresponds to counter currency
if (marketOrder.getType() == BID) {
builder.size(null);
builder.funds(marketOrder.getOriginalAmount());
builder.funds(marketOrder.getOriginalAmount().toPlainString());
}
// on sell order amount corresponds to base currency
else if (marketOrder.getType() == ASK) {
builder.size(marketOrder.getOriginalAmount());
builder.size(marketOrder.getOriginalAmount().toPlainString());
builder.funds(null);
}

Expand Down Expand Up @@ -353,7 +353,7 @@ private static Object adaptOrder(Order order) {
}
return request
.symbol(adaptCurrencyPair((CurrencyPair) order.getInstrument()))
.size(order.getOriginalAmount())
.size(order.getOriginalAmount().toPlainString())
.side(adaptSide(order.getType()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public String placeMarketOrder(MarketOrder marketOrder) throws IOException {

@Override
public String placeStopOrder(StopOrder stopOrder) throws IOException {
return kucoinCreateOrder(KucoinAdapters.adaptStopOrder(stopOrder)).getOrderId();
return kucoinCreateStopOrder(KucoinAdapters.adaptStopOrder(stopOrder)).getOrderId();
}

private OpenOrders convertOpenOrders(Collection<OrderResponse> orders, OpenOrdersParams params) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ public OrderCreateResponse kucoinCreateOrder(OrderCreateApiRequest opsRequest)
() -> orderApi.createOrder(apiKey, digest, nonceFactory, passphrase, opsRequest));
}

public OrderCreateResponse kucoinCreateStopOrder(OrderCreateApiRequest opsRequest)
throws IOException {
checkAuthenticated();
return classifyingExceptions(
() -> orderApi.createStopOrder(apiKey, digest, nonceFactory, passphrase, opsRequest));
}

public List<OrderResponse> getKucoinRecentOrders() throws IOException {
this.checkAuthenticated();
return classifyingExceptions(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,68 +1,74 @@
/** Copyright 2019 Mek Global Limited. */
package org.knowm.xchange.kucoin.dto.request;

import java.math.BigDecimal;
import lombok.Builder;
import lombok.Getter;

/**
* 订单创建对象
*
* @author 屈亮
* @since 2018-09-17
* Represents a request to create a new order (limit, market, or stop) on KuCoin.
*/
@Getter
@Builder
public class OrderCreateApiRequest {

/** a valid trading symbol code. e.g. ETH-BTC */
/** Unique order id created by users to identify their orders, e.g. UUID. */
private final String clientOid;

/** A valid trading symbol code, e.g. ETH-BTC. */
private final String symbol;

/** [optional] limit or market (default is limit) */
@Builder.Default private final String type = "limit";
/** The type of trading, e.g. TRADE (Spot Trade). Default is TRADE. */
@Builder.Default private final String tradeType = "TRADE";

/** buy or sell */
/** buy or sell. */
private final String side;

/** price per base currency */
private final BigDecimal price;
/** limit or market (default is limit). */
@Builder.Default private final String type = "limit";

/** Remark for the order, length cannot exceed 100 utf8 characters. */
private final String remark;

/** amount of base currency to buy or sell */
private final BigDecimal size;
/** Self-trade prevention strategy: CN, CO, CB or DC. */
private final String stp;

/** [optional] Desired amount of quote currency to use */
private final BigDecimal funds;
// Stop-related fields (optional)

/** [optional] self trade protect , CN, CO, CB or DC */
@Builder.Default private final String stp = "";
/** "entry" or "loss" (KuCoin’s stop types). */
private final String stop;

/** [optional] Either loss or entry. Requires stopPrice to be defined */
@Builder.Default private final String stop = "";
/** Trigger price for the stop order. Null for regular orders. */
private final String stopPrice;

/** [optional] Only if stop is defined. Sets trigger price for stop order */
private final BigDecimal stopPrice;
// Common fields

/** [optional] GTC, GTT, IOC, or FOK (default is GTC) */
/** [limit order] Price per base currency. */
private final String price;

/** [limit order] Amount of base currency to buy or sell. */
private final String size;

/** [limit order] Time in force strategy: GTC, GTT, IOC, or FOK (default is GTC). */
@Builder.Default private final String timeInForce = "GTC";

/** [optional] * cancel after n seconds */
private final long cancelAfter;
/** [limit order] Cancel after n seconds, requires timeInForce = GTT. */
private final Long cancelAfter;

/** [optional] ** Post only flag */
/** [limit order] Post only flag. */
private final boolean postOnly;

/** [optional] Orders not displayed in order book */
/** [limit order] Order will not be displayed in the order book. */
private final boolean hidden;

/** [optional] Only visible portion of the order is displayed in the order book */
/** [limit order] Only a portion of the order is displayed in the order book. */
private final boolean iceberg;

/** [optional] The maximum visible size of an iceberg order */
private final BigDecimal visibleSize;
/** [limit order] The maximum visible size of an iceberg order. */
private final String visibleSize;

/** Unique order id selected by you to identify your order e.g. UUID */
private final String clientOid;

/** [optional] remark for the order, length cannot exceed 100 utf8 characters */
private final String remark;
/**
* [market order] The amount of quote currency to spend.
* size and funds are mutually exclusive.
*/
private final String funds;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import si.mazi.rescu.SynchronizedValueFactory;

/** Based on code by chenshiwei on 2019/1/10. */
@Path("/api/v1/orders")
@Path("/api/v1")
@Produces(MediaType.APPLICATION_JSON)
public interface OrderAPI {

Expand All @@ -41,6 +41,7 @@ public interface OrderAPI {
* @return A response containing the order id.
*/
@POST
@Path("/hf/orders")
@Consumes(MediaType.APPLICATION_JSON)
KucoinResponse<OrderCreateResponse> createOrder(
@HeaderParam(APIConstants.API_HEADER_KEY) String apiKey,
Expand All @@ -50,6 +51,23 @@ KucoinResponse<OrderCreateResponse> createOrder(
OrderCreateApiRequest opsRequest)
throws IOException;

/**
* Place a new stop-order.
*
* @param opsRequest Stop-Order creation request.
* @return A response containing the order id.
*/
@POST
@Path("/stop-order")
@Consumes(MediaType.APPLICATION_JSON)
KucoinResponse<OrderCreateResponse> createStopOrder(
@HeaderParam(APIConstants.API_HEADER_KEY) String apiKey,
@HeaderParam(APIConstants.API_HEADER_SIGN) ParamsDigest signature,
@HeaderParam(APIConstants.API_HEADER_TIMESTAMP) SynchronizedValueFactory<Long> nonce,
@HeaderParam(APIConstants.API_HEADER_PASSPHRASE) String apiPassphrase,
OrderCreateApiRequest opsRequest)
throws IOException;

/**
* Cancel an order
*
Expand All @@ -59,7 +77,7 @@ KucoinResponse<OrderCreateResponse> createOrder(
* @return A response containing the id of the cancelled order.
*/
@DELETE
@Path("/{orderId}")
@Path("/orders/{orderId}")
KucoinResponse<OrderCancelResponse> cancelOrder(
@HeaderParam(APIConstants.API_HEADER_KEY) String apiKey,
@HeaderParam(APIConstants.API_HEADER_SIGN) ParamsDigest signature,
Expand All @@ -75,6 +93,7 @@ KucoinResponse<OrderCancelResponse> cancelOrder(
* @return A response containing the ids of all open orders.
*/
@DELETE
@Path("/orders")
KucoinResponse<OrderCancelResponse> cancelOrders(
@HeaderParam(APIConstants.API_HEADER_KEY) String apiKey,
@HeaderParam(APIConstants.API_HEADER_SIGN) ParamsDigest signature,
Expand All @@ -90,7 +109,7 @@ KucoinResponse<OrderCancelResponse> cancelOrders(
* @return The requested order.
*/
@GET
@Path("/{orderId}")
@Path("/orders/{orderId}")
KucoinResponse<OrderResponse> getOrder(
@HeaderParam(APIConstants.API_HEADER_KEY) String apiKey,
@HeaderParam(APIConstants.API_HEADER_SIGN) ParamsDigest signature,
Expand All @@ -116,6 +135,7 @@ KucoinResponse<OrderResponse> getOrder(
* @return A page of orders.
*/
@GET
@Path("/orders")
KucoinResponse<Pagination<OrderResponse>> queryOrders(
@HeaderParam(APIConstants.API_HEADER_KEY) String apiKey,
@HeaderParam(APIConstants.API_HEADER_SIGN) ParamsDigest signature,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class KucoinAdaptersTest {
void adapt_market_buy_order() {
OrderCreateApiRequest expected =
OrderCreateApiRequest.builder()
.funds(new BigDecimal("15"))
.funds(new BigDecimal("15").toPlainString())
.clientOid("abc")
.side("buy")
.symbol("BTC-USDT")
Expand All @@ -37,7 +37,7 @@ void adapt_market_buy_order() {
void adapt_market_sell_order() {
OrderCreateApiRequest expected =
OrderCreateApiRequest.builder()
.size(new BigDecimal("0.002"))
.size(new BigDecimal("0.002").toPlainString())
.clientOid("abc")
.side("sell")
.symbol("BTC-USDT")
Expand Down