The official Java client for communicating with Kite Connect API.

The Kite Connect API Java client

The official Java client for communicating with Kite Connect API.

Kite Connect is a set of REST-like APIs that expose many capabilities required to build a complete investment and trading platform. Execute orders in real time, manage user portfolio, stream live market data (WebSockets), and more, with the simple HTTP API collection.

Rainmatter (c) 2016. Licensed under the MIT License.



  • Download jar file and include it in your build path.

  • Include com.rainmatter.kiteconnect into build path from maven. Use version 1.4.1

API usage

// Initialize Kiteconnect using apiKey.
Kiteconnect kiteSdk = new Kiteconnect("xxxx");

// Set userId.

/* First you should get request_token, public_token using kitconnect login and then use request_token, public_token, api_secret to make any kiteconnect api call.
Get login url. Use this url in webview to login user, after authenticating user you will get requestToken. Use the same to get accessToken. */
String url = kiteSdk.getLoginUrl();

// Get accessToken as follows,
UserModel userModel =  kiteSdk.requestAccessToken("xxxxx", "xxxxx");

// Set request token and public token which are obtained from login process.

// Set session expiry callback.
kiteSdk.registerHook(new SessionExpiryHook() {
    public void sessionExpired() {
    System.out.println("session expired");                    }

// Get margins returns margin model, you can pass equity or commodity as arguments to get margins of respective segments.
Margins margins = kiteSdk.getMargins("equity");

/* Place order method requires a map argument which contains,
tradingsymbol, exchange, transaction_type, order_type, quantity, product, price, trigger_price, disclosed_quantity, validity
squareoff_value, stoploss_value, trailing_stoploss
and variety  which can be value can be regular, bo, co, amo.
place order which will return order model which will have only orderId in the order model.

Following is an example param for SL order,
if a call fails then KiteException will have error message in it
Success of this call implies only order has been placed successfully, not order execution.*/
Map<String, Object> param = new HashMap<String, Object>(){
        put("quantity", "1");
        put("order_type", "SL");
        put("tradingsymbol", "HINDALCO");
        put("product", "CNC");
        put("exchange", "NSE");
        put("transaction_type", "BUY");
        put("validity", "DAY");
        put("price", "158.0");
        put("trigger_price", "157.5");
Order order = kiteconnect.placeOrder(param, "regular");

For more details, take a look at in sample directory.

WebSocket live streaming data

/** To get live price use KiteTicker websocket connection. 
It is recommended to use only one websocket connection at any point of time and make sure you stop connection, once user goes out of app.*/
ArrayList tokens = new ArrayList<>();
KiteTicker tickerProvider = new KiteTicker(kiteconnect);
tickerProvider.setOnConnectedListener(new OnConnect() {
    public void onConnected() {
        try {
            /** Subscribe ticks for token.
              * By default, all tokens are subscribed for modeQuote.*/
        } catch (IOException e) {
        } catch (WebSocketException e) {

tickerProvider.setOnDisconnectedListener(new OnDisconnect() {
    public void onDisconnected() {
       // your code goes here

tickerProvider.setOnTickerArrivalListener(new OnTick() {
    public void onTick(ArrayList<Tick> ticks) {

// Connects to ticker server for getting live quotes.

// Disconnect from ticker server.

For more details about different mode of quotes and subscribing for them, take a look at Examples in sample directory.