Idirect-Tech / Breeze-Java-SDK

The official Java client library for the ICICI Securities trading APIs
8 stars 8 forks source link

Table Of Content

Usage

Download the jar file of the project from the following link breezeconnect jar file and include it in the build path of your project.

Breeze API Java Client

breezeapi@icicisecurities.com

The official Java client library for the ICICI Securities trading APIs. BreezeConnect is a set of REST-like APIs that allows one to build a complete investment and trading platform. Following are some notable features of Breeze APIs:

  1. Execute orders in real time
  2. Manage Portfolio
  3. Access to 10 years of historical market data including 1 sec OHLCV
  4. Streaming live OHLC (websockets)
  5. Option Chain API

API Usage


// Initialize SDK
BreezeConnect breezeConnect = new BreezeConnect("your_api_key");

// Obtain your session key from https://api.icicidirect.com/apiuser/login?api_key=YOUR_API_KEY
// Incase your api-key has special characters(like +,=,!) then encode the api key before using in the url as shown below.
System.out.println("https://api.icicidirect.com/apiuser/login?api_key="+URLEncoder.encode("your_api_key", StandardCharsets.UTF_8));

// Generate Session
breezeConnect.generateSession("your_secret_key","your_api_session");


Websocket Usage

// Initialize SDK
BreezeConnect breezeConnect = new BreezeConnect("your_api_key");

// Obtain your session key from https://api.icicidirect.com/apiuser/login?api_key=YOUR_API_KEY
// Incase your api-key has special characters(like +,=,!) then encode the api key before using in the url as shown below.
System.out.println("https://api.icicidirect.com/apiuser/login?api_key="+URLEncoder.encode("your_api_key", StandardCharsets.UTF_8));

// Generate Session
breezeConnect.generateSession("your_secret_key","your_api_session");

// Connect to websocket(it will connect to rate refresh server)
breezeConnect.connectTicker();

// Callback to receive ticks.
breezeConnect.registerOnTickEventListener(new OnTickEventListener() {
    @Override
    public void onTickEvent(Object tick) {
        System.out.println(tick.toString());
    }
});

// subscribe stocks feeds

breezeConnect.subscribeFeeds("NFO","ZEEENT","options","31-Mar-2022","350","Call", true, false);

// subscribe stocks feeds by stock-token
breezeConnect.subscribeFeeds("1.1!500780");

// unsubscribe stocks feeds
breezeConnect.unsubscribeFeeds("NFO","ZEEENT","options","31-Mar-2022","350","Call", true, false);

// unsubscribe stocks feeds by stock-token
breezeConnect.unsubscribeFeeds("1.1!500780");

// subscribe to Real Time Streaming OHLCV Data of stocks
breezeConnect.subscribeFeeds("NFO", "ZEEENT", "options", "31-Mar-2022","350", "Call", "1minute");

// subscribe to Real Time Streaming OHLCV Data of stocks by stock-token
breezeConnect.subscribeFeeds("1.1!500780","1second");

// unsubscribe to Real Time Streaming OHLCV Data of stocks
breezeConnect.unsubscribeFeeds("NFO", "ZEEENT", "options", "31-Mar-2022", "350", right="Call", interval="1minute");

// unsubscribe to Real Time Streaming OHLCV Data of stocks by stock-token
breezeConnect.unsubscribeFeeds("1.1!500780","1second");

// subscribe order notification feeds(it will connect to order streaming server)
breezeConnect.subscribeFeeds(true)

// unsubscribe order notification feeds(also it will disconnect the order streaming server)
breezeConnect.unsubscribeFeeds(get_order_notification=true)



NOTE

Examples for stock_token are "4.1!38071" or "1.1!500780".

Template for stock_token : X.Y! X : exchange code Y : Market Level data Token : ISEC stock code

Value of X can be : 1 for BSE, 4 for NSE, 13 for NDX, 6 for MCX, 4 for NFO,

Value of Y can be : 1 for Level 1 data, 4 for Level 2 data

Token number can be obtained via get_names() function or downloading master security file via https://api.icicidirect.com/breezeapi/documents/index.html#instruments

exchange_code must be 'BSE', 'NSE', 'NDX', 'MCX' or 'NFO'.

stock_code should not be an empty string. Examples for stock_code are "WIPRO" or "ZEEENT".

product_type can be either 'Futures', 'Options' or an empty string. Product_type can not be an empty string for exchange_code 'NDX', 'MCX' and 'NFO'.

strike_date can be in DD-MMM-YYYY(Ex.: 01-Jan-2022) or an empty string. strike_date can not be an empty string for exchange_code 'NDX', 'MCX' and 'NFO'.

strike_price can be float-value in string or an empty string. strike_price can not be an empty string for product_type 'Options'.

right can be either 'Put', 'Call' or an empty string. right can not be an empty string for product_type 'Options'.

Either get_exchange_quotes must be True or get_market_depth must be True.

Both get_exchange_quotes and get_market_depth can be True, But both must not be False.

For Streaming OHLCV, interval must not be empty and must be equal to either of the following "1second","1minute", "5minute", "30minute"


List of other SDK Methods:

Index

Get Customer details by api-session value.

breezeConnect.getCustomerDetails("your_api_session");


Back to Index


Get Demat Holding details of your account.


breezeConnect.getDematHoldings();


Back to Index


Get Funds details of your account.


breezeConnect.getFunds();


Back to Index


Set Funds of your account

breezeConnect.setFunds("debit","200","Equity");

Note: Set Funds of your account by transaction-type as "Credit" or "Debit" with amount in numeric string as rupees and segment-type as "Equity" or "FNO".


Back to Index


Get Historical Data for Futures

breezeConnect.getHistoricalData(
    "1minute","2022-08-15T07:00:00.000Z","2022-08-17T07:00:00.000Z",
    "ICIBAN","NFO","futures","2022-08-25T07:00:00.000Z","others","0"
);

Back to Index

Get Historical Data for Equity

breezeConnect.getHistoricalData(
    "1minute","2022-08-15T07:00:00.000Z","2022-08-17T07:00:00.000Z",
    "ITC","NSE","cash"
);

Back to Index

Get Historical Data for Options


breezeConnect.getHistoricalData(
    "1minute","2022-08-15T07:00:00.000Z","2022-08-17T07:00:00.000Z",
    "CNXBAN","NFO","options","2022-09-29T07:00:00.000Z","call","38000"
);

Note : Get Historical Data for specific stock-code by mentioned interval either as "1minute", "5minute", "30minute" or as "1day"


Back to Index


Get Historical Data (version 2) for Futures

breezeConnect.getHistoricalDatav2(
    "1minute","2022-08-15T07:00:00.000Z","2022-08-17T07:00:00.000Z",
    "ICIBAN","NFO","futures","2022-08-25T07:00:00.000Z","others","0"
);        

Back to Index

Get Historical Data (version 2) for Equity

breezeConnect.getHistoricalDatav2(
    "1minute","2022-08-15T07:00:00.000Z","2022-08-17T07:00:00.000Z",
    "ITC","NSE","cash"
);

Back to Index

Get Historical Data (version 2) for Options


breezeConnect.getHistoricalDatav2(
    "1minute","2022-08-15T07:00:00.000Z","2022-08-17T07:00:00.000Z",
    "CNXBAN","NFO","options","2022-09-29T07:00:00.000Z","call","38000"
);

Note : 1) Get Historical Data (version 2) for specific stock-code by mentioning interval either as "1second","1minute", "5minute", "30minute" or as "1day". 2) Maximum candle intervals in one single request is 1000


Back to Index


Add Margin to your account.

breezeConnect.addMargin(
    "margin", "ICIBAN", "BSE", "2021220", "100", "3817.10", "10", "0", "", "", 
    "", "", "", ""
);


Back to Index


Get Margin of your account.

breezeConnect.getMargin("NSE");

Note: Please change exchange_code=“NFO” to get F&O margin details


Back to Index


Placing a Futures Order from your account.

breezeConnect.placeOrder(
    "ICIBAN","NFO","futures","buy","limit","0","3200","200","day",
    "2022-08-22T06:00:00.000Z","0","2022-08-25T06:00:00.000Z","others",
    "0","Test"
);

Placing an Option Order from your account.

breezeConnect.placeOrder(
    "NIFTY","NFO","options","buy","market","","50","","day","2022-08-30T06:00:00.000Z",
    "0","2022-09-29T06:00:00.000Z","call","16600"
);


Back to Index

Place a cash order from your account.

breezeConnect.placeOrder(
    "ITC","NSE","cash","buy","limit","","1","305","day"
);


Back to Index

Place an optionplus order


breezeConnect.placeOrder(
    "NIFTY","NFO","optionplus","buy","limit","15","50","11.25","day",
    "2022-12-02T06:00:00.000Z","0","2022-12-08T06:00:00.000Z","call",
    "19000","Limit","20","Test"
);


Back to Index

Place an future plus order


breezeConnect.placeOrder( 
    "NIFTY","NFO","futureplus","Buy","limit","18720",
    "50","18725","Day","0","29-DEC-2022"
);


Future plus - "Stop loss trigger price cannot be less than last traded price for Buy order"

Back to Index


Get an order details by exchange-code and order-id from your account.

breezeConnect.getOrderDetail("NSE","20220819N100000001");

Note: Please change exchange_code=“NFO” to get details about F&O


Back to Index


Get order list of your account.

breezeConnect.getOrderList("NSE","2022-08-01T10:00:00.000Z","2022-08-19T10:00:00.000Z");

Note: Please change exchange_code=“NFO” to get details about F&O


Back to Index


Cancel an order from your account whose status are not Executed.

breezeConnect.cancelOrder("NSE","20220819N100000001");


Back to Index


Modify an order from your account whose status are not Executed.

breezeConnect.modifyOrder(
    "202208191100000001","NFO","limit","0","250","290100","day",
    "0","2022-08-22T06:00:00.000Z"
);


Back to Index


Get Portfolio Holdings of your account.

breezeConnect.getPortfolioHoldings(
    "NFO","2022-08-01T06:00:00.000Z","2022-08-19T06:00:00.000Z","",""
);

Note: Please change exchange_code=“NSE” to get Equity Portfolio Holdings


Back to Index


Get Portfolio Positions from your account.

breezeConnect.getPortfolioPositions()


Back to Index


Get quotes of mentioned stock-code

breezeConnect.getQuotes(
    "ICIBAN","NFO","2022-08-25T06:00:00.000Z","futures",
    "others","0"
);


Back to Index


Get option-chain of mentioned stock-code for product-type Futures where input of expiry-date is not compulsory

breezeConnect.getOptionChainQuotes(
    "ICIBAN","NFO","futures","2022-08-25T06:00:00.000Z"
);


Back to Index

Get option-chain of mentioned stock-code for product-type Options where atleast 2 input is required out of expiry-date, right and strike-price

breezeConnect.getOptionChainQuotes(
    "ICIBAN","NFO","options","2022-08-25T06:00:00.000Z","call","16850"
);


Back to Index


Square off an Equity Margin Order

breezeConnect.squareOff(
    "NSE","margin","NIFTY","10","0","sell","market","day","0","0",
    "","","","",""
);

Note: Please refer get_portfolio_positions() for settlement id and margin_amount


Back to Index

Square off an FNO Futures Order

breezeConnect.squareOff(
    "NFO","futures","ICIBAN","2022-08-25T06:00:00.000Z","sell","market",
    "day","0","50","0","2022-08-12T06:00:00.000Z","","0"
);


Back to Index

Square off an FNO Options Order

breezeConnect.squareOff(
    "NFO","options","ICIBAN","2022-08-25T06:00:00.000Z","Call","16850",
    "sell","market","day","0","50","0","2022-08-12T06:00:00.000Z","","0"
);


Back to Index


Get trade list of your account.

breezeConnect.getTradeList(
    "2022-08-01T06:00:00.000Z","2022-08-19T06:00:00.000Z","NSE",
    "","","");

Note: Please change exchange_code=“NFO” to get details about F&O


Back to Index


Get trade detail of your account.

breezeConnect.getTradeDetail("NSE","20220819N100000005");

Note: Please change exchange_code=“NFO” to get details about F&O


Back to Index


Get Names

breezeConnect.getNames('NSE','TATASTEEL');
breezeConnect.getNames('NSE','RELIANCE');

Note: Use this method to find ICICI specific stock codes / token

Back to Index


Preview Order


breezeConnect.previewOrder("ICIBAN","NSE", "margin","limit","907.05","buy","1","N");

Back to Index