Skip to content

Commit

Permalink
Merge pull request #17 from Kucoin/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ISAAC-XXYYZZ authored Oct 18, 2024
2 parents 14e1232 + 8206cff commit d16eae6
Show file tree
Hide file tree
Showing 37 changed files with 625 additions and 58 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.kucoin.futures</groupId>
<artifactId>kucoin-futures-java-sdk</artifactId>
<version>1.2.8</version>
<version>1.2.9</version>

<name>kucoin-futures-java-sdk</name>
<description>kucoin-futures-java-sdk</description>
Expand Down Expand Up @@ -80,7 +80,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
<version>1.18.34</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ public interface KucoinFuturesPrivateWSClient extends KucoinFuturesPublicWSClien
*/
String onPositionAllChange(KucoinFuturesAPICallback<KucoinEvent<PositionChangeEvent>> callback);


/**
* Margin Mode Change Events
* @param callback
* @return
*/
String onMarginModeChange(KucoinFuturesAPICallback<KucoinEvent<MarginModeChangeEvent>> callback);


/**
* Cross Leverage Change Events
* @param callback
* @return
*/
String onCrossLeverageChange(KucoinFuturesAPICallback<KucoinEvent<CrossLeverageChangeEvent>> callback);

/**
* You will receive a message when the specified symbol order changes
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ private APIConstants() {}
public static final String API_POSITION_TOPIC_PREFIX = "/contract/position:";

public static final String API_POSITION_ALL_TOPIC_PREFIX = "/contract/positionAll";
public static final String API_CONTRACT_MARGIN_MODE_PREFIX = "/contract/marginMode";
public static final String API_CONTRACT_CROSS_LEVERAGE_PREFIX = "/contract/crossLeverage";
public static final String API_K_LINE_TOPIC_PREFIX = "/contractMarket/limitCandle:";
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ public String onPositionAllChange(KucoinFuturesAPICallback<KucoinEvent<PositionC
return subscribe(topic, true, true);
}

@Override
public String onMarginModeChange(KucoinFuturesAPICallback<KucoinEvent<MarginModeChangeEvent>> callback) {
if (callback != null) {
this.getListener().getCallbackMap().put(APIConstants.API_CONTRACT_MARGIN_MODE_PREFIX, callback);
this.getListener().getTypeReferenceMap().put(APIConstants.API_CONTRACT_MARGIN_MODE_PREFIX,
new TypeReference<KucoinEvent<MarginModeChangeEvent>>() {});
}
String topic = APIConstants.API_CONTRACT_MARGIN_MODE_PREFIX;
return subscribe(topic, true, true);
}

@Override
public String onCrossLeverageChange(KucoinFuturesAPICallback<KucoinEvent<CrossLeverageChangeEvent>> callback) {
if (callback != null) {
this.getListener().getCallbackMap().put(APIConstants.API_CONTRACT_CROSS_LEVERAGE_PREFIX, callback);
this.getListener().getTypeReferenceMap().put(APIConstants.API_CONTRACT_CROSS_LEVERAGE_PREFIX,
new TypeReference<KucoinEvent<CrossLeverageChangeEvent>>() {});
}
String topic = APIConstants.API_CONTRACT_CROSS_LEVERAGE_PREFIX;
return subscribe(topic, true, true);
}

@Override
public String onOrderChange(KucoinFuturesAPICallback<KucoinEvent<OrderChangeEvent>> callback, String symbol) {
if (callback != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public enum PrivateChannelEnum {
POSITION(APIConstants.API_POSITION_TOPIC_PREFIX),
POSITION_ALL(APIConstants.API_POSITION_ALL_TOPIC_PREFIX),

MARGIN_MODE_CHANGE(APIConstants.API_CONTRACT_MARGIN_MODE_PREFIX),
CROSS_LEVERAGE_CHANGE(APIConstants.API_CONTRACT_CROSS_LEVERAGE_PREFIX),

SYMBOL_ORDER_CHANGE(APIConstants.API_SYMBOL_ORDER_CHANGE_TOPIC_PREFIX),

ORDER_CHANGE(APIConstants.API_ORDER_CHANGE_TOPIC_PREFIX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.kucoin.futures.core.rest.request.OrderCreateApiRequest;
import com.kucoin.futures.core.rest.impl.retrofit.AuthRetrofitAPIImpl;
import com.kucoin.futures.core.rest.request.DuringPageRequest;
import com.kucoin.futures.core.rest.request.StOrderCreateRequest;
import com.kucoin.futures.core.rest.response.*;
import retrofit2.http.Query;

Expand Down Expand Up @@ -40,6 +41,11 @@ public OrderCreateResponse createOrderTest(OrderCreateApiRequest opsRequest) thr
return executeSync(getAPIImpl().createOrderTest(opsRequest));
}

@Override
public StOrderCreateResponse createStOrders(StOrderCreateRequest request) throws IOException {
return executeSync(getAPIImpl().createStOrders(request));
}

@Override
public OrderCancelResponse cancelOrder(String orderId) throws IOException {
return executeSync(getAPIImpl().cancelOrder(orderId));
Expand All @@ -65,6 +71,11 @@ public OrderResponse getOrderDetail(String orderId) throws IOException {
return executeSync(getAPIImpl().getOrder(orderId));
}

@Override
public OrderResponse getOrderDetailByClientOid(String clientOid) throws IOException {
return executeSync(getAPIImpl().getOrderByClientOid(clientOid));
}

@Override
public Pagination<OrderResponse> getOrderList(String symbol, String side, String type,
String status, DuringPageRequest request) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
*/
package com.kucoin.futures.core.rest.adapter;

import com.kucoin.futures.core.rest.impl.retrofit.AuthRetrofitAPIImpl;
import com.kucoin.futures.core.rest.interceptor.FuturesApiKey;
import com.kucoin.futures.core.rest.interfaces.PositionAPI;
import com.kucoin.futures.core.rest.request.AddMarginManuallyRequest;
import com.kucoin.futures.core.rest.request.HistoryPositionsRequest;
import com.kucoin.futures.core.rest.request.UpdateAutoDepositMarginRequest;
import com.kucoin.futures.core.rest.impl.retrofit.AuthRetrofitAPIImpl;
import com.kucoin.futures.core.rest.interfaces.retrofit.PositionAPIRetrofit;
import com.kucoin.futures.core.rest.request.WithdrawMarginRequest;
import com.kucoin.futures.core.rest.response.HistoryPositionResponse;
import com.kucoin.futures.core.rest.response.Pagination;
import com.kucoin.futures.core.rest.response.PositionResponse;
import com.kucoin.futures.core.rest.request.*;
import com.kucoin.futures.core.rest.response.*;

import java.io.IOException;
import java.math.BigDecimal;
Expand All @@ -40,6 +35,11 @@ public List<PositionResponse> getPositions() throws IOException {
return super.executeSync(getAPIImpl().getPositions());
}

@Override
public MaxOpenSizeResponse getMaxOpenSize(MaxOpenSizeRequest request) throws IOException {
return super.executeSync(getAPIImpl().getMaxOpenSize(request.getSymbol(), request.getPrice(), request.getLeverage()));
}

@Override
public Pagination<HistoryPositionResponse> getHistoryPositions(HistoryPositionsRequest request) throws IOException {
return super.executeSync(getAPIImpl().getHistoryPositions(request.getSymbol(),
Expand All @@ -50,6 +50,26 @@ public Pagination<HistoryPositionResponse> getHistoryPositions(HistoryPositionsR
);
}

@Override
public MarginModeResponse getMarginMode(String symbol) throws IOException {
return super.executeSync(getAPIImpl().getMarginMode(symbol));
}

@Override
public MarginModeResponse changeMarginMode(ChangeMarginRequest request) throws IOException {
return super.executeSync(getAPIImpl().changeMarginMode(request));
}

@Override
public GetCrossUserLeverageResponse getCrossUserLeverage(String symbol) throws IOException {
return super.executeSync(getAPIImpl().getCrossUserLeverage(symbol));
}

@Override
public boolean changeCrossUserLeverage(ChangeCrossUserLeverageRequest req) throws IOException {
return super.executeSync(getAPIImpl().changeCrossUserLeverage(req));
}

@Override
public void setAutoDepositMargin(String symbol, boolean status) throws IOException {
UpdateAutoDepositMarginRequest request = UpdateAutoDepositMarginRequest.builder().status(status).symbol(symbol).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.kucoin.futures.core.rest.response.TickerResponse;

import java.io.IOException;
import java.util.List;

/**
* @author chenshiwei
Expand All @@ -24,4 +25,9 @@ public TickerAPIAdaptor(String baseUrl) {
public TickerResponse getTicker(String symbol) throws IOException {
return super.executeSync(getAPIImpl().getTicker(symbol));
}

@Override
public List<TickerResponse> getAllTickers() throws IOException {
return super.executeSync(getAPIImpl().getAllTickers());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.kucoin.futures.core.rest.request.DuringPageRequest;
import com.kucoin.futures.core.rest.request.OrderCreateApiRequest;
import com.kucoin.futures.core.rest.request.StOrderCreateRequest;
import com.kucoin.futures.core.rest.response.*;

import java.io.IOException;
Expand Down Expand Up @@ -53,6 +54,18 @@ public interface OrderAPI {
*/
OrderCreateResponse createOrderTest(OrderCreateApiRequest opsRequest) throws IOException;


/**
* This interface supports both take-profit and stop-loss functions, and other functions are exactly the same as the place order interface.
* You can place two types of orders: limit and market. Orders can only be placed if your account has sufficient funds. Once an order is placed,
* your funds will be put on hold for the duration of the order. The amount of funds on hold depends on the order type and parameters specified.
* Please be noted that the system would hold the fees from the orders entered the orderbook in advance. Read Get Fills to learn more.
* @param request
* @return
* @throws IOException
*/
StOrderCreateResponse createStOrders(StOrderCreateRequest request) throws IOException;

/**
* Cancel an order
* <p>
Expand Down Expand Up @@ -133,6 +146,15 @@ Pagination<OrderResponse> getOrderList(String symbol, String side, String type,
*/
OrderResponse getOrderDetail(String orderId) throws IOException;


/**
* Get a single order by clientOid
*
* @param clientOid
* @return The requested order.
*/
OrderResponse getOrderDetailByClientOid(String clientOid) throws IOException;

/**
* This interface is for the actual fee rate of the trading pair.
* The fee rate of your sub-account is the same as that of the master account.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
*/
package com.kucoin.futures.core.rest.interfaces;

import com.kucoin.futures.core.rest.request.ChangeCrossUserLeverageRequest;
import com.kucoin.futures.core.rest.request.ChangeMarginRequest;
import com.kucoin.futures.core.rest.request.HistoryPositionsRequest;
import com.kucoin.futures.core.rest.request.WithdrawMarginRequest;
import com.kucoin.futures.core.rest.response.HistoryPositionResponse;
import com.kucoin.futures.core.rest.response.Pagination;
import com.kucoin.futures.core.rest.response.PositionResponse;
import com.kucoin.futures.core.rest.response.*;

import java.io.IOException;
import java.math.BigDecimal;
Expand Down Expand Up @@ -37,6 +37,14 @@ public interface PositionAPI {
*/
List<PositionResponse> getPositions() throws IOException;


/**
* Get Maximum Open Position Size
* @return
* @throws IOException
*/
MaxOpenSizeResponse getMaxOpenSize(MaxOpenSizeRequest request) throws IOException;

/**
* This interface can query position history information records
*
Expand All @@ -46,6 +54,32 @@ public interface PositionAPI {
*/
Pagination<HistoryPositionResponse> getHistoryPositions(HistoryPositionsRequest request) throws IOException;


/**
* This interface can query the margin mode of the current symbol.
* @param symbol symbol
* @return
* @throws IOException
*/
MarginModeResponse getMarginMode(String symbol) throws IOException;


/**
* This interface can modify the margin mode of the current symbol
*/
MarginModeResponse changeMarginMode(ChangeMarginRequest request) throws IOException;


/**
* This interface can query the current symbol’s cross-margin leverage multiple
*/
GetCrossUserLeverageResponse getCrossUserLeverage(String symbol) throws IOException;

/**
* This interface can modify the current symbol’s cross-margin leverage multiple
*/
boolean changeCrossUserLeverage(ChangeCrossUserLeverageRequest req) throws IOException;

/**
* Enable/Disable of Auto-Deposit Margin
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.kucoin.futures.core.rest.response.TickerResponse;

import java.io.IOException;
import java.util.List;

/**
* @author chenshiwei
Expand All @@ -25,4 +26,12 @@ public interface TickerAPI {
*/
TickerResponse getTicker(String symbol) throws IOException;


/**
* Get Latest Ticker for All Contracts
* @return
* @throws IOException
*/
List<TickerResponse> getAllTickers() throws IOException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@
package com.kucoin.futures.core.rest.interfaces.retrofit;

import com.kucoin.futures.core.rest.request.OrderCreateApiRequest;
import com.kucoin.futures.core.rest.request.StOrderCreateRequest;
import com.kucoin.futures.core.rest.response.*;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Path;
import retrofit2.http.Query;
import retrofit2.http.*;

import java.util.List;

Expand All @@ -29,6 +25,9 @@ public interface OrderAPIRetrofit {
@POST("api/v1/orders/test")
Call<KucoinFuturesResponse<OrderCreateResponse>> createOrderTest(@Body OrderCreateApiRequest opsRequest);

@POST("api/v1/st-orders")
Call<KucoinFuturesResponse<StOrderCreateResponse>> createStOrders(@Body StOrderCreateRequest opsRequest);

@DELETE("api/v1/orders/{orderId}")
Call<KucoinFuturesResponse<OrderCancelResponse>> cancelOrder(@Path("orderId") String orderId);

Expand All @@ -44,24 +43,27 @@ public interface OrderAPIRetrofit {
@GET("api/v1/orders/{orderId}")
Call<KucoinFuturesResponse<OrderResponse>> getOrder(@Path("orderId") String orderId);

@GET("api/v1/orders/byClientOid")
Call<KucoinFuturesResponse<OrderResponse>> getOrderByClientOid(@Query("clientOid") String clientOid);

@GET("api/v1/orders")
Call<KucoinFuturesResponse<Pagination<OrderResponse>>> queryOrders(@Query("symbol") String symbol,
@Query("side") String side,
@Query("type") String type,
@Query("status") String status,
@Query("startAt") Long startAt,
@Query("endAt") Long endAt,
@Query("pageSize") int pageSize,
@Query("currentPage") int currentPage);
@Query("side") String side,
@Query("type") String type,
@Query("status") String status,
@Query("startAt") Long startAt,
@Query("endAt") Long endAt,
@Query("pageSize") int pageSize,
@Query("currentPage") int currentPage);

@GET("api/v1/stopOrders")
Call<KucoinFuturesResponse<Pagination<OrderResponse>>> queryStopOrders(@Query("symbol") String symbol,
@Query("side") String side,
@Query("type") String type,
@Query("startAt") Long startAt,
@Query("endAt") Long endAt,
@Query("pageSize") int pageSize,
@Query("currentPage") int currentPage);
@Query("side") String side,
@Query("type") String type,
@Query("startAt") Long startAt,
@Query("endAt") Long endAt,
@Query("pageSize") int pageSize,
@Query("currentPage") int currentPage);

@GET("api/v1/recentDoneOrders")
Call<KucoinFuturesResponse<List<OrderResponse>>> queryRecentDoneOrders();
Expand Down
Loading

0 comments on commit d16eae6

Please sign in to comment.