breezeconnect

1.0.29 • Public • Published

Table Of Content

Breeze API Javascript Client

breezeapi@icicisecurities.com

The official Javascript 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 Documentation

Installing the client

npm install breezeconnect

API Usage

var BreezeConnect = require('breezeconnect').BreezeConnect;

var appKey ="your_api_key";
var appSecret = "your_secret_key";

var breeze = new BreezeConnect({"appKey":appKey});


//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.
console.log("https://api.icicidirect.com/apiuser/login?api_key="+encodeURI("your_api_key"))

//Generate Session
breeze.generateSession(appSecret,"your_api_session").then(function(resp){
    apiCalls();
}).catch(function(err){
    console.log(err)
});

function apiCalls(){
    breeze.getFunds().then(function(resp){
        console.log("Final Response");
        console.log(resp);
        });
}

Websocket Usage

//Connect to websocket(it will connect to rate refresh server)
breeze.wsConnect();

//Callback to receive ticks.
function onTicks(ticks){
    console.log(ticks);
}

//Assign the callbacks
breeze.onTicks = onTicks;


//subscribe stocks feeds by stock-token
breeze.subscribeFeeds({stockToken:"4.1!1594"})
.then(
        function(resp){
            console.log(resp);
        }
)

// subscribe to oneclick strategy stream
breeze.subscribeFeeds({stockToken:"one_click_fno"})
.then(
        function(resp){
            console.log(resp);
        }
)

// unsubscribe to oneclick strategy stream
breeze.unsubscribeFeeds({stockToken:"one_click_fno"})
.then(
        function(resp){
            console.log(resp);
        }
)

// subscribe to i_click_2_gain strategy stream
breeze.subscribeFeeds({stockToken:"i_click_2_gain"})
.then(
        function(resp){
            console.log(resp);
        }
)

// unsubscribe to i_click_2_gain strategy stream
breeze.unsubscribeFeeds({stockToken:"i_click_2_gain"})
.then(
        function(resp){
            console.log(resp);
        }
)


//subscribe stocks feeds
breeze.subscribeFeeds(
    {
        exchangeCode:"NFO", 
        stockCode:"ZEEENT", 
        productType:"options", 
        expiryDate:"31-Mar-2022", 
        strikePrice:"350", 
        right:"Call", 
        getExchangeQuotes:true, 
        getMarketDepth:false
    }
).then(function(resp){console.log(resp)});

//subscribe stocks feeds
breeze.unsubscribeFeeds(
    {
        exchangeCode:"NFO", 
        stockCode:"ZEEENT", 
        productType:"options", 
        expiryDate:"31-Mar-2022", 
        strikePrice:"350", 
        right:"Call", 
        getExchangeQuotes:true, 
        getMarketDepth:false
    }
).then(function(resp){console.log(resp)});


//unsubscribe feeds using stock token
breeze.unsubscribeFeeds({stockToken:"4.1!1594"}).then(
        function(resp){
            console.log(resp);
        }
)

//subscribe to Real Time Streaming OHLCV Data of stocks by stock-token
breeze.subscribeFeeds({stockToken:"1.1!500780", interval:"1second"})
.then(
        function(resp){
            console.log(resp);
        }
)

//subscribe to Real Time Streaming OHLCV Data of stocks
breeze.subscribeFeeds(
    {
        exchangeCode:"NFO", 
        stockCode:"ZEEENT", 
        productType:"options", 
        expiryDate:"31-Mar-2022", 
        strikePrice:"350", 
        right:"Call", 
        getExchangeQuotes:true, 
        getMarketDepth:false,
        interval:"1minute"
    }
).then(function(resp){console.log(resp)});

// unsubscribe from Real Time Streaming OHLCV Data of stocks by stock-token
breeze.unsubscribeFeeds({stockToken:"1.1!500780", interval:"1second"})
.then(
        function(resp){
            console.log(resp);
        }
)

//unsubscribe from Real Time Streaming OHLCV Data of stocks
breeze.unsubscribeFeeds(
    {
        exchangeCode:"NFO", 
        stockCode:"ZEEENT", 
        productType:"options", 
        expiryDate:"31-Mar-2022", 
        strikePrice:"350", 
        right:"Call", 
        getExchangeQuotes:true, 
        getMarketDepth:false,
        interval:"1minute"
    }
).then(function(resp){console.log(resp)});

//subscribe order notification feeds(it will connect to order streaming server)
breeze.subscribeFeeds({getOrderNotification:true}).then(
        function(resp){
            console.log(resp);
        }
)

//unsubscribe order notification feeds(it will disconnect from order streaming server)
breeze.subscribeFeeds({getOrderNotification:true}).then(
        function(resp){
            console.log(resp);
        }
)

//disconnects rate refresh server
breeze.wsDisconnect();

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

exchangeCode 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 exchangeCode '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 exchangeCode '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.

breeze.getCustomerDetails("api session").then((data) => {
    console.log(data);
}).catch((err)=>{
    console.log(err);
});

Back to Index

Get Demat Holding details of your account.

breeze.getDematHoldings().then(function(resp){
    console.log(resp);
});

Back to Index

Get Funds details of your account.

breeze.getFunds().then(function(resp){
    console.log(resp);
});

Back to Index

Set Funds of your account

breeze.setFunds(
    {
        transactionType:"debit",  //"debit", "credit"
        amount:"100",
        segment:"Equity"
    }
)
.then(function(resp){
    console.log(resp);
});

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 Equity

breeze.getHistoricalData(
    {
        interval:"1minute",   //'1minute', '5minute', '30minute','1day'
        fromDate: "2022-08-15T07:00:00.000Z",
        toDate: "2022-08-17T07:00:00.000Z",
        stockCode:"ITC",
        exchangeCode:"NSE",   // 'NSE','BSE','NFO'
        productType:"cash"
    }
)
.then(function(resp){
    console.log(resp);
});

Back to Index

Get Historical Data for Options

breeze.getHistoricalData(
    {
        interval:"1minute",       //'1minute', '5minute', '30minute','1day'
        fromDate: "2022-08-15T07:00:00.000Z",
        toDate: "2022-08-17T07:00:00.000Z",
        stockCode:"CNXBAN",
        exchangeCode:"NFO",      // 'NSE','BSE','NFO'
        productType:"options",   // "futures","options","futureplus","optionplus", 'cash'
        expiryDate:"2022-09-29T07:00:00.000Z",
        right:"call",           // "call","put", "others" 
        strikePrice:"38000"
    }
)
.then((resp)=>{
    console.log(resp);
});

Back to Index

Get Historical Data for Futures

breeze.getHistoricalData(
    {
        interval:"1minute",       //'1minute', '5minute', '30minute','1day'
        fromDate: "2022-08-15T07:00:00.000Z",
        toDate: "2022-08-17T07:00:00.000Z",
        stockCode:"ICIBAN",
        exchangeCode:"NFO",      // 'NSE','BSE','NFO'
        productType:"futures",   // "futures","options","futureplus","optionplus", 'cash'
        expiryDate:"2022-08-25T07:00:00.000Z",
        right:"others",           // "call","put", "others" 
        strikePrice:"0"
    }
)
.then((resp)=>{
    console.log(resp);
});

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 Equity

breeze.getHistoricalDatav2(
    {
        interval:"1minute",   //'1second', '1minute', '5minute', '30minute','1day'
        fromDate: "2022-08-15T07:00:00.000Z",
        toDate: "2022-08-17T07:00:00.000Z",
        stockCode:"ITC",
        exchangeCode:"NSE",   // 'NSE','BSE','NFO','NDX,'MCX'
        productType:"cash"
    }
)
.then(function(resp){
    console.log(resp);
});

Back to Index

Get Historical Data (version 2) for Options

breeze.getHistoricalDatav2(
    {
        interval:"1minute",       //'1second', '1minute', '5minute', '30minute','1day'
        fromDate: "2022-08-15T07:00:00.000Z",
        toDate: "2022-08-17T07:00:00.000Z",
        stockCode:"CNXBAN",
        exchangeCode:"NFO",      // 'NSE','BSE','NFO','NDX,'MCX'
        productType:"options",   // "futures","options",'cash'
        expiryDate:"2022-09-29T07:00:00.000Z",
        right:"call",           // "call","put", "others" 
        strikePrice:"38000"
    }
)
.then((resp)=>{
    console.log(resp);
});

Back to Index

Get Historical Data (version 2) for Futures

breeze.getHistoricalDatav2(
    {
        interval:"1minute",       //'1second', '1minute', '5minute', '30minute','1day'
        fromDate: "2022-08-15T07:00:00.000Z",
        toDate: "2022-08-17T07:00:00.000Z",
        stockCode:"ICIBAN",
        exchangeCode:"NFO",      // 'NSE','BSE','NFO'
        productType:"futures",   // "futures","options","futureplus","optionplus", 'cash'
        expiryDate:"2022-08-25T07:00:00.000Z",
        right:"others",           // "call","put", "others" 
        strikePrice:"0"
    }
)
.then((resp)=>{
    console.log(resp);
});

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.

breeze.addMargin(
    {
        productType:"cash",   //"futures","options","futureplus","optionplus","cash","eatm","margin"
        stockCode:"ITC", 
        exchangeCode:"NSE",    // 'NSE','BSE','NFO'
        settlementId:"2022106", 
        addAmount:"100", 
        marginAmount:"265", 
        openQuantity:"1", 
        coverQuantity:"0", 
        categoryIndexPerStock:"", 
        expiryDate:"", 
        right:"",             //"call", "put", "others"
        contractTag:"", 
        strikePrice:"", 
        segmentCode:"N"
    }
)
.then(function(resp){
    console.log(resp);
})

Back to Index

Get Margin of your account.

breeze.getMargin(exchangeCode='NSE').then(function(resp){
    console.log(resp);
})

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


Back to Index

Placing a Futures Order from your account.

breeze.placeOrder(
    {
        stockCode:"ICIBAN",
        exchangeCode:"NFO",
        product:"futures",
        action:"buy",
        orderType:"limit",
        stoploss:"0",
        quantity:"3200",
        price:"200",
        validity:"day",
        validityDate:"2022-08-22T06:00:00.000Z",
        disclosedQuantity:"0",
        expiryDate:"2022-08-25T06:00:00.000Z",
        right:"others",
        strike_price:"0",
        userRemark:"Test"
    }                
)
.then(function(resp){
    console.log(resp);
})

Back to Index

Placing a btst Order from your account.

breeze.placeOrder(
    {
        stockCode:"ICIBAN",
        exchangeCode:"NFO",
        product:"futures",
        action:"buy",
        orderType:"limit",
        stoploss:"0",
        quantity:"3200",
        price:"200",
        validity:"day",
        validityDate:"2022-08-22T06:00:00.000Z",
        disclosedQuantity:"0",
        expiryDate:"2022-08-25T06:00:00.000Z",
        right:"others",
        strike_price:"0",
        userRemark:"Test",
        settlementId: "2023008",
        orderSegmentCode = "N"
    }                
)
.then(function(resp){
    console.log(resp);
})

Back to Index

Placing an Option Order from your account.

breeze.placeOrder(
    {
        stockCode:"NIFTY",
        exchangeCode:"NFO",
        product:"options",
        action:"buy",
        orderType:"market",
        stoploss:"",
        quantity:"50",
        price:"",
        validity:"day",
        validityDate:"2022-08-30T06:00:00.000Z",
        disclosedQuantity:"0",
        expiryDate:"2022-09-29T06:00:00.000Z",
        right:"call",
        strikePrice:"16600"
    }
)
.then(function(resp){
    console.log(resp);
})

Back to Index

Place a cash order from your account.

breeze.placeOrder(
    {
        stockCode:"ITC",
        exchangeCode:"NSE",
        product:"cash",
        action:"buy",
        orderType:"limit",
        stoploss:"",
        quantity:"1",
        price:"305",
        validity:"day"
    }
)
.then(function(resp){
    console.log(resp);
})

Back to Index

Place an optionplus order

breeze.placeOrder(
    {
        stockCode:"NIFTY",
        exchangeCode:"NFO",
        product:"optionplus",
        action:"buy",
        orderType:"limit",
        stoploss:"15",
        quantity:"50",
        price:"11.25",
        validity:"day",
        validityDate:"2022-12-02T06:00:00.000Z",
        disclosedQuantity:"0",
        expiryDate:"2022-12-08T06:00:00.000Z",
        right:"call",
        strikePrice:"19000",
        orderTypeFresh:"Limit",
        orderRateFresh:"20",
        userRemark:"Test"
    }
)
.then(function(resp){
    console.log(resp);
})

Back to Index

Place an future plus order

breeze.placeOrder(
    {
        stockCode:"NIFTY",
        exchangeCode:"NFO",                                     
        product:"futureplus",                                    
        action: "Buy",                                            
        orderType: "limit",
        stoploss:"18720",                                            
        quantity:"50",                                          
        price: "18725",                                                                             
        validity:"Day",       
        disclosedQuantity:"0",                                  
        expiryDate:"29-DEC-2022"
    }
)
.then(function(resp){
    console.log(resp);
})

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.

breeze.getOrderDetail(
    {
        exchangeCode:"NSE",
        orderId:"20220819N100000001"
    }
)
.then(function(resp){
    console.log(resp);
})

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


Back to Index

Get order list of your account.

breeze.getOrderList(
    {
        exchangeCode:"NSE",
        fromDate:"2022-08-01T10:00:00.000Z",
        toDate:"2022-08-19T10:00:00.000Z"
    }
)
.then(function(resp){
    console.log(resp);
})

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


Back to Index

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

breeze.cancelOrder(
    {
        exchangeCode:"NSE",
        orderId:"20220819N100000001"
    }        
)
.then(function(resp){
    console.log(resp);
})

Back to Index

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

breeze.modifyOrder(
    {
        orderId:"202208191100000001",
        exchangeCode:"NFO",
        orderType:"limit",
        stoploss:"0",
        quantity:"250",
        price:"290100",
        validity:"day",
        disclosedQuantity:"0",
        validityDate:"2022-08-22T06:00:00.000Z"
    }
)
.then(function(resp){
    console.log(resp);
})

Back to Index

Get Portfolio Holdings of your account.

breeze.getPortfolioHoldings(
    {
        exchangeCode:"NFO",
        fromDate:"2022-08-01T06:00:00.000Z",
        toDate:"2022-08-19T06:00:00.000Z",
        stockCode:"",
        portfolioType:""
    }    
)
.then(function(resp){
    console.log(resp);
})

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


Back to Index

Get Portfolio Positions from your account.

breeze.getPortfolioPositions()

Back to Index

Get quotes of mentioned stock-code

breeze.getQuotes(
    {
        stockCode:"ICIBAN",
        exchangeCode:"NFO",
        expiryDate:"2022-08-25T06:00:00.000Z",
        productType:"futures",
        right:"others",
        strikePrice:"0"
    }
)
.then(function(resp){
    console.log(resp);
})

Back to Index

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

breeze.getOptionChainQuotes(
    {
        stockCode:"ICIBAN",
        exchangeCode:"NFO",
        productType:"futures",
        expiryDate:"2022-08-25T06:00:00.000Z"
    }
)
.then(function(resp){
    console.log(resp);
})

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

breeze.getOptionChainQuotes(
    {
        stockCode:"ICIBAN",
        exchangeCode:"NFO",
        productType:"options",
        expiryDate:"2022-08-25T06:00:00.000Z",
        right:"call",
        strikePrice:"16850"
    }
)
.then(function(resp){
    console.log(resp);
})

Back to Index

Square off an Equity Margin Order

breeze.squareOff(
    {
        exchangeCode:"NSE",
        product:"margin",
        stockCode:"NIFTY",
        quantity:"10",
        price:"0",
        action:"sell",
        orderType:"market",
        validity:"day",
        stoploss:"0",
        disclosedQuantity:"0",
        protectionPercentage:"",
        settlementId:"",
        coverQuantity:"",
        openQuantity:"",
        marginAmount:""
    }
)
.then(function(resp){
    console.log(resp);
})

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


Back to Index

Square off an FNO Futures Order

breeze.squareOff(
    {
        exchangeCode:"NFO",
        product:"futures",
        stockCode:"ICIBAN",
        expiryDate:"2022-08-25T06:00:00.000Z",
        action:"sell",
        orderType:"market",
        validity:"day",
        stoploss:"0",
        quantity:"50",
        price:"0",
        validityDate:"2022-08-12T06:00:00.000Z",
        tradePassword:"",
        disclosedQuantity:"0"
    }
)
.then(function(resp){
    console.log(resp);
})

Back to Index

Square off an FNO Options Order

breeze.squareOff(
    {
        exchangeCode:"NFO",
        product:"options",
        stockCode:"ICIBAN",
        expiryDate:"2022-08-25T06:00:00.000Z",
        right:"Call",
        strikePrice:"16850",
        action:"sell",
        orderType:"market",
        validity:"day",
        stoploss:"0",
        quantity:"50",
        price:"0",
        validityDate:"2022-08-12T06:00:00.000Z",
        tradePassword:"",
        disclosedQuantity:"0"
    }
)
.then(function(resp){
    console.log(resp);
})

Back to Index

Get trade list of your account.

breeze.getTradeList(
    {
        fromDate:"2022-08-01T06:00:00.000Z",
        toDate:"2022-08-19T06:00:00.000Z",
        exchangeCode:"NSE",
        productType:"",
        action:"",
        stockCode:""
    }
)
.then(function(resp){
    console.log(resp);
})

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


Back to Index

Get trade detail of your account.

breeze.getTradeDetail(
    {
        exchangeCode:"NSE",
        orderId:"20220819N100000005"
    }
)
.then(function(resp){
    console.log(resp);
})

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


Back to Index

Get Names

breeze.getNames({exchangeCode :'NSE',stockCode : 'TATASTEEL'})
.then(function(resp){
    console.log(resp);
})

breeze.getNames({exchangeCode : 'NSE',stockCode : 'RELIANCE'})
.then(function(resp){
    console.log(resp);
})

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

Back to Index


Preview Order

    breeze.previewOrder(
        {
        stockCode : "ICIBAN",
        exchangeCode : "NSE",
        productType : "margin",
        orderType  : "limit",
        price : "907.05",
        action :"buy",
        quantity : "1",
        specialFlag : "N"
        }
        ).then(function(resp){
        console.log(resp);
        }).catch((err)=>{
            console.log(err);
        })

Back to Index


Limit Calculator

breeze.limitCalculator(strikePrice = "19200",                                    
    productType = "optionplus",                 
    expiryDate  = "06-JUL-2023",
    underlying = "NIFTY",
    exchangeCode = "NFO",
    orderFlow = "Buy",
    stopLossTrigger = "200.00",
    optionType = "Call",
    sourceFlag = "P",
    limitRate = "",
    orderReference = "",
    availableQuantity = "",
    marketType = "limit",
    freshOrderLimit = "177.70")

Back to Index


margin calculator

    breeze.marginCalculator([{
            "strike_price": "0",
            "quantity": "15",
            "right": "others",
            "product": "futures",
            "action": "buy",
            "price": "46230.85",
            "expiry_date": "31-Aug-2023",
            "stock_code": "CNXBAN",
            "cover_order_flow": "N",
            "fresh_order_type": "N",
            "cover_limit_rate": "0",
            "cover_sltp_price": "0",
            "fresh_limit_rate": "0",
            "open_quantity": "0"
        },
        {
            "strike_price": "37000",
            "quantity": "15",
            "right": "Call",
            "product": "options",
            "action": "buy",
            "price": "9100",
            "expiry_date": "27-Jul-2023",
            "stock_code": "CNXBAN",
            "cover_order_flow": "N",
            "fresh_order_type": "N",
            "cover_limit_rate": "0",
            "cover_sltp_price": "0",
            "fresh_limit_rate": "0",
            "open_quantity": "0"
        },
        {
            "strike_price": "0",
            "quantity": "50",
            "right": "others",
            "product": "futureplus",
            "action": "buy",
            "price": "19800",
            "expiry_date": "27-Jul-2023",
            "stock_code": "NIFTY",
            "cover_order_flow": "N",
            "fresh_order_type": "N",
            "cover_limit_rate": "0",
            "cover_sltp_price": "0",
            "fresh_limit_rate": "0",
            "open_quantity": "0"
        },
        {
            "strike_price": "19600",
            "quantity": "50",
            "right": "call",
            "product": "optionplus",
            "action": "buy",
            "price": "245.05",
            "expiry_date": "27-Jul-2023",
            "stock_code": "NIFTY",
            "cover_order_flow": "sell",
            "fresh_order_type": "limit",
            "cover_limit_rate": "180.00",
            "cover_sltp_price": "200.00",
            "fresh_limit_rate": "245.05",
            "open_quantity": "50"
        }],exchangeCode = "NFO")

Package Sidebar

Install

npm i breezeconnect

Weekly Downloads

9

Version

1.0.29

License

none

Unpacked Size

131 kB

Total Files

4

Last publish

Collaborators

  • icicidirect