Skip to content

Commit

Permalink
endpoint update
Browse files Browse the repository at this point in the history
  • Loading branch information
blazeTan committed Jul 19, 2024
1 parent 731fbef commit 14e1232
Show file tree
Hide file tree
Showing 26 changed files with 414 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The detailed document [https://docs.kucoin.com/futures/](https://docs.kucoin.com
<dependency>
<groupId>com.kucoin.futures</groupId>
<artifactId>kucoin-futures-java-sdk</artifactId>
<version>1.2.7</version>
<version>1.2.8</version>
</dependency>
```
## Usage
Expand Down
2 changes: 1 addition & 1 deletion 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.7</version>
<version>1.2.8</version>

<name>kucoin-futures-java-sdk</name>
<description>kucoin-futures-java-sdk</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ public interface KucoinFuturesPrivateWSClient extends KucoinFuturesPublicWSClien
*/
String onPositionChange(KucoinFuturesAPICallback<KucoinEvent<PositionChangeEvent>> callback, String ... symbols);

/**
* All Position Change Events
*
* @param callback
* @return
*/
String onPositionAllChange(KucoinFuturesAPICallback<KucoinEvent<PositionChangeEvent>> 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 @@ -60,6 +60,15 @@ public interface KucoinFuturesPublicWSClient {
*/
String onLevel2Depth50Data(KucoinFuturesAPICallback<KucoinEvent<Level2OrderBookEvent>> callback, String... symbols);

/**
* Klines
*
* @param callback
* @param subParam symbol_1min, 3min, 5min, 15min, 30min, 1hour, 2hour, 4hour, 8hour, 12hour, 1day, 1week, 1month
* @return
*/
String onKline(KucoinFuturesAPICallback<KucoinEvent<KLineEvent>> callback, String subParam);

/**
* For each order executed, the system will send you the match messages in the format as following.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ private APIConstants() {}
public static final String API_LIFECYCLE_TOPIC_PREFIX = "/contractMarket/advancedOrders";
public static final String API_BALANCE_TOPIC_PREFIX = "/contractAccount/wallet";
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_K_LINE_TOPIC_PREFIX = "/contractMarket/limitCandle:";
}
32 changes: 32 additions & 0 deletions src/main/java/com/kucoin/futures/core/enums/KLineTypeEnum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.kucoin.futures.core.enums;

import lombok.Getter;

@Getter
public enum KLineTypeEnum {

ONE_MIN("1min"),
THREE_MIN("3min"),
FIVE_MIN("5min"),
FIFTEEN_MIN("15min"),
THIRTY_MIN("30min"),
ONE_HOUR("1hour"),
TWO_HOUR("2hour"),
FOUR_HOUR("4hour"),
EIGHT_HOUR("8hour"),
TWELVE_HOUR("12hour"),
ONE_DAY("1day"),
ONE_WEEK("1week"),
ONE_MONTH("1month");

KLineTypeEnum(String type) {
this.type = type;
}

private final String type;

public String kLineParam(String symbol){
return symbol+"_" + type;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ public String onPositionChange(KucoinFuturesAPICallback<KucoinEvent<PositionChan
return subscribe(topic, true, true);
}

@Override
public String onPositionAllChange(KucoinFuturesAPICallback<KucoinEvent<PositionChangeEvent>> callback) {
if (callback != null) {
this.getListener().getCallbackMap().put(APIConstants.API_POSITION_ALL_TOPIC_PREFIX, callback);
this.getListener().getTypeReferenceMap().put(APIConstants.API_POSITION_ALL_TOPIC_PREFIX,
new TypeReference<KucoinEvent<PositionChangeEvent>>() {});
}
String topic = APIConstants.API_POSITION_ALL_TOPIC_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 @@ -93,6 +93,17 @@ public String onLevel2Depth50Data(KucoinFuturesAPICallback<KucoinEvent<Level2Ord
return subscribe(topic, false, true);
}

@Override
public String onKline(KucoinFuturesAPICallback<KucoinEvent<KLineEvent>> callback, String subParam) {
if (callback != null) {
this.getListener().getCallbackMap().put(APIConstants.API_K_LINE_TOPIC_PREFIX, callback);
this.getListener().getTypeReferenceMap().put(APIConstants.API_K_LINE_TOPIC_PREFIX,
new TypeReference<KucoinEvent<KLineEvent>>() {});
}
String topic = APIConstants.API_K_LINE_TOPIC_PREFIX + subParam;
return subscribe(topic, false, true);
}

@Override
public String onExecutionData(KucoinFuturesAPICallback<KucoinEvent<ExecutionChangeEvent>> callback, String... symbols) {
if (callback != null) {
Expand Down Expand Up @@ -154,8 +165,8 @@ public String ping(String requestId) {
}

@Override
public String unsubscribe(PublicChannelEnum channelEnum, String... symbols) {
return super.unsubscribe(channelEnum.getTopicPrefix() + Arrays.stream(symbols).collect(Collectors.joining(",")),
public String unsubscribe(PublicChannelEnum channelEnum, String... params) {
return super.unsubscribe(channelEnum.getTopicPrefix() + String.join(",", params),
false, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum PrivateChannelEnum {
ACCOUNT(APIConstants.API_BALANCE_TOPIC_PREFIX),

POSITION(APIConstants.API_POSITION_TOPIC_PREFIX),
POSITION_ALL(APIConstants.API_POSITION_ALL_TOPIC_PREFIX),

SYMBOL_ORDER_CHANGE(APIConstants.API_SYMBOL_ORDER_CHANGE_TOPIC_PREFIX),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public enum PublicChannelEnum {

LEVEL2_DEPTH_50(APIConstants.API_LEVEL2_DEPTH_50_PREFIX),

K_LINE_TOPIC(APIConstants.API_K_LINE_TOPIC_PREFIX),

MATCH(APIConstants.API_EXECUTION_TOPIC_PREFIX),

LEVEL3_V2(APIConstants.API_LEVEL3_V2_TOPIC_PREFIX),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,10 @@ public Pagination<OrderResponse> getUntriggeredStopOrderList(String symbol, Stri
public List<OrderResponse> getRecentDoneOrders() throws IOException {
return executeSync(getAPIImpl().queryRecentDoneOrders());
}

@Override
public TradeFeeResponse getTradeFee(String symbol) throws IOException {
return executeSync(getAPIImpl().getTradeFee(symbol));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
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 java.io.IOException;
Expand Down Expand Up @@ -36,12 +40,32 @@ public List<PositionResponse> getPositions() throws IOException {
return super.executeSync(getAPIImpl().getPositions());
}

@Override
public Pagination<HistoryPositionResponse> getHistoryPositions(HistoryPositionsRequest request) throws IOException {
return super.executeSync(getAPIImpl().getHistoryPositions(request.getSymbol(),
request.getFrom(),
request.getTo(),
request.getLimit(),
request.getPageId())
);
}

@Override
public void setAutoDepositMargin(String symbol, boolean status) throws IOException {
UpdateAutoDepositMarginRequest request = UpdateAutoDepositMarginRequest.builder().status(status).symbol(symbol).build();
super.executeSync(getAPIImpl().setAutoDepositMargin(request));
}

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

@Override
public BigDecimal withdrawMargin(WithdrawMarginRequest request) throws IOException {
return super.executeSync(getAPIImpl().withdrawMargin(request));
}

@Override
public void addMarginManually(String symbol, BigDecimal margin, String bizNo) throws IOException {
AddMarginManuallyRequest request = AddMarginManuallyRequest.builder().symbol(symbol).margin(margin).bizNo(bizNo).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,14 @@ Pagination<OrderResponse> getOrderList(String symbol, String side, String type,
*/
OrderResponse getOrderDetail(String orderId) 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.
*
* @param symbol Symbol of the contract
* @return
* @throws IOException
*/
TradeFeeResponse getTradeFee(String symbol) throws IOException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
*/
package com.kucoin.futures.core.rest.interfaces;

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 java.io.IOException;
Expand Down Expand Up @@ -33,6 +37,15 @@ public interface PositionAPI {
*/
List<PositionResponse> getPositions() throws IOException;

/**
* This interface can query position history information records
*
* @param request
* @return
* @throws IOException
*/
Pagination<HistoryPositionResponse> getHistoryPositions(HistoryPositionsRequest request) throws IOException;

/**
* Enable/Disable of Auto-Deposit Margin
*
Expand All @@ -42,6 +55,24 @@ public interface PositionAPI {
*/
void setAutoDepositMargin(String symbol, boolean status) throws IOException;

/**
* This interface can query the maximum amount of margin that the current position supports withdrawal.
*
* @param symbol Symbol of the contract
* @return The size of the position that can be deposited. If it is USDT-margin, it represents the amount of USDT. If it is coin-margin, this value represents the number of coins
* @throws IOException
*/
BigDecimal getMaxWithdrawMargin(String symbol) throws IOException;

/**
* Remove Margin Manually
*
* @param request
* @return The size of the position deposited. If it is USDT-margin, it represents the amount of USDT. If it is coin-margin, this value represents the number of coins
* @throws IOException
*/
BigDecimal withdrawMargin(WithdrawMarginRequest request) throws IOException;

/**
* Add Margin Manually
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,7 @@ Call<KucoinFuturesResponse<Pagination<OrderResponse>>> queryStopOrders(@Query("s
@GET("api/v1/recentDoneOrders")
Call<KucoinFuturesResponse<List<OrderResponse>>> queryRecentDoneOrders();

@GET("api/v1/trade-fees")
Call<KucoinFuturesResponse<TradeFeeResponse>> getTradeFee(@Query("symbol") String symbol);

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

import com.kucoin.futures.core.rest.request.AddMarginManuallyRequest;
import com.kucoin.futures.core.rest.request.UpdateAutoDepositMarginRequest;
import com.kucoin.futures.core.rest.response.KucoinFuturesResponse;
import com.kucoin.futures.core.rest.response.PositionResponse;
import com.kucoin.futures.core.rest.request.WithdrawMarginRequest;
import com.kucoin.futures.core.rest.response.*;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Query;

import java.math.BigDecimal;
import java.util.List;

/**
Expand All @@ -27,9 +28,22 @@ public interface PositionAPIRetrofit {
@GET("api/v1/positions")
Call<KucoinFuturesResponse<List<PositionResponse>>> getPositions();

@GET("api/v1/history-positions")
Call<KucoinFuturesResponse<Pagination<HistoryPositionResponse>>> getHistoryPositions(@Query("symbol") String symbol,
@Query("from") Long from,
@Query("to") Long to,
@Query("limit") Integer limit,
@Query("pageId") Integer pageId);

@POST("api/v1/position/margin/auto-deposit-status")
Call<KucoinFuturesResponse<Object>> setAutoDepositMargin(@Body UpdateAutoDepositMarginRequest request);

@GET("api/v1/margin/maxWithdrawMargin")
Call<KucoinFuturesResponse<BigDecimal>> getMaxWithdrawMargin(@Query("symbol") String symbol);

@POST("api/v1/margin/withdrawMargin")
Call<KucoinFuturesResponse<BigDecimal>> withdrawMargin(@Body WithdrawMarginRequest request);

@POST("api/v1/position/margin/deposit-margin")
Call<KucoinFuturesResponse<Object>> addMarginManually(@Body AddMarginManuallyRequest request);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2019 Mek Global Limited
*/

package com.kucoin.futures.core.rest.request;

import lombok.Builder;
import lombok.Data;

/**
* @author blaze.tan
*/
@Data
@Builder
public class HistoryPositionsRequest {

/**
* Symbol of the contract
*/
private String symbol;

/**
* Closing start time
*/
private Long from;

/**
* Closing end time
*/
private Long to;

/**
* Number of requests per page, max 200, default 10
*/
private Integer limit = 10;

/**
* Current page number, default 1
*/
private Integer pageId = 1;

}
Loading

0 comments on commit 14e1232

Please sign in to comment.