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 27c9d52 commit 99366aa
Show file tree
Hide file tree
Showing 32 changed files with 866 additions and 38 deletions.
5 changes: 2 additions & 3 deletions README.md
Expand Up @@ -13,13 +13,13 @@ The detailed document [https://docs.kucoin.com](https://docs.kucoin.com).
<dependency>
<groupId>com.kucoin</groupId>
<artifactId>kucoin-java-sdk</artifactId>
<version>1.0.9</version>
<version>1.0.10</version>
</dependency>
```
## Usage
### Build Client
```java
KucoinClientBuilder builder = new KucoinClientBuilder().withBaseUrl("https://openapi-sandbox.kucoin.com").withApiKey("YOUR_API_KEY", "YOUR_SECRET", "YOUR_PASS_PHRASE");
KucoinClientBuilder builder = new KucoinClientBuilder().withBaseUrl("https://openapi-v2.kucoin.com").withApiKey("YOUR_API_KEY", "YOUR_SECRET", "YOUR_PASS_PHRASE");
KucoinRestClient kucoinRestClient = builder.buildRestClient();
KucoinPrivateWSClient kucoinPrivateWSClient = builder.buildPrivateWSClient();
KucoinPublicWSClient kucoinPublicWSClient = builder.buildPublicWSClient();
Expand All @@ -30,7 +30,6 @@ You can use `withBaseUrl` method to change evironment.
| **Environment** | **BaseUri** |
| -------- | -------- |
| *Production* `DEFAULT` | https://openapi-v2.kucoin.com |
| *Sandbox* | https://openapi-sandbox.kucoin.com |

If you only need to use the public web socket client or REST client public method, you can igonre `withApiKey` method. To customize your own API implementation, you may use the `with*API` method we provided for you.

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -6,7 +6,7 @@

<groupId>com.kucoin</groupId>
<artifactId>kucoin-java-sdk</artifactId>
<version>1.0.9</version>
<version>1.0.10</version>

<name>kucoin-java-sdk</name>
<description>kucoin-java-sdk</description>
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/kucoin/sdk/KucoinClientBuilder.java
Expand Up @@ -71,6 +71,8 @@ public class KucoinClientBuilder {

private IsolatedAPI isolatedAPI;

private OcoOrderAPI ocoOrderAPI;

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 @@ -89,6 +91,7 @@ public KucoinRestClient buildRestClient() {
if (symbolAPI == null) symbolAPI = new SymbolAPIAdaptor(baseUrl);
if (orderBookAPI == null) orderBookAPI = new OrderBookAPIAdapter(baseUrl, apiKey, secret, passPhrase, apiKeyVersion);
if (historyAPI == null) historyAPI = new HistoryAPIAdapter(baseUrl);
if (ocoOrderAPI == null) ocoOrderAPI = new OcoOrderAPIAdapter(baseUrl, apiKey, secret, passPhrase, apiKeyVersion);
return new KucoinRestClientImpl(this);
}

Expand Down Expand Up @@ -145,6 +148,11 @@ public KucoinClientBuilder withStopOrderAPI(StopOrderAPI stopOrderAPI) {
return this;
}

public KucoinClientBuilder withOcoOrderAPI(OcoOrderAPI ocoOrderAPI) {
this.ocoOrderAPI = ocoOrderAPI;
return this;
}

public KucoinClientBuilder withWithdrawalAPI(WithdrawalAPI withdrawalAPI) {
this.withdrawalAPI = withdrawalAPI;
return this;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/kucoin/sdk/KucoinRestClient.java
Expand Up @@ -41,4 +41,6 @@ public interface KucoinRestClient {
LoanAPI loanAPI();

IsolatedAPI isolatedAPI();

OcoOrderAPI ocoOrderAPI();
}
16 changes: 12 additions & 4 deletions src/main/java/com/kucoin/sdk/impl/KucoinRestClientImpl.java
Expand Up @@ -36,13 +36,15 @@ public class KucoinRestClientImpl implements KucoinRestClient {

private final StopOrderAPI stopOrderAPI;

private CommonAPI commonAPI;
private final CommonAPI commonAPI;

private MarginAPI marginAPI;
private final MarginAPI marginAPI;

private LoanAPI loanAPI;
private final LoanAPI loanAPI;

private IsolatedAPI isolatedAPI;
private final IsolatedAPI isolatedAPI;

private final OcoOrderAPI ocoOrderAPI;

public KucoinRestClientImpl(KucoinClientBuilder kucoinBuilder) {
this.userAPI = kucoinBuilder.getUserAPI();
Expand All @@ -61,6 +63,7 @@ public KucoinRestClientImpl(KucoinClientBuilder kucoinBuilder) {
this.marginAPI = kucoinBuilder.getMarginAPI();
this.loanAPI = kucoinBuilder.getLoanAPI();
this.isolatedAPI = kucoinBuilder.getIsolatedAPI();
this.ocoOrderAPI = kucoinBuilder.getOcoOrderAPI();
}

@Override
Expand Down Expand Up @@ -143,4 +146,9 @@ public IsolatedAPI isolatedAPI() {
return isolatedAPI;
}

@Override
public OcoOrderAPI ocoOrderAPI() {
return ocoOrderAPI;
}

}
14 changes: 14 additions & 0 deletions src/main/java/com/kucoin/sdk/model/enums/OcoOrderStatusEnum.java
@@ -0,0 +1,14 @@
/**
* Copyright 2019 Mek Global Limited.
*/
package com.kucoin.sdk.model.enums;

/**
* @author blazetan
*/
public enum OcoOrderStatusEnum {
NEW,
TRIGGERED,
CANCELLED,
DONE
}
15 changes: 15 additions & 0 deletions src/main/java/com/kucoin/sdk/model/enums/StopOrderStatusEnum.java
@@ -0,0 +1,15 @@
/**
* Copyright 2019 Mek Global Limited.
*/
package com.kucoin.sdk.model.enums;

/**
* @author blazetan
*/
public enum StopOrderStatusEnum {
NEW,
PENDING,
TRIGGERED,
CANCELLED,
DONE
}
10 changes: 10 additions & 0 deletions src/main/java/com/kucoin/sdk/rest/adapter/IsolatedAPIAdapter.java
Expand Up @@ -82,4 +82,14 @@ public void repaySingle(String symbol, String currency, BigDecimal size, String
request.setLoanId(loanId);
executeSync(getAPIImpl().repaySingle(request));
}

@Override
public List<IsolatedMarginCurrencyResponse> getIsolatedCurrencies(String symbol) throws IOException {
return executeSync(getAPIImpl().getIsolatedCurrencies(true, symbol));
}

@Override
public IsolatedAccountV3Response getIsolatedAccountsV3(String symbol, String quoteCurrency, String queryType) throws IOException {
return executeSync(getAPIImpl().getIsolatedAccountsV3(symbol, quoteCurrency, queryType));
}
}
22 changes: 17 additions & 5 deletions src/main/java/com/kucoin/sdk/rest/adapter/MarginAPIAdapter.java
Expand Up @@ -7,11 +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.response.MarginAccountResponse;
import com.kucoin.sdk.rest.response.MarginConfigResponse;
import com.kucoin.sdk.rest.response.MarginOrderCreateResponse;
import com.kucoin.sdk.rest.response.MarginPriceStrategyResponse;
import com.kucoin.sdk.rest.response.MarkPriceResponse;
import com.kucoin.sdk.rest.response.*;

import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -54,4 +50,20 @@ public MarginOrderCreateResponse createMarginOrder(MarginOrderCreateRequest requ
public List<MarginPriceStrategyResponse> getMarginPriceStrategy(String marginModel) throws IOException {
return executeSync(getAPIImpl().getMarginPriceStrategy(marginModel));
}

@Override
public List<EtfInfoResponse> getEtfInfo(String currency) throws IOException {
return executeSync(getAPIImpl().getEtfInfo(currency));
}

@Override
public List<CrossMarginCurrencyResponse> getMarginCurrencies(String symbol, String currency) throws IOException {
return executeSync(getAPIImpl().getMarginCurrencies(symbol, currency));
}

@Override
public MarginAccountResponse getMarginAccounts(String quoteCurrency, String queryType) throws IOException {
return executeSync(getAPIImpl().getMarginAccounts(quoteCurrency, queryType));
}

}
93 changes: 93 additions & 0 deletions src/main/java/com/kucoin/sdk/rest/adapter/OcoOrderAPIAdapter.java
@@ -0,0 +1,93 @@
/**
* Copyright 2019 Mek Global Limited.
*/
package com.kucoin.sdk.rest.adapter;

import com.kucoin.sdk.rest.impl.retrofit.AuthRetrofitAPIImpl;
import com.kucoin.sdk.rest.interfaces.OcoOrderAPI;
import com.kucoin.sdk.rest.interfaces.retrofit.OcoOrderAPIRetrofit;
import com.kucoin.sdk.rest.request.OcoOrderCancelRequest;
import com.kucoin.sdk.rest.request.OcoOrderCreateRequest;
import com.kucoin.sdk.rest.request.OcoOrderQueryRequest;
import com.kucoin.sdk.rest.response.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
* @author blazetan
*/
public class OcoOrderAPIAdapter extends AuthRetrofitAPIImpl<OcoOrderAPIRetrofit> implements OcoOrderAPI {

public OcoOrderAPIAdapter(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 OrderCreateResponse createOcoOrder(OcoOrderCreateRequest request) throws IOException {
return executeSync(getAPIImpl().createOcoOrder(request));
}

@Override
public OrderCancelResponse cancelOcoOrder(String orderId) throws IOException {
return executeSync(getAPIImpl().cancelOcoOrderByOrderId(orderId));
}

@Override
public OrderCancelResponse cancelOcoOrderByClientOid(String clientOid) throws IOException {
return executeSync(getAPIImpl().cancelOcoOrderByClientOid(clientOid));
}

@Override
public OrderCancelResponse cancelOcoOrders(OcoOrderCancelRequest request) throws IOException {
Map<String, String> params = new HashMap<>();
if (request.getSymbol() != null) {
params.put("symbol", request.getSymbol());
}
if (request.getOrderIds() != null) {
params.put("orderIds", request.getOrderIds());
}
return executeSync(getAPIImpl().cancelOcoOrders(params));
}

@Override
public OcoOrderResponse getOcoOrder(String orderId) throws IOException {
return executeSync(getAPIImpl().getOcoOrderByOrderId(orderId));
}

@Override
public OcoOrderDetailResponse getOcoOrderDetails(String orderId) throws IOException {
return executeSync(getAPIImpl().getOcoOrderDetails(orderId));
}

@Override
public OcoOrderResponse getOcoOrderByClientOid(String clientOid) throws IOException {
return executeSync(getAPIImpl().getOcoOrderByClientOid(clientOid));
}

@Override
public Pagination<OcoOrderResponse> queryOcoOrders(OcoOrderQueryRequest request) throws IOException {
Map<String, String> params = new HashMap<>();
if (request.getSymbol() != null) {
params.put("symbol", request.getSymbol());
}
if (request.getStartAt() != null) {
params.put("startAt", String.valueOf(request.getStartAt().getTime()));
}
if (request.getEndAt() != null) {
params.put("endAt", String.valueOf(request.getEndAt().getTime()));
}
params.put("currentPage", String.valueOf(request.getCurrentPage()));
params.put("pageSize", String.valueOf(request.getPageSize()));
if (request.getOrderIds() != null) {
params.put("orderIds", request.getOrderIds());
}
return executeSync(getAPIImpl().getOcoOrders(params));
}

}
Expand Up @@ -166,6 +166,11 @@ public String cancelHFOrdersBySymbol(String symbol) throws IOException {
return executeSync(getAPIImpl().cancelHFOrdersBySymbol(symbol));
}

@Override
public HFOrderCancelAllResponse cancelAllHFOrders() throws IOException {
return executeSync(getAPIImpl().cancelAllHFOrders());
}

@Override
public List<HFOrderResponse> getActiveHFOrders(String symbol) throws IOException {
return executeSync(getAPIImpl().getActiveHFOrders(symbol));
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/kucoin/sdk/rest/interfaces/IsolatedAPI.java
Expand Up @@ -90,4 +90,25 @@ public interface IsolatedAPI {
* @param loanId Trade order number; when this field is configured, the sequence strategy is invalidated
*/
void repaySingle(String symbol, String currency, BigDecimal size, String loanId) throws IOException;

/**
* This interface can obtain the risk limit and currency configuration of isolated margin.
*
* @param symbol
* @return
* @throws IOException
*/
List<IsolatedMarginCurrencyResponse> getIsolatedCurrencies(String symbol) throws IOException;

/**
* Get Account Detail - Isolated Margin V3
* @param symbol For isolated trading pairs, query all without passing
* @param quoteCurrency currently only supports USDT, KCS, BTC, default is USDT
* @param queryType Query account type (default MARGIN), ISOLATED- - only query low frequency isolated margin account, ISOLATED_V2-only query high frequency isolated margin account, ALL - consistent aggregate query with the web side
* @return
*/
IsolatedAccountV3Response getIsolatedAccountsV3(String symbol,
String quoteCurrency,
String queryType) throws IOException;

}
33 changes: 28 additions & 5 deletions src/main/java/com/kucoin/sdk/rest/interfaces/MarginAPI.java
Expand Up @@ -4,11 +4,8 @@
package com.kucoin.sdk.rest.interfaces;

import com.kucoin.sdk.rest.request.MarginOrderCreateRequest;
import com.kucoin.sdk.rest.response.MarginAccountResponse;
import com.kucoin.sdk.rest.response.MarginConfigResponse;
import com.kucoin.sdk.rest.response.MarginOrderCreateResponse;
import com.kucoin.sdk.rest.response.MarginPriceStrategyResponse;
import com.kucoin.sdk.rest.response.MarkPriceResponse;
import com.kucoin.sdk.rest.response.*;
import retrofit2.http.Query;

import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -64,4 +61,30 @@ public interface MarginAPI {
* @return
*/
List<MarginPriceStrategyResponse> getMarginPriceStrategy(String marginModel) throws IOException;

/**
* Get Leveraged Token Info
* @param currency
* @return EtfInfoResponse
* @throws IOException
*/
List<EtfInfoResponse> getEtfInfo(String currency) throws IOException;

/**
* This interface can obtain the risk limit and currency configuration of cross margin.
*
* @param symbol
* @param currency
* @return
*/
List<CrossMarginCurrencyResponse> getMarginCurrencies(String symbol, String currency) throws IOException;

/**
* Get Account Detail - Cross Margin
* @param quoteCurrency currently only supports USDT, KCS, BTC, USDT as default
* @param queryType Query account type (default MARGIN), MARGIN - only query low frequency cross margin account, MARGIN_V2-only query high frequency cross margin account, ALL - consistent aggregate query with the web side
* @return
*/
MarginAccountResponse getMarginAccounts(String quoteCurrency, String queryType) throws IOException;

}

0 comments on commit 99366aa

Please sign in to comment.