UNPKG

uatbreezeconnect

Version:

UAT version of Breeze Connect API

329 lines (267 loc) 11.9 kB
# UAT Breeze Connect SDK This is a package to integrate streaming of stocks or user's order-notification & call APIs through which you can fetch live/historical data, automate your trading strategies, and monitor your portfolio in real time. ## Setup NodeJS & npm You must download and install Node.js and npm. Please click [here](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) Once installed, You should initiate breeze project environment via npm ``` npm init ``` ## Installing the client You can install the latest release via npm ``` npm install uatbreezeconnect ``` Or, You can also install the specific release version via npm ``` npm i uatbreezeconnect@1.0.9-rc.2 ``` ## Websocket Usage ```javascript var BreezeConnect = require('uatbreezeconnect').BreezeConnect; // Initialize SDK var breeze = new BreezeConnect({ "appKey": "your_api_key"}); // Obtain your session key from https://uatapi.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://uatapi.icicidirect.com/apiuser/login?api_key="+encodeURI("your_api_key")) // Generate Session by Promise method generateSession() and invoking user-defined websocket() inside then() breeze.generateSession({secretKey:"your_secret_key",sessionToken:"your_api_session"}).then(function (resp) { // invoking user-defined method websocket(); }).catch(function (err) { console.log(err) }); // Callback function to receive ticks. function onTicks(ticks){ console.log(ticks); } // User-defined method for websocket with different function to call. function websocket(){ // Connect to websocket breeze.wsConnect() // Assign the callbacks. breeze.onTicks = onTicks; // 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 by stock-token breeze.subscribeFeeds({stockToken:"1.1!500780"}).then( function(resp){ console.log(resp); } ) // unsubscribe 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 stocks feeds by stock-token breeze.unsubscribeFeeds({stockToken:"1.1!500780"}).then( function(resp){ console.log(resp); } ) // subscribe order notification feeds breeze.subscribeFeeds({getOrderNotification:true}).then( function(resp){ console.log(resp); } ) } ``` --- **NOTE** Examples for stock_token are "4.1!38071" or "1.1!500780". 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. --- ## API Usage ```javascript var BreezeConnect = require('uatbreezeconnect').BreezeConnect; // Initialize SDK var breeze = new BreezeConnect({ "appKey": "your_api_key"}); // Obtain your session key from https://uatapi.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://uatapi.icicidirect.com/apiuser/login?api_key="+encodeURI("your_api_key")) // Generate Session by Promise method generateSession() and invoking user-defined apiCalls() inside then() breeze.generateSession({secretKey:"your_secret_key",sessionToken:"your_api_session"}).then(function (resp) { // invoking user-defined method apiCalls(); }).catch(function (err) { console.log(err) }); // Generate ISO8601 Date/DateTime String var date_string = '04 JUL 2022' var iso_date_string = new Date(date_string+" 05:30 +5:30").toISOString(); // '2022-07-04T00:00:00.000Z' var date_time_string = '04 JUL 2022 09:00' var iso_date_time_string = new Date(date_time_string+" +5:30").toISOString(); //'2022-07-04T03:30:00.000Z' // User-defined method for apiCalls with various function to call various APIs. function apiCalls() { // Following are the complete list of API method: // Get Customer details by api-session value. breeze.getCustomerDetails({apiSession:"your_api_session"}).then((resp) => { console.log(resp); }) // Get Demat Holding details of your account. breeze.getDematHoldings().then((resp) => { console.log(resp); }) // Get Funds details of your account. breeze.getFunds().then((resp) => { console.log(resp); }) // 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". breeze.setFunds({transactionType:"debit", amount:"200", segment:"Equity"}).then((resp) => { console.log(resp); }) // Get Historical Data for specific stock-code by mentioned interval either as "minute", "5minute", "30minutes" or as "day". breeze.getHistoricalData({interval:"1minute", fromDate:"2021-11-15T04:00:00.000Z", toDate:"2021-11-17T04:00:00.000Z", stockCode:"AXIBAN", exchangeCode:"NFO", productType:"futures", expiryDate:"2021-11-25T04:00:00.000Z", right:"others", strikePrice:"0"}).then((resp) => { console.log(resp); }) // Add Margin to your account. breeze.addMargin({productType:"margin", stockCode:"TCS", exchangeCode:"BSE", settlementId:"2021220", addAmount:"100", marginAmount:"3817.10", openQuantity:"10", coverQuantity:"0", categoryIndexPerStock:"", expiryDate:"", right:"", contractTag:"", strikePrice:"", segmentCode:""}).then((resp) => { console.log(resp); }) // Get Margin of your account. breeze.getMargin({exchangeCode:"NSE"}).then((resp) => { console.log(resp); }) // Place an order from your account. breeze.placeOrder({stockCode:"AXIBAN", exchangeCode:"NFO", product:"futures", action:"buy", orderType:"limit", stoploss:"0", quantity:"1200", price:"712.00", validity:"day", validityDate:"2021-12-16T05:30:00.000Z", disclosedQuantity:"0", expiryDate:"2021-12-25T05:30:00.000Z", right:"others", strikePrice:"0", userRemark:"Test"}).then((resp) => { console.log(resp); }) // Get an order details by exchange-code and order-id from your account. breeze.getOrderDetail({exchangeCode:"NSE", orderId:"20211116N100000023"}).then((resp) => { console.log(resp); }) // Get order list of your account. breeze.getOrderList({exchangeCode:"NSE", fromDate:"2021-11-01T05:30:00.000Z", toDate:"2021-11-30T05:30:00.000Z"}).then((resp) => { console.log(resp); }) // Cancel an order from your account whose status are not Executed. breeze.cancelOrder({exchangeCode:"NSE", orderId:"20211116N100000022"}).then((resp) => { console.log(resp); }) // Modify an order from your account whose status are not Executed. breeze.modifyOrder({orderId:"202111241100000002", exchangeCode:"NFO", orderType:"limit", stoploss:"0", quantity:"250", price:"290100", validity:"day", disclosedQuantity:"0", validityDate:"2021-12-30T05:30:00.000Z"}).then((resp) => { console.log(resp); }) // Get Portfolio Holdings of your account. breeze.getPortfolioHoldings({exchangeCode:"NFO", fromDate:"2021-11-01T05:30:00.000Z", toDate:"2021-11-30T05:30:00.000Z", stockCode:"", portfolioType:""}).then((resp) => { console.log(resp); }) // Get Portfolio Positions from your account. breeze.getPortfolioPositions().then((resp) => { console.log(resp); }) // Get quotes of mentioned stock-code breeze.getQuotes({stockCode:"AXIBAN", exchangeCode:"NFO", expiryDate:"2021-12-30T05:30:00.000Z", productType:"futures", right:"others", strikePrice:"0"}).then((resp) => { console.log(resp); }) // Sqauare off an order breeze.squareOff({sourceFlag:"", stockCode:"NIFTY", exchangeCode:"NFO", quantity:"50", price:"0", action:"sell", orderType:"market", validity:"day", stoploss:"0", disclosedQuantity:"0", protectionPercentage:"", settlementId:"", marginAmount:"", openQuantity:"", coverQuantity:"", productType:"futures", expiryDate:"2021-12-30T05:30:00.000Z", right:"", strikePrice:"0", validityDate:"2021-12-16T05:30:00.000Z", tradePassword:"", aliasName:""}).then((resp) => { console.log(resp); }) // Get trade list of your account. breeze.getTradeList({fromDate:"2021-09-28T05:30:00.000Z", toDate:"2021-11-15T05:30:00.000Z", exchangeCode:"NSE", productType:"", action:"", stockCode:""}).then((resp) => { console.log(resp); }) // Get trade detail of your account. breeze.getTradeDetail({exchangeCode:"NSE", orderId:"20210928N100000067"}).then((resp) => { console.log(resp); }) } ```