Skip to content

Kucoin/kucoin-futures-java-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JAVA SDK for KucoinFutures API

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

Latest Version

Build Status

Installation

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

Usage

Build Client

KucoinFuturesClientBuilder builder = new KucoinFuturesClientBuilder().withBaseUrl("https://api-sandbox-futures.kucoin.com").withApiKey("YOUR_API_KEY", "YOUR_SECRET", "YOUR_PASS_PHRASE");
KucoinFuturesRestClient kucoinFuturesRestClient = builder.buildRestClient();
KucoinFuturesPrivateWSClient kucoinFuturesPrivateWSClient = builder.buildPrivateWSClient();
KucoinFuturesPublicWSClient kucoinFuturesPublicWSClient = builder.buildPublicWSClient();

You can use withBaseUrl method to change evironment.

Environment BaseUri
Production DEFAULT https://api-futures.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
kucoinFuturesRestClient.accountAPI().accountOverview();
kucoinFuturesRestClient.accountAPI().transactionHistory(type, pageRequest);          
Deposits
kucoinFuturesRestClient.depositAPI().getDepositAddress(currency);
kucoinFuturesRestClient.depositAPI().getDepositAddressList(status, pageRequest);
Withdrawals
kucoinFuturesRestClient.withdrawalAPI().withdrawalAPI().getWithdrawList(status, pageRequest);
kucoinFuturesRestClient.withdrawalAPI().getWithdrawQuotas(currency);
WithdrawApplyRequest withdrawApplyRequest = WithdrawApplyRequest.builder().address(address)
                .amount(amount).currency(currency).build();
kucoinFuturesRestClient.withdrawalAPI().withdrawFunds(withdrawApplyRequest);
kucoinFuturesRestClient.withdrawalAPI().cancelWithdraw(withdrawalId);
Transfer
kucoinFuturesRestClient.transferAPI().getTransferOutRecords(status, pageRequest);
kucoinFuturesRestClient.transferAPI().toKucoinMainAccount(bizNo, amount);
kucoinFuturesRestClient.transferAPI().cancelTransferOutRequest(applyId)

Trade

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

Orders
OrderCreateApiRequest createRequest = OrderCreateApiRequest.builder()
                .price(BigDecimal.valueOf(1000)).size(BigDecimal.ONE).side("buy").leverage("5")
                .symbol(SYMBOL).type("limit").clientOid(UUID.randomUUID().toString()).build();
kucoinFuturesRestClient.orderAPI().getOrderDetail(orderId);
kucoinFuturesRestClient.orderAPI().cancelOrder(orderId);
kucoinFuturesRestClient.orderAPI().cancelAllOrders(symbol);
kucoinFuturesRestClient.orderAPI().getUntriggeredStopOrderList(symbol, sid, type, pageRequest);
kucoinFuturesRestClient.orderAPI().cancelAllStopOrders(symbol);
kucoinFuturesRestClient.orderAPI().getOrderList(symbol, side, type, status, pageRequest);
kucoinFuturesRestClient.orderAPI().getRecentDoneOrders();
Fills
kucoinFuturesRestClient.fillAPI().getFills(symbol, orderId, side, type, pageRequest);
kucoinFuturesRestClient.fillAPI().recentFills();
kucoinFuturesRestClient.fillAPI().calActiveOrderValue(symbol);
Positions
kucoinFuturesRestClient.positionAPI().getPosition(symbol);
kucoinFuturesRestClient.positionAPI().getPositions();
kucoinFuturesRestClient.positionAPI().setAutoDepositMargin(symbol, status);
kucoinFuturesRestClient.positionAPI().addMarginManually(symbol, margin, bizNo);
Funding Fees
kucoinFuturesRestClient.fundingFeeAPI().getFundingHistory(symbol, reverse, forward, hasMoreRequest);

Market Date

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

Symbols
kucoinFuturesRestClient.symbolAPI().getContract(symbol);
kucoinFuturesRestClient.symbolAPI().getOpenContractList();
Ticker
kucoinFuturesRestClient.symbolAPI().tickerAPI().getTicker(symbol);
Order Book
kucoinFuturesRestClient.orderBookAPI().getFullLevel2OrderBook(symbol);
kucoinFuturesRestClient.orderBookAPI().getLevel2PullingMessages(symbol, sequenceStart, sequenceEnd);
kucoinFuturesRestClient.orderBookAPI().getFullLevel3OrderBook(symbol);
kucoinFuturesRestClient.orderBookAPI().getLevel3PullingMessages(symbol, sequenceStart, sequenceEnd);
Histories
kucoinFuturesRestClient.historyAPI().getTransactionHistories(symbol)
Index
kucoinFuturesRestClient.indexAPI().getInterestRateList(symbol, reverse, forward, hasMoreRequest);
Time
kucoinFuturesRestClient.timeAPI().getServerTimeStamp();

Websocket Feed

Use KucoinFuturesClientBuilder 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
kucoinFuturesPublicWSClient.onTicker(response -> {
            System.out.println(response);
        }, symbols);
kucoinFuturesPublicWSClient.onLevel2Data(response -> {
            System.out.println(response);
        }, symbols);
kucoinFuturesPublicWSClient.onExecutionData(response -> {
            System.out.println(response);
        }, symbols);
kucoinFuturesPublicWSClient.onLevel3Data(response -> {
            System.out.println(response);
        }, symbols);
kucoinFuturesPublicWSClient.onContractMarketData(response -> {
            System.out.println(response);
        }, symbols);
kucoinFuturesPublicWSClient.onTransactionStatistic(response -> {
            System.out.println(response);
        }, symbols);

Private Channels

Listen for stop order activate message
kucoinPrivateWSClient.onStopOrderActivate(response -> {
            System.out.println(response);
        });
Listen for account balance changes
kucoinPrivateWSClient.onAccountBalance(response -> {
            System.out.println(response);
        });
Listen for position change message
kucoinPrivateWSClient.onPositionChange(response -> {
            System.out.println(response);
        }, symbols);

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

Packages

No packages published

Languages