Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testcases added for api and websocket #18

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ module.exports.API = {

candle_data: '/rest/secure/angelbroking/historical/v1/getCandleData',
market_data : '/rest/secure/angelbroking/market/v1/quote',
search_scrip : '/rest/secure/angelbroking/order/v1/searchScrip'
search_scrip : '/rest/secure/angelbroking/order/v1/searchScrip',
get_all_holding : '/rest/secure/angelbroking/portfolio/v1/getAllHolding',
// "api.token": "/session/token",
// "api.token.invalidate": "/session/token",
// "api.token.renew": "/session/refresh_token",
Expand Down
70 changes: 38 additions & 32 deletions example/test.js → example/api_test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
let { SmartAPI, WebSocketClient, WebSocketV2 } = require('../lib');
let { SmartAPI, WebSocketClient, WebSocketV2 } = require("../lib");

let smart_api = new SmartAPI({
api_key: 'smartapi_key', // PROVIDE YOUR API KEY HERE
// OPTIONAL : If user has valid access token and refresh token then it can be directly passed to the constructor
// access_token: "YOUR_ACCESS_TOKEN",
// refresh_token: "YOUR_REFRESH_TOKEN"
api_key: "smartapi_key", // PROVIDE YOUR API KEY HERE
// OPTIONAL : If user has valid access token and refresh token then it can be directly passed to the constructor
// access_token: "YOUR_ACCESS_TOKEN",
// refresh_token: "YOUR_REFRESH_TOKEN"
});

// // If user does not have valid access token and refresh token then use generateSession method
Expand Down Expand Up @@ -60,9 +60,9 @@ let smart_api = new SmartAPI({

// // // return smart_api.getOrderBook();

// smart_api.getOrderBook().then((data)=>{
// console.log(data);
// })
// smart_api.getOrderBook().then((data)=>{
// console.log(data);
// })

// // // return smart_api.getTradeBook();

Expand Down Expand Up @@ -124,27 +124,33 @@ let smart_api = new SmartAPI({
// // // "todate": "2021-02-10 09:20"
// // // })


// Market Data Methods
// smart_api.marketData({
// "mode": "FULL",
// "exchangeTokens": {
// "NSE": [
// "3045"
// ]
// }
// }).then((data) => {
// console.log(JSON.stringify(data, null, 2));
// // console.log(JSON.stringify(data))
// });

// search Scrip Methods
smart_api.searchScrip({
"exchange": "BSE",
"searchscrip":"Titan"
}).then((data)=>{
console.log(data);
})
// Market Data Methods
// smart_api.marketData({
// "mode": "FULL",
// "exchangeTokens": {
// "NSE": [
// "3045"
// ]
// }
// }).then((data) => {
// console.log(JSON.stringify(data, null, 2));
// // console.log(JSON.stringify(data))
// });

// search Scrip Methods
smart_api
.searchScrip({
exchange: "BSE",
searchscrip: "Titan",
})
.then((data) => {
console.log(data);
});

// get all holding method
// smart_api.getAllHolding().then((data)=>{
// console.log(data);
// })
// })
// .then((data) => {
// console.log('PROFILE::', data);
Expand Down Expand Up @@ -240,8 +246,8 @@ let smart_api = new SmartAPI({
// console.log('receiveTick:::::', data);
// }

// setTimeout(() => {
// web_socket.close();
// }, 10000);
// setTimeout(() => {
// web_socket.close();
// }, 10000);
// });
// ########################### Socket V2 Sample Code End Here ###########################
8 changes: 8 additions & 0 deletions lib/smartapi-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,14 @@ var SmartApi = function (params) {
});
};

/**
* Description
* @method getAllHolding
*/
self.getAllHolding = function () {
return get_request('get_all_holding');
};

/**
* Description
* @method ruleList
Expand Down
7 changes: 5 additions & 2 deletions lib/websocket2.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ let WebSocketV2 = function (params) {
let reset;
let open = 1;

let connected = false; // Add a connection status flag

this.connect = function () {
try {
return new Promise((resolve, reject) => {
Expand All @@ -50,7 +52,8 @@ let WebSocketV2 = function (params) {
reset = setInterval(function () {
ws.send('ping');
}, ping_Interval);
resolve();
connected = true;
resolve(connected);
};

ws.onmessage = function (evt) {
Expand Down Expand Up @@ -119,7 +122,7 @@ let WebSocketV2 = function (params) {
exchangeType !== EXCHANGES.nse_cm &&
exchangeType !== EXCHANGES.nse_fo
) {
throw new Error('Invalid Exchange type pased');
throw new Error('Invalid Exchange type passed');
}

if (mode === MODE.Depth) {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "smartapi-javascript",
"version": "1.0.15",
"version": "1.0.16",
"description": "",
"main": "./lib/",
"scripts": {
Expand All @@ -17,6 +17,8 @@
"atob": "^2.1.2",
"axios": "^0.20.0",
"binary-parser": "^2.2.1",
"chai": "^4.3.10",
"mocha": "^10.2.0",
"pako": "^2.1.0",
"public-ip": "^4.0.2",
"querystring": "^0.2.0",
Expand Down
Loading