Skip to content

Commit

Permalink
v1.0.14
Browse files Browse the repository at this point in the history
- Add HFMarginAPI
- Add VipLendingAPI
- Update MarginAPI
- Update CurrencyAPI
- Add new TOPIC to PrivateWSClient
  • Loading branch information
colt-han committed Aug 7, 2024
1 parent 4b2aa73 commit 62dbca3
Show file tree
Hide file tree
Showing 46 changed files with 1,498 additions and 32 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](https://docs.kucoin.com).
<dependency>
<groupId>com.kucoin</groupId>
<artifactId>kucoin-java-sdk</artifactId>
<version>1.0.13</version>
<version>1.0.14</version>
</dependency>
```
## Usage
Expand Down
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.kucoin</groupId>
<artifactId>kucoin-java-sdk</artifactId>
<version>1.0.14-SNAPSHOT</version>
<version>1.0.14</version>

<name>kucoin-java-sdk</name>
<description>kucoin-java-sdk</description>
Expand Down Expand Up @@ -186,6 +186,12 @@
<goals>
<goal>sign</goal>
</goals>
<configuration>
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/kucoin/sdk/KucoinClientBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public class KucoinClientBuilder {

private VipLendingAPI vipLendingAPI;

private HFMarginAPI hfMarginAPI;

public KucoinRestClient buildRestClient() {
if (StringUtils.isBlank(baseUrl)) baseUrl = APIConstants.API_BASE_URL;
if (userAPI == null) userAPI = new UserAPIAdapter(baseUrl, apiKey, secret, passPhrase, apiKeyVersion);
Expand All @@ -98,6 +100,7 @@ public KucoinRestClient buildRestClient() {
if (ocoOrderAPI == null) ocoOrderAPI = new OcoOrderAPIAdapter(baseUrl, apiKey, secret, passPhrase, apiKeyVersion);
if (earnAPI == null) earnAPI = new EarnAPIAdapter(baseUrl, apiKey, secret, passPhrase, apiKeyVersion);
if (vipLendingAPI == null) vipLendingAPI = new VipLendingAdapter(baseUrl, apiKey, secret, passPhrase, apiKeyVersion);
if (hfMarginAPI == null) hfMarginAPI = new HFMarginAPIAdapter(baseUrl, apiKey, secret, passPhrase, apiKeyVersion);
return new KucoinRestClientImpl(this);
}

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/kucoin/sdk/KucoinPrivateWSClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ public interface KucoinPrivateWSClient {
*/
String onMarginPosition(KucoinAPICallback<KucoinEvent<MarginPositionEvent>> callback);

/**
* Isolated Margin Position Event
* <a href="https://www.kucoin.com/docs/websocket/margin-trading/private-channels/isoleted-margin-position-event">ApiDoc</a>
*
* @param callback callback
* @return String
*/
String onMarginIsolatedPosition(KucoinAPICallback<KucoinEvent<MarginIsolatedPositionEvent>> callback);

/**
* Borrowing change message push
*
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/kucoin/sdk/KucoinRestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ public interface KucoinRestClient {
EarnAPI earnAPI();

VipLendingAPI vipLendingAPI();

HFMarginAPI HFMarginAPI();
}
2 changes: 2 additions & 0 deletions src/main/java/com/kucoin/sdk/constants/APIConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ public class APIConstants {
public static final String API_SNAPSHOT_TOPIC_PREFIX = "/market/snapshot:";
public static final String API_INDICATOR_INDEX_TOPIC_PREFIX = "/indicator/index:";
public static final String API_INDICATOR_MARKPRICE_TOPIC_PREFIX = "/indicator/markPrice:";
@Deprecated
public static final String API_MARGIN_FUNDINGBOOK_TOPIC_PREFIX = "/margin/fundingBook:";
public static final String API_MARGIN_ISOLATED_POSITION_TOPIC_PREFIX = "/margin/isolatedPosition:";
}
11 changes: 11 additions & 0 deletions src/main/java/com/kucoin/sdk/impl/KucoinPrivateWSClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ public String onMarginPosition(KucoinAPICallback<KucoinEvent<MarginPositionEvent
return subscribe(APIConstants.API_MARGIN_POSITION_TOPIC_PREFIX, true, true);
}

@Override
public String onMarginIsolatedPosition(KucoinAPICallback<KucoinEvent<MarginIsolatedPositionEvent>> callback) {
if (callback != null) {
this.listener.getCallbackMap().put(APIConstants.API_MARGIN_ISOLATED_POSITION_TOPIC_PREFIX, callback);
this.listener.getTypeReferenceMap().put(APIConstants.API_MARGIN_ISOLATED_POSITION_TOPIC_PREFIX,
new TypeReference<KucoinEvent<MarginIsolatedPositionEvent>>() {
});
}
return subscribe(APIConstants.API_MARGIN_ISOLATED_POSITION_TOPIC_PREFIX, true, true);
}

@Override
public String onMarginLoan(KucoinAPICallback<KucoinEvent<MarginLoanEvent>> callback, String symbol) {
if (callback != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ public String onIndicatorMarkPrice(KucoinAPICallback<KucoinEvent<IndicatorEvent>
}

@Override
@Deprecated
public String onMarginFundingBook(KucoinAPICallback<KucoinEvent<FundingBookEvent>> callback, String... currency) {
if (callback != null) {
this.listener.getCallbackMap().put(APIConstants.API_MARGIN_FUNDINGBOOK_TOPIC_PREFIX, callback);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/kucoin/sdk/impl/KucoinRestClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class KucoinRestClientImpl implements KucoinRestClient {

private final VipLendingAPI vipLendingAPI;

private final HFMarginAPI hfMarginAPI;

public KucoinRestClientImpl(KucoinClientBuilder kucoinBuilder) {
this.userAPI = kucoinBuilder.getUserAPI();
this.accountAPI = kucoinBuilder.getAccountAPI();
Expand All @@ -70,6 +72,7 @@ public KucoinRestClientImpl(KucoinClientBuilder kucoinBuilder) {
this.ocoOrderAPI = kucoinBuilder.getOcoOrderAPI();
this.earnAPI = kucoinBuilder.getEarnAPI();
this.vipLendingAPI = kucoinBuilder.getVipLendingAPI();
this.hfMarginAPI = kucoinBuilder.getHfMarginAPI();
}

@Override
Expand Down Expand Up @@ -167,4 +170,9 @@ public VipLendingAPI vipLendingAPI() {
return vipLendingAPI;
}

@Override
public HFMarginAPI HFMarginAPI() {
return hfMarginAPI;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public enum PrivateChannelEnum {
ORDER_CHANGE(APIConstants.API_ORDER_TOPIC_PREFIX),
ORDER_V2_CHANGE(APIConstants.API_ORDER_V2_TOPIC_PREFIX),
MARGIN_POSITION_CHANGE(APIConstants.API_MARGIN_POSITION_TOPIC_PREFIX),
MARGIN_ISOLATED_POSITION_CHANGE(APIConstants.API_MARGIN_ISOLATED_POSITION_TOPIC_PREFIX),
MARGIN_LOAN_CHANGE(APIConstants.API_MARGIN_LOAN_TOPIC_PREFIX),

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

INDICATOR_MARKPRICE(APIConstants.API_INDICATOR_MARKPRICE_TOPIC_PREFIX),

@Deprecated
MARGIN_FUNDINGBOOK(APIConstants.API_MARGIN_FUNDINGBOOK_TOPIC_PREFIX);

private String topicPrefix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.kucoin.sdk.rest.interfaces.retrofit.CurrencyAPIRetrofit;
import com.kucoin.sdk.rest.response.CurrencyDetailResponse;
import com.kucoin.sdk.rest.response.CurrencyDetailV2Response;
import com.kucoin.sdk.rest.response.CurrencyDetailV3Response;
import com.kucoin.sdk.rest.response.CurrencyResponse;

import java.io.IOException;
Expand Down Expand Up @@ -49,4 +50,9 @@ public List<CurrencyDetailV2Response> getCurrenciesV3() throws IOException {
public Map<String, BigDecimal> getFiatPrice(String base, String currencies) throws IOException {
return super.executeSync(getAPIImpl().getFiatPrice(base, currencies));
}

@Override
public CurrencyDetailV3Response getCurrencyDetailV3(String currency, String chain) throws IOException {
return super.executeSync(getAPIImpl().getCurrencyDetailV3(currency, chain));
}
}
86 changes: 86 additions & 0 deletions src/main/java/com/kucoin/sdk/rest/adapter/HFMarginAPIAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.kucoin.sdk.rest.adapter;

import com.kucoin.sdk.rest.impl.retrofit.AuthRetrofitAPIImpl;
import com.kucoin.sdk.rest.interfaces.HFMarginAPI;
import com.kucoin.sdk.rest.interfaces.retrofit.HFMarginAPIRetrofit;
import com.kucoin.sdk.rest.request.HFMarginOrderCreateRequest;
import com.kucoin.sdk.rest.response.*;

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

/**
* @author Colt Han
* @since 2024/7/26
*/
public class HFMarginAPIAdapter extends AuthRetrofitAPIImpl<HFMarginAPIRetrofit> implements HFMarginAPI {

public HFMarginAPIAdapter(String baseUrl, String apiKey, String secret, String passPhrase, Integer apiKeyVersion) {
this.baseUrl = baseUrl;
this.apiKey = apiKey;
this.secret = secret;
this.passPhrase = passPhrase;
this.apiKeyVersion = apiKeyVersion;
}

@Override
public HfMarginOrderActiveSymbolsResponse getHFMarginOrderActiveSymbols(String tradeType) throws IOException {
return executeSync(getAPIImpl().getHfMarginOrderActiveSymbols(tradeType));
}

@Override
public HFMarginOrderCreateResponse createHFMarginOrder(HFMarginOrderCreateRequest request) throws IOException {
return executeSync(getAPIImpl().createHFMarginOrder(request));
}

@Override
public HFMarginOrderCreateResponse createHFMarginOrderTest(HFMarginOrderCreateRequest request) throws IOException {
return executeSync(getAPIImpl().createHFMarginOrderTest(request));
}

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

@Override
public HFMarginOrderCancelByOrderIdResponse cancelHFMarginOrderByOrderId(String orderId, String symbol) throws IOException {
return executeSync(getAPIImpl().cancelHFMarginOrderByOrderId(orderId, symbol));
}

@Override
public String cancelAllHFMarginOrdersBySymbol(String symbol, String tradeType) throws IOException {
return executeSync(getAPIImpl().cancelAllHFMarginOrdersBySymbol(symbol, tradeType));
}

@Override
public List<HFMarginOrderResponse> getHFMarginActiveOrders(String tradeType, String symbol) throws IOException {
return executeSync(getAPIImpl().getHFMarginActiveOrders(tradeType, symbol));
}

@Override
public HFMarginOrderListResponse getHFMarginDoneOrders(String symbol, String tradeType,
String side, String type,
Long startAt, Long endAt,
Long lastId, Integer limit) throws IOException {
return executeSync(getAPIImpl().getHFMarginDoneOrders(symbol, tradeType, side, type, startAt, endAt, lastId, limit));
}

@Override
public HFMarginOrderResponse getHFMarginOrderByOrderId(String orderId, String symbol) throws IOException {
return executeSync(getAPIImpl().getHFMarginOrderByOrderId(orderId, symbol));
}

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

@Override
public HFMarginFillsResponse getHFMarginFills(String orderId, String symbol,
String tradeType, String side,
String type, Long startAt,
Long endAt, Long lastId, Integer limit) throws IOException {
return executeSync(getAPIImpl().getHFMarginFills(orderId, symbol, tradeType, side, type, startAt, endAt, lastId, limit));
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/kucoin/sdk/rest/adapter/MarginAPIAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.kucoin.sdk.rest.interfaces.MarginAPI;
import com.kucoin.sdk.rest.interfaces.retrofit.MarginAPIRetrofit;
import com.kucoin.sdk.rest.request.MarginOrderCreateRequest;
import com.kucoin.sdk.rest.request.UserLeverageUpdateRequest;
import com.kucoin.sdk.rest.response.*;

import java.io.IOException;
Expand Down Expand Up @@ -71,4 +72,13 @@ public MarginAccountResponse getMarginAccounts(String quoteCurrency, String quer
return executeSync(getAPIImpl().getMarginAccounts(quoteCurrency, queryType));
}

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

@Override
public Void updateUserLeverage(UserLeverageUpdateRequest request) throws IOException {
return executeSync(getAPIImpl().updateUserLeverage(request));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import java.io.IOException;

/**
* Created by colt.han on 2024/07/23.
* VipLendingAdapter
*
* @author Colt Han
* @since 2024/7/23
*/
public class VipLendingAdapter extends AuthRetrofitAPIImpl<VipLendingAPIRetrofit> implements VipLendingAPI {

Expand Down
16 changes: 13 additions & 3 deletions src/main/java/com/kucoin/sdk/rest/interfaces/CurrencyAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
*/
package com.kucoin.sdk.rest.interfaces;

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

import com.kucoin.sdk.exception.KucoinApiException;
import com.kucoin.sdk.rest.response.CurrencyDetailResponse;
import com.kucoin.sdk.rest.response.CurrencyDetailV2Response;
import com.kucoin.sdk.rest.response.CurrencyDetailV3Response;
import com.kucoin.sdk.rest.response.CurrencyResponse;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
Expand Down Expand Up @@ -69,4 +69,14 @@ public interface CurrencyAPI {
* @throws KucoinApiException when errors are returned from the exchange.
*/
Map<String, BigDecimal> getFiatPrice(String base, String currencies) throws IOException;

/**
* Get Currency Detail (V3)
* <a href="https://www.kucoin.com/docs/rest/spot-trading/market-data/get-currency-detail">ApiDoc</a>
*
* @param currency Path parameter, Currency
* @param chain Support for querying the chain of currency, e.g. The available value for USDT are OMNI, ERC20, TRC20. This only apply for multi-chain currency, and there is no need for single chain currency.
* @return The currency details of a specified currency
*/
CurrencyDetailV3Response getCurrencyDetailV3(String currency, String chain) throws IOException;
}
Loading

0 comments on commit 62dbca3

Please sign in to comment.