Skip to content

z0mz0m/kucoin-java-sdk

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JAVA SDK for KuCoin API

The detailed document https://docs.kucoin.com.

Latest Version

Build Status

Installation

  1. Install library into your Maven's local repository by running mvn clean install
  2. Add the following Maven dependency to your project's pom.xml:
<dependency>
    <groupId>com.kucoin</groupId>
    <artifactId>kucoin-java-sdk</artifactId>
    <version>1.0.11</version>
</dependency>

Usage

Build Client

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();

You can use withBaseUrl method to change evironment.

Environment BaseUri
Production DEFAULT https://openapi-v2.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.

Example

REST API

User

You need to sign the request to use the private user API.

Accounts
kucoinRestClient.accountAPI().listAccounts(currency, type);
kucoinRestClient.accountAPI().getAccount(mainAccountId);
kucoinRestClient.accountAPI().getAccountHistory(mainAccountId, startAt, endAt, pageNo, pageSize);
kucoinRestClient.accountAPI().innerTransfer(clientOid, fromAccountId, size, toAccountId);
kucoinRestClient.accountAPI().createAccount(currency, type);             
Deposits
kucoinRestClient.depositAPI().createDepositAddress(currency);
kucoinRestClient.depositAPI().getDepositAddress(currency);
kucoinRestClient.depositAPI().getDepositPageList(currency, startAt, endAt, status, pageNo, pageSize);
Withdrawals
kucoinRestClient.withdrawalAPI().getWithdrawList(currency, status, startAt, endAt, pageNo, pageSize);
kucoinRestClient.withdrawalAPI().getWithdrawQuotas(currency);
WithdrawApplyRequest withdrawApplyRequest = WithdrawApplyRequest.builder().address("address")
                .amount(BigDecimal.valueOf(amount)).currency("currency").build();
kucoinRestClient.withdrawalAPI().applyWithdraw(withdrawApplyRequest);
kucoinRestClient.withdrawalAPI().cancelWithdraw(withdrawalId);

Trade

You need to sign the request to use the private trade API.

Orders
OrderCreateApiRequest request = OrderCreateApiRequest.builder()
                .price(BigDecimal.valueOf(price)).size(BigDecimal.ONE).side("buy")
                .symbol("ETH-BTC").type("limit").clientOid(UUID.randomUUID().toString()).build();
kucoinRestClient.orderAPI().createOrder(request);
kucoinRestClient.orderAPI().listOrders(symbol, side, type, status, startAt, endAt, pageNo, pageSize);
kucoinRestClient.orderAPI().getOrder(orderId);
kucoinRestClient.orderAPI().cancelOrder(orderId);
kucoinRestClient.orderAPI().cancelAllOrders(symbol);
Fills
kucoinRestClient.fillAPI().listFills(symbol, orderId, side, type, startAt, endAt, pageNo, pageSize);

Market Date

Market data is public and can be used without a signed request.

Symbols & Ticker
kucoinRestClient.symbolAPI().getTicker(symbol);
kucoinRestClient.symbolAPI().getSymbols();
kucoinRestClient.symbolAPI().getAllTickers();
kucoinRestClient.symbolAPI().get24hrStats(symbol);
kucoinRestClient.symbolAPI().getMarketList();
Order Book
kucoinRestClient.orderBookAPI().getFullOrderBookAggregated(symbol);
kucoinRestClient.orderBookAPI().getFullOrderBookAtomic(symbol);
kucoinRestClient.orderBookAPI().getPartOrderBookAggregated(symbol);
Histories
kucoinRestClient.historyAPI().getTradeHistories(symbol)
kucoinRestClient.historyAPI().getHistoricRates(symbol, startAt, endAt, type);
Currencies
kucoinRestClient.currencyAPI().getCurrencies();
kucoinRestClient.currencyAPI().getCurrencyDetail(currency);
kucoinRestClient.currencyAPI().getFiatPrice(base, currencies);
Time
kucoinRestClient.timeAPI().getServerTimeStamp();

Websocket Feed

Use KucoinClientBuilder to build an instance of the websocket client. Private channel client need to pass the API Key + Secret + Pass Phreas.

The Websocket client uses ChooseServerStrategy to choose server for connection. If you don't plan to use builder.withChooseServerStrategy to set your own strategy, you may use the strategy we provided by random.

Ping

wsClient.ping(requestId)

Unsubscribe

wsClient.unsubscribe(channelEnum, symbols);

Close Client

wsClient.close();

Public Channels

Listen for changes to the order boock for ETH-BTC and KCS-BTC
kucoinPublicWSClient.onTicker(response -> {
            System.out.println(response);
        }, "ETH-BTC", "KCS-BTC");
kucoinPublicWSClient.onLevel2Data(response -> {
            System.out.println(response);
        }, "ETH-BTC", "KCS-BTC");
kucoinPublicWSClient.onMatchExecutionData(response -> {
            System.out.println(response);
        });
kucoinPublicWSClient.onLevel3Data(response -> {
            System.out.println(response);
        }, "ETH-BTC", "KCS-BTC");

Private Channels

Listen for account balance changes
kucoinPrivateWSClient.onAccountBalance(response -> {
            System.out.println(response);
        });
Listen for order activate message
kucoinPrivateWSClient.onOrderActivate(response -> {
            System.out.println(response);
        }, "ETH-BTC", "KCS-BTC");

Testing

To contribute code or modify the library, you may enter the following command to run the test suite:

mvn clean test

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%