Code Monkey home page Code Monkey logo

kucoin-java-sdk's Introduction

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 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.0</version>
</dependency>

Usage

Build Client

KucoinClientBuilder builder = new KucoinClientBuilder().withBaseUrl("https://openapi-sandbox.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
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.

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().get24hrStats(symbol);
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);
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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.