Skip to content

Commit

Permalink
add new endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
blazeTan committed Feb 19, 2024
1 parent 6dee4c9 commit a8d4b27
Show file tree
Hide file tree
Showing 17 changed files with 154 additions and 42 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.4</version>
<version>1.2.5</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.4</version>
<version>1.2.5</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 @@ -77,7 +77,7 @@ public KucoinFuturesRestClient buildRestClient() {
if (tickerAPI == null) tickerAPI = new TickerAPIAdaptor(baseUrl);
if (orderBookAPI == null) orderBookAPI = new OrderBookAPIAdapter(baseUrl);
if (historyAPI == null) historyAPI = new HistoryAPIAdapter(baseUrl);
if (indexAPI == null) indexAPI = new IndexAPIAdapter(baseUrl);
if (indexAPI == null) indexAPI = new IndexAPIAdapter(baseUrl, apiKey);
if (timeAPI == null) timeAPI = new TimeAPIAdapter(baseUrl);
if (serviceStatusAPI == null) serviceStatusAPI = new ServiceStatusAPIAdapter(baseUrl);
if (kChartAPI == null) kChartAPI = new KChartAPIAdapter(baseUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import com.kucoin.futures.core.rest.interceptor.FuturesApiKey;
import com.kucoin.futures.core.rest.interfaces.FundingFeeAPI;
import com.kucoin.futures.core.rest.request.DuringHasMoreRequest;
import com.kucoin.futures.core.rest.response.PublicFundingReteResponse;
import com.kucoin.futures.core.rest.response.HasMoreResponse;
import com.kucoin.futures.core.rest.interfaces.retrofit.FundingFeeAPIRetrofit;
import com.kucoin.futures.core.rest.response.FundingHistoryResponse;

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

/**
* @author chenshiwei
Expand All @@ -31,4 +33,9 @@ public HasMoreResponse<FundingHistoryResponse> getFundingHistory(String symbol,
return super.executeSync(getAPIImpl().getFundingHistory(symbol, reverse, forward, request.getStarAt(),
request.getEndAt(), request.getOffset(), request.getMaxCount()));
}

@Override
public List<PublicFundingReteResponse> getPublicFundingRates(String symbol, long from, long to) throws IOException {
return super.executeSync(getAPIImpl().getFundingRates(symbol, from, to));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,25 @@

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

import com.kucoin.futures.core.rest.response.IndexResponse;
import com.kucoin.futures.core.rest.response.MarkPriceResponse;
import com.kucoin.futures.core.rest.impl.retrofit.AuthRetrofitAPIImpl;
import com.kucoin.futures.core.rest.interceptor.FuturesApiKey;
import com.kucoin.futures.core.rest.response.*;
import com.kucoin.futures.core.rest.impl.retrofit.PublicRetrofitAPIImpl;
import com.kucoin.futures.core.rest.interfaces.IndexAPI;
import com.kucoin.futures.core.rest.interfaces.retrofit.IndexAPIRetrofit;
import com.kucoin.futures.core.rest.request.DuringHasMoreRequest;
import com.kucoin.futures.core.rest.response.FundingRateResponse;
import com.kucoin.futures.core.rest.response.HasMoreResponse;
import com.kucoin.futures.core.rest.response.IndexRateResponse;
import com.kucoin.futures.core.rest.response.InterestRateResponse;

import java.io.IOException;

/**
* @author chenshiwei
* @since 2019/10/15
*/
public class IndexAPIAdapter extends PublicRetrofitAPIImpl<IndexAPIRetrofit> implements IndexAPI {
public class IndexAPIAdapter extends AuthRetrofitAPIImpl<IndexAPIRetrofit> implements IndexAPI {

public IndexAPIAdapter(String baseUrl) {
public IndexAPIAdapter(String baseUrl, FuturesApiKey apiKey) {
this.baseUrl = baseUrl;
this.apiKey = apiKey;
}

@Override
Expand Down Expand Up @@ -60,4 +58,10 @@ public HasMoreResponse<IndexRateResponse> getPremiumIndex(String symbol) throws
public FundingRateResponse getCurrentFundingRate(String symbol) throws IOException {
return super.executeSync(getAPIImpl().getCurrentFundingRate(symbol));
}

@Override
public TradeStatisticsResponse getTradeStatistics() throws IOException {
return super.executeSync(getAPIImpl().getTradeStatistics());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
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.response.OrderCancelResponse;
import com.kucoin.futures.core.rest.response.OrderCreateResponse;
import com.kucoin.futures.core.rest.response.OrderResponse;
import com.kucoin.futures.core.rest.response.Pagination;
import com.kucoin.futures.core.rest.response.*;
import retrofit2.http.Query;

import java.io.IOException;
import java.util.List;
Expand All @@ -37,6 +35,11 @@ public OrderCancelResponse cancelOrder(String orderId) throws IOException {
return executeSync(getAPIImpl().cancelOrder(orderId));
}

@Override
public OrderCancelByClientOidResponse cancelOrderByClientOid(String clientOid, String symbol) throws IOException {
return executeSync(getAPIImpl().cancelOrderByClientOid(clientOid, symbol));
}

@Override
public OrderCancelResponse cancelAllLimitOrders(String symbol) throws IOException {
return executeSync(getAPIImpl().cancelLimitOrders(symbol));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
*/
package com.kucoin.futures.core.rest.interfaces;

import com.kucoin.futures.core.rest.response.PublicFundingReteResponse;
import com.kucoin.futures.core.rest.response.FundingHistoryResponse;
import com.kucoin.futures.core.rest.request.DuringHasMoreRequest;
import com.kucoin.futures.core.rest.response.HasMoreResponse;

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

/**
* Funding Fee API
Expand All @@ -31,4 +33,15 @@ public interface FundingFeeAPI {
HasMoreResponse<FundingHistoryResponse> getFundingHistory(String symbol, Boolean reverse, Boolean forward,
DuringHasMoreRequest request) throws IOException;

/**
* Get Public Funding History
*
* @param symbol
* @param from
* @param to
* @return
* @throws IOException
*/
List<PublicFundingReteResponse> getPublicFundingRates(String symbol, long from, long to) throws IOException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@

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

import com.kucoin.futures.core.rest.response.IndexResponse;
import com.kucoin.futures.core.rest.response.MarkPriceResponse;
import com.kucoin.futures.core.rest.response.*;
import com.kucoin.futures.core.rest.request.DuringHasMoreRequest;
import com.kucoin.futures.core.rest.response.FundingRateResponse;
import com.kucoin.futures.core.rest.response.HasMoreResponse;
import com.kucoin.futures.core.rest.response.IndexRateResponse;
import com.kucoin.futures.core.rest.response.InterestRateResponse;

import java.io.IOException;

Expand Down Expand Up @@ -73,4 +68,13 @@ HasMoreResponse<IndexResponse> getIndexList(String symbol, Boolean reverse, Bool
* @return
*/
FundingRateResponse getCurrentFundingRate(String symbol) throws IOException;

/**
* Get 24hour futures transaction volume
*
* @return
* @throws IOException
*/
TradeStatisticsResponse getTradeStatistics() throws IOException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@

import com.kucoin.futures.core.rest.request.DuringPageRequest;
import com.kucoin.futures.core.rest.request.OrderCreateApiRequest;
import com.kucoin.futures.core.rest.response.OrderCancelResponse;
import com.kucoin.futures.core.rest.response.OrderCreateResponse;
import com.kucoin.futures.core.rest.response.OrderResponse;
import com.kucoin.futures.core.rest.response.Pagination;
import com.kucoin.futures.core.rest.response.*;

import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -46,6 +43,16 @@ public interface OrderAPI {
*/
OrderCancelResponse cancelOrder(String orderId) throws IOException;

/**
* Cancel Order by clientOid
*
* @param clientOid
* @param symbol
* @return OrderCancelByClientOidResponse
* @throws IOException
*/
OrderCancelByClientOidResponse cancelOrderByClientOid(String clientOid, String symbol) throws IOException;

/**
* Cancel all open orders (excluding stop orders). The response is a list of orderIDs of the canceled orders.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
*/
package com.kucoin.futures.core.rest.interfaces.retrofit;

import com.kucoin.futures.core.rest.response.PublicFundingReteResponse;
import com.kucoin.futures.core.rest.response.FundingHistoryResponse;
import com.kucoin.futures.core.rest.response.HasMoreResponse;
import com.kucoin.futures.core.rest.response.KucoinFuturesResponse;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Query;

import java.util.List;

/**
* @author chenshiwei
* @since 2019/10/14
Expand All @@ -25,4 +28,9 @@ Call<KucoinFuturesResponse<HasMoreResponse<FundingHistoryResponse>>> getFundingH
@Query("offset") Long offset,
@Query("maxCount") Long maxCount);

@GET("/api/v1/contract/funding-rates")
Call<KucoinFuturesResponse<List<PublicFundingReteResponse>>> getFundingRates(@Query("symbol") String symbol,
@Query("from") long from,
@Query("to") long to);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@

package com.kucoin.futures.core.rest.interfaces.retrofit;

import com.kucoin.futures.core.rest.response.IndexResponse;
import com.kucoin.futures.core.rest.response.MarkPriceResponse;
import com.kucoin.futures.core.rest.response.FundingRateResponse;
import com.kucoin.futures.core.rest.response.HasMoreResponse;
import com.kucoin.futures.core.rest.response.IndexRateResponse;
import com.kucoin.futures.core.rest.response.InterestRateResponse;
import com.kucoin.futures.core.rest.response.KucoinFuturesResponse;
import com.kucoin.futures.core.rest.response.*;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;
Expand Down Expand Up @@ -49,4 +43,7 @@ Call<KucoinFuturesResponse<HasMoreResponse<IndexResponse>>> getIndexList(@Query(
@GET("api/v1/funding-rate/{symbol}/current")
Call<KucoinFuturesResponse<FundingRateResponse>> getCurrentFundingRate(@Path("symbol") String symbol);

@GET("api/v1/trade-statistics")
Call<KucoinFuturesResponse<TradeStatisticsResponse>> getTradeStatistics();

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

import com.kucoin.futures.core.rest.request.OrderCreateApiRequest;
import com.kucoin.futures.core.rest.response.KucoinFuturesResponse;
import com.kucoin.futures.core.rest.response.OrderCancelResponse;
import com.kucoin.futures.core.rest.response.OrderCreateResponse;
import com.kucoin.futures.core.rest.response.OrderResponse;
import com.kucoin.futures.core.rest.response.Pagination;
import com.kucoin.futures.core.rest.response.*;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
Expand All @@ -30,6 +26,9 @@ public interface OrderAPIRetrofit {
@DELETE("api/v1/orders/{orderId}")
Call<KucoinFuturesResponse<OrderCancelResponse>> cancelOrder(@Path("orderId") String orderId);

@DELETE("api/v1/orders/client-order/{clientOid}")
Call<KucoinFuturesResponse<OrderCancelByClientOidResponse>> cancelOrderByClientOid(@Path("clientOid") String clientOid, @Query("symbol") String symbol);

@DELETE("api/v1/orders")
Call<KucoinFuturesResponse<OrderCancelResponse>> cancelLimitOrders(@Query("symbol") String symbol);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2019 Mek Global Limited
*/
package com.kucoin.futures.core.rest.response;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.ToString;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* @author blazetan
*/
@Data
@ToString
@JsonIgnoreProperties(ignoreUnknown = true)
public class OrderCancelByClientOidResponse {

private String clientOid;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.kucoin.futures.core.rest.response;

import lombok.Data;

import java.math.BigDecimal;

/**
* @author blazetan
*/
@Data
public class PublicFundingReteResponse {
private String symbol;
private BigDecimal fundingRate;
private long timepoint;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.kucoin.futures.core.rest.response;

import lombok.Data;

import java.math.BigDecimal;

/**
* @author blazetan
*/
@Data
public class TradeStatisticsResponse {

private BigDecimal turnoverOf24h;

}
7 changes: 3 additions & 4 deletions src/test/java/com/kucoin/futures/core/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public class BaseTest {
@BeforeClass
public static void setUpClass() throws IOException {
KucoinFuturesClientBuilder builder = new KucoinFuturesClientBuilder().withBaseUrl("https://api-futures.kucoin.com")
.withApiKey("", "",
"", APIConstants.DEFAULT_API_KEY_VERSION);
.withApiKey("", "", "", APIConstants.DEFAULT_API_KEY_VERSION);

futuresRestClient = builder.buildRestClient();
kucoinFuturesPrivateWSClient = builder.buildPrivateWSClient();
Expand All @@ -53,8 +52,8 @@ public static void setUpClass() throws IOException {
kucoinFuturesPublicWSClient = builder.buildPublicWSClient();
kucoinFuturesPublicWSClient.connect();

startAt = LocalDateTime.of(2021, 3, 1, 0, 0, 0).atZone(ZoneId.of("Asia/Shanghai")).toInstant().toEpochMilli();
endAt = LocalDateTime.of(2021, 4, 30, 0, 0, 0).atZone(ZoneId.of("Asia/Shanghai")).toInstant().toEpochMilli();
startAt = LocalDateTime.of(2024, 1, 1, 0, 0, 0).atZone(ZoneId.of("Asia/Shanghai")).toInstant().toEpochMilli();
endAt = LocalDateTime.of(2024, 1, 30, 0, 0, 0).atZone(ZoneId.of("Asia/Shanghai")).toInstant().toEpochMilli();

pageRequest = DuringPageRequest.builder().starAt(startAt).endAt(endAt).currentPage(1).pageSize(10).build();
hasMoreRequest = DuringHasMoreRequest.builder().starAt(startAt).endAt(endAt).offset(0).maxCount(10).build();
Expand Down
Loading

0 comments on commit a8d4b27

Please sign in to comment.