From ff09989c03a63c10ce4c40baa874d977fe404240 Mon Sep 17 00:00:00 2001 From: Amol Date: Mon, 9 Oct 2023 10:16:42 +0530 Subject: [PATCH 1/7] package updated --- example/test.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/example/test.js b/example/test.js index 13effe8..721e4ec 100644 --- a/example/test.js +++ b/example/test.js @@ -139,12 +139,12 @@ let smart_api = new SmartAPI({ // }); // search Scrip Methods - smart_api.searchScrip({ - "exchange": "BSE", - "searchscrip":"Titan" - }).then((data)=>{ - console.log(data); - }) + // smart_api.searchScrip({ + // "exchange": "BSE", + // "searchscrip":"Titan" + // }).then((data)=>{ + // console.log(data); + // }) // }) // .then((data) => { // console.log('PROFILE::', data); diff --git a/package.json b/package.json index 0e13623..2ae93cd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "smartapi-javascript", - "version": "1.0.15", + "version": "1.0.16", "description": "", "main": "./lib/", "scripts": { From e057e66ae0b262738e9e46efb1ee1a537ead25ee Mon Sep 17 00:00:00 2001 From: Amol Date: Fri, 13 Oct 2023 13:03:04 +0530 Subject: [PATCH 2/7] getAllHolding api added --- config/api.js | 3 ++- example/test.js | 17 +++++++++++------ lib/smartapi-connect.js | 8 ++++++++ lib/websocket2.0.js | 2 +- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/config/api.js b/config/api.js index 3d589cd..e207cb8 100644 --- a/config/api.js +++ b/config/api.js @@ -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", diff --git a/example/test.js b/example/test.js index 721e4ec..4488436 100644 --- a/example/test.js +++ b/example/test.js @@ -139,12 +139,17 @@ let smart_api = new SmartAPI({ // }); // search Scrip Methods - // smart_api.searchScrip({ - // "exchange": "BSE", - // "searchscrip":"Titan" - // }).then((data)=>{ - // console.log(data); - // }) + 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); diff --git a/lib/smartapi-connect.js b/lib/smartapi-connect.js index e70f8d9..2f15c71 100644 --- a/lib/smartapi-connect.js +++ b/lib/smartapi-connect.js @@ -467,6 +467,14 @@ var SmartApi = function (params) { }); }; + /** + * Description + * @method getAllHolding + */ + self.getAllHolding = function () { + return get_request('get_all_holding'); + }; + /** * Description * @method ruleList diff --git a/lib/websocket2.0.js b/lib/websocket2.0.js index 8e19ba9..a7a7a2c 100644 --- a/lib/websocket2.0.js +++ b/lib/websocket2.0.js @@ -119,7 +119,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) { From 3faad98fe7ebf8afa6239cd6d754330e8ad9cdfc Mon Sep 17 00:00:00 2001 From: Amol Date: Mon, 16 Oct 2023 17:36:43 +0530 Subject: [PATCH 3/7] testcases --- example/test.js | 33 +++--- package.json | 2 + test/test.js | 259 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 281 insertions(+), 13 deletions(-) create mode 100644 test/test.js diff --git a/example/test.js b/example/test.js index 4488436..0c5688e 100644 --- a/example/test.js +++ b/example/test.js @@ -1,17 +1,17 @@ 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: "", // 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: 'eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI6IkE1MjE2MzEzNCIsInJvbGVzIjowLCJ1c2VydHlwZSI6IlVTRVIiLCJ0b2tlbiI6ImV5SmhiR2NpT2lKSVV6VXhNaUlzSW5SNWNDSTZJa3BYVkNKOS5leUp6ZFdJaU9pSkJOVEl4TmpNeE16UWlMQ0psZUhBaU9qRTJPVGMxTXpFeE16QXNJbWxoZENJNk1UWTVOelF6TWpjMU5pd2lhblJwSWpvaU9Ea3pZMlUxWldVdFltRTNOQzAwT1RRd0xXRmhabUV0TnpJeVpHUmxPVFprWXpSbUlpd2liMjF1WlcxaGJtRm5aWEpwWkNJNk9Dd2ljMjkxY21ObGFXUWlPaUl6SWl3aWRYTmxjbDkwZVhCbElqb2lZMnhwWlc1MElpd2lkRzlyWlc1ZmRIbHdaU0k2SW5SeVlXUmxYMkZqWTJWemMxOTBiMnRsYmlJc0ltZHRYMmxrSWpvNExDSnpiM1Z5WTJVaU9pSXpJbjAuRzlxSnl1ZmxxVTdkM1JNckhGRzRkdXVaV3FJSHZPLTBmRkxpQmFCR0V1bm5SeDFsMWt0QktZWlpwczY2RzBNWVFwOXIxdWlWa0V6R05fZkctVWlJZXciLCJBUEktS0VZIjoiVkcyczM0Q3EiLCJpYXQiOjE2OTc0MzI4MTYsImV4cCI6MTY5NzUzMTEzMH0.cNBTyw40c0eW_ZyXi4Dh4ZZ5MVDykbWrsEXaBzercNl2JjNwD0hpU5I_7Y42uDsCP6StZX-MfMU6yNw5BSrNTg', + refresh_token: 'eyJhbGciOiJIUzUxMiJ9.eyJ0b2tlbiI6IlJFRlJFU0gtVE9LRU4iLCJSRUZSRVNILVRPS0VOIjoiZXlKaGJHY2lPaUpJVXpVeE1pSXNJblI1Y0NJNklrcFhWQ0o5LmV5SnpkV0lpT2lKQk5USXhOak14TXpRaUxDSmxlSEFpT2pFMk9UYzBOell3TVRZc0ltbGhkQ0k2TVRZNU56UXpNamMxTml3aWFuUnBJam9pWVdKbU5tVmhNMll0TnprelpDMDBObU0xTFRneFlUVXRZMlUxT1Rjell6azVOV1V6SWl3aWRHOXJaVzRpT2lKU1JVWlNSVk5JTFZSUFMwVk9JaXdpZFhObGNsOTBlWEJsSWpvaVkyeHBaVzUwSWl3aWRHOXJaVzVmZEhsd1pTSTZJblJ5WVdSbFgzSmxabkpsYzJoZmRHOXJaVzRpZlEuTTRYb1dkTHVnS043YnJFSW1TZXMwc190X29DNTF1amdmc1NmbUFpOU5SRTVkYXNBUDVTUWhkejN1VHdEaGtyakVDWXZxTHFhTTBiMzBYN3BHMnNaX1EiLCJpYXQiOjE2OTc0MzI4MTZ9.wiFmh17e52K7YZbWaX4JD949RRDVd3C76gZ7C3RBpmygIN164jbpC0N1tHEWn_QLh4Fk8bQfAeSGRT1pTjxJag', }); // // If user does not have valid access token and refresh token then use generateSession method // } // smart_api -// .generateSession('CLIENT_CODE', 'PASSWORD', 'TOTP') +// .generateSession('A52163134', '4321', '919073') // .then((data) => { // console.log(data); // return smart_api.getProfile(); @@ -64,10 +64,17 @@ let smart_api = new SmartAPI({ // console.log(data); // }) -// // // return smart_api.getTradeBook(); + // return smart_api.getTradeBook(); // // // Portfolio Methods -// // // return smart_api.getHolding(); + smart_api + .getHolding() + .then((data) => { + console.log("Success: ", data); + }) + .catch((err) => { + console.log("Error:", err); + }); // // // return smart_api.getPosition(); @@ -139,12 +146,12 @@ let smart_api = new SmartAPI({ // }); // search Scrip Methods - smart_api.searchScrip({ - "exchange": "BSE", - "searchscrip":"Titan" - }).then((data)=>{ - console.log(data); - }) + // smart_api.searchScrip({ + // "exchange": "BSE", + // "searchscrip":"Titan" + // }).then((data)=>{ + // console.log(data); + // }) // get all holding method // smart_api.getAllHolding().then((data)=>{ diff --git a/package.json b/package.json index 2ae93cd..4069815 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000..c24dc13 --- /dev/null +++ b/test/test.js @@ -0,0 +1,259 @@ +let { SmartAPI, WebSocketClient, WebSocketV2 } = require("../lib"); +var chai = require("chai"); +var expect = chai.expect; + +let smart_api = new SmartAPI({ + api_key: "VG2s34Cq", + // OPTIONAL : If user has valid access token and refresh token then it can be directly passed to the constructor + access_token: + "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI6IkE1MjE2MzEzNCIsInJvbGVzIjowLCJ1c2VydHlwZSI6IlVTRVIiLCJ0b2tlbiI6ImV5SmhiR2NpT2lKSVV6VXhNaUlzSW5SNWNDSTZJa3BYVkNKOS5leUp6ZFdJaU9pSkJOVEl4TmpNeE16UWlMQ0psZUhBaU9qRTJPVGMxTXpFeE16QXNJbWxoZENJNk1UWTVOelF6TWpjMU5pd2lhblJwSWpvaU9Ea3pZMlUxWldVdFltRTNOQzAwT1RRd0xXRmhabUV0TnpJeVpHUmxPVFprWXpSbUlpd2liMjF1WlcxaGJtRm5aWEpwWkNJNk9Dd2ljMjkxY21ObGFXUWlPaUl6SWl3aWRYTmxjbDkwZVhCbElqb2lZMnhwWlc1MElpd2lkRzlyWlc1ZmRIbHdaU0k2SW5SeVlXUmxYMkZqWTJWemMxOTBiMnRsYmlJc0ltZHRYMmxrSWpvNExDSnpiM1Z5WTJVaU9pSXpJbjAuRzlxSnl1ZmxxVTdkM1JNckhGRzRkdXVaV3FJSHZPLTBmRkxpQmFCR0V1bm5SeDFsMWt0QktZWlpwczY2RzBNWVFwOXIxdWlWa0V6R05fZkctVWlJZXciLCJBUEktS0VZIjoiVkcyczM0Q3EiLCJpYXQiOjE2OTc0MzI4MTYsImV4cCI6MTY5NzUzMTEzMH0.cNBTyw40c0eW_ZyXi4Dh4ZZ5MVDykbWrsEXaBzercNl2JjNwD0hpU5I_7Y42uDsCP6StZX-MfMU6yNw5BSrNTg", + refresh_token: + "eyJhbGciOiJIUzUxMiJ9.eyJ0b2tlbiI6IlJFRlJFU0gtVE9LRU4iLCJSRUZSRVNILVRPS0VOIjoiZXlKaGJHY2lPaUpJVXpVeE1pSXNJblI1Y0NJNklrcFhWQ0o5LmV5SnpkV0lpT2lKQk5USXhOak14TXpRaUxDSmxlSEFpT2pFMk9UYzBOell3TVRZc0ltbGhkQ0k2TVRZNU56UXpNamMxTml3aWFuUnBJam9pWVdKbU5tVmhNMll0TnprelpDMDBObU0xTFRneFlUVXRZMlUxT1Rjell6azVOV1V6SWl3aWRHOXJaVzRpT2lKU1JVWlNSVk5JTFZSUFMwVk9JaXdpZFhObGNsOTBlWEJsSWpvaVkyeHBaVzUwSWl3aWRHOXJaVzVmZEhsd1pTSTZJblJ5WVdSbFgzSmxabkpsYzJoZmRHOXJaVzRpZlEuTTRYb1dkTHVnS043YnJFSW1TZXMwc190X29DNTF1amdmc1NmbUFpOU5SRTVkYXNBUDVTUWhkejN1VHdEaGtyakVDWXZxTHFhTTBiMzBYN3BHMnNaX1EiLCJpYXQiOjE2OTc0MzI4MTZ9.wiFmh17e52K7YZbWaX4JD949RRDVd3C76gZ7C3RBpmygIN164jbpC0N1tHEWn_QLh4Fk8bQfAeSGRT1pTjxJag", +}); + +// generateSession api +// describe("generateSession", function () { +// let res; +// before(async function () { +// res = await smart_api.generateSession("A52163134", "4321", "378315"); +// if (res.status) { +// const { jwtToken, refreshToken } = res.data; + +// // Directly assign tokens if accessible +// smart_api.access_token = jwtToken; +// smart_api.refresh_token = refreshToken; +// } +// }); + +// it("Generate session successful", function () { +// if (res.status) { +// expect(res).to.have.property("status", true); +// expect(res).to.have.property("message", "SUCCESS"); +// expect(res).to.have.property("errorcode", ""); +// expect(res).to.have.property("data"); +// } +// }); + +// it("Generate session failed", function () { +// if (res.status === false) { +// expect(res).to.have.property("status", false); +// expect(res).to.have.property("message"); +// expect(res).to.have.property("errorcode"); +// expect(res).to.have.property("data", null); +// } +// }); +// }); + +// getProfile api +describe("getProfile", function () { + let res; + before(async function () { + res = await smart_api.getProfile(); + }); + + it("Get Profile successful", function () { + if (res.status) { + expect(res).to.have.property("status", true); + expect(res).to.have.property("message", "SUCCESS"); + expect(res).to.have.property("errorcode", ""); + expect(res).to.have.property("data"); + } + }); + + it("Get Profile failed", function () { + if (res.success === false) { + expect(res).to.have.property("success", false); + expect(res).to.have.property("message"); + expect(res).to.have.property("errorCode"); + expect(res).to.have.property("data"); + } + }); +}); + +// placeOrder api +describe("placeOrder", function () { + let res; + before(async function () { + res = await smart_api.placeOrder({ + variety: "NORMAL", + tradingsymbol: "SBIN-EQ", + symboltoken: "3045", + transactiontype: "BUY", + exchange: "NSE", + ordertype: "LIMIT", + producttype: "INTRADAY", + duration: "DAY", + price: "19500", + squareoff: "0", + stoploss: "0", + quantity: "1", + }); + }); + + it("Place Order successful", function () { + if (res.status) { + expect(res).to.have.property("status", true); + expect(res).to.have.property("message", "SUCCESS"); + expect(res).to.have.property("errorcode", ""); + expect(res).to.have.property("data"); + } + }); + + it("Place order failed", function () { + if (res.status === false) { + expect(res).to.have.property("status", false); + expect(res).to.have.property("message"); + expect(res).to.have.property("errorcode"); + expect(res).to.have.property("data", null); + } + }); +}); + +// modifyOrder api +describe("modifyOrder", function () { + let res; + before(async function () { + res = await smart_api.modifyOrder({ + orderid: "231016000616769", + variety: "NORMAL", + tradingsymbol: "SBIN-EQ", + symboltoken: "3045", + transactiontype: "BUY", + exchange: "NSE", + ordertype: "LIMIT", + producttype: "INTRADAY", + duration: "DAY", + price: "19500", + squareoff: "0", + stoploss: "0", + quantity: "2", + }); + }); + + it("Modify Order successful", function () { + if (res.status) { + expect(res).to.have.property("status", true); + expect(res).to.have.property("message", "SUCCESS"); + expect(res).to.have.property("errorcode", ""); + expect(res).to.have.property("data"); + } + }); + + it("Modify order failed", function () { + if (res.status === false) { + expect(res).to.have.property("status", false); + expect(res).to.have.property("message"); + expect(res).to.have.property("errorcode"); + expect(res).to.have.property("data", null); + } + }); +}); + +// cancelOrder api +describe("cancelOrder", function () { + let res; + before(async function () { + res = await smart_api.cancelOrder({ + variety: "NORMAL", + orderid: "231016000616769", + }); + }); + + it("Cancel Order successful", function () { + if (res.status) { + expect(res).to.have.property("status", true); + expect(res).to.have.property("message", "SUCCESS"); + expect(res).to.have.property("errorcode", ""); + expect(res).to.have.property("data"); + } + }); + + it("Cancel order failed", function () { + if (res.status === false) { + expect(res).to.have.property("status", false); + expect(res).to.have.property("message"); + expect(res).to.have.property("errorcode"); + expect(res).to.have.property("data", null); + } + }); +}); + +// getOrderBook api +describe("getOrderBook", function () { + let res; + before(async function () { + res = await smart_api.getOrderBook(); + }); + + it("Get order book successful", function () { + if (res.status) { + expect(res).to.have.property("status", true); + expect(res).to.have.property("message", "SUCCESS"); + expect(res).to.have.property("errorcode", ""); + expect(res).to.have.property("data"); + } + }); + + it("Get order book failed", function () { + if (res.status === false) { + expect(res).to.have.property("status", false); + expect(res).to.have.property("message"); + expect(res).to.have.property("errorcode"); + expect(res).to.have.property("data", null); + } + }); +}); + +// getTradeBook api +describe("getTradeBook", function () { + let res; + before(async function () { + res = await smart_api.getTradeBook(); + }); + + it("Get trade book successful", function () { + if (res.status) { + expect(res).to.have.property("status", true); + expect(res).to.have.property("message", "SUCCESS"); + expect(res).to.have.property("errorcode", ""); + expect(res).to.have.property("data"); + } + }); + + it("Get trade book failed", function () { + if (res.status === false) { + expect(res).to.have.property("status", false); + expect(res).to.have.property("message"); + expect(res).to.have.property("errorcode"); + expect(res).to.have.property("data"); + } + }); +}); + +// getHolding api +describe("getHolding", function () { + let res; + before(async function () { + res = await smart_api.getHolding(); + }); + + it("Get holding successful", function () { + if (res.status) { + expect(res).to.have.property("status", true); + expect(res).to.have.property("message", "SUCCESS"); + expect(res).to.have.property("errorcode", ""); + expect(res).to.have.property("data"); + } + }); + + it("Get holding failed", function () { + if (res.status === false) { + expect(res).to.have.property("status", false); + expect(res).to.have.property("message"); + expect(res).to.have.property("errorcode"); + expect(res).to.have.property("data"); + } + }); +}); + + From 730acca0430222574ca36d9d1ab07f26ef4942b0 Mon Sep 17 00:00:00 2001 From: Amol Date: Wed, 18 Oct 2023 10:19:03 +0530 Subject: [PATCH 4/7] testcases added --- example/test.js | 224 ++++++++++++++++++++------------- test/test.js | 324 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 457 insertions(+), 91 deletions(-) diff --git a/example/test.js b/example/test.js index 0c5688e..ffdf8a2 100644 --- a/example/test.js +++ b/example/test.js @@ -1,17 +1,17 @@ let { SmartAPI, WebSocketClient, WebSocketV2 } = require('../lib'); let smart_api = new SmartAPI({ - api_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: 'eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI6IkE1MjE2MzEzNCIsInJvbGVzIjowLCJ1c2VydHlwZSI6IlVTRVIiLCJ0b2tlbiI6ImV5SmhiR2NpT2lKSVV6VXhNaUlzSW5SNWNDSTZJa3BYVkNKOS5leUp6ZFdJaU9pSkJOVEl4TmpNeE16UWlMQ0psZUhBaU9qRTJPVGMxTXpFeE16QXNJbWxoZENJNk1UWTVOelF6TWpjMU5pd2lhblJwSWpvaU9Ea3pZMlUxWldVdFltRTNOQzAwT1RRd0xXRmhabUV0TnpJeVpHUmxPVFprWXpSbUlpd2liMjF1WlcxaGJtRm5aWEpwWkNJNk9Dd2ljMjkxY21ObGFXUWlPaUl6SWl3aWRYTmxjbDkwZVhCbElqb2lZMnhwWlc1MElpd2lkRzlyWlc1ZmRIbHdaU0k2SW5SeVlXUmxYMkZqWTJWemMxOTBiMnRsYmlJc0ltZHRYMmxrSWpvNExDSnpiM1Z5WTJVaU9pSXpJbjAuRzlxSnl1ZmxxVTdkM1JNckhGRzRkdXVaV3FJSHZPLTBmRkxpQmFCR0V1bm5SeDFsMWt0QktZWlpwczY2RzBNWVFwOXIxdWlWa0V6R05fZkctVWlJZXciLCJBUEktS0VZIjoiVkcyczM0Q3EiLCJpYXQiOjE2OTc0MzI4MTYsImV4cCI6MTY5NzUzMTEzMH0.cNBTyw40c0eW_ZyXi4Dh4ZZ5MVDykbWrsEXaBzercNl2JjNwD0hpU5I_7Y42uDsCP6StZX-MfMU6yNw5BSrNTg', - refresh_token: 'eyJhbGciOiJIUzUxMiJ9.eyJ0b2tlbiI6IlJFRlJFU0gtVE9LRU4iLCJSRUZSRVNILVRPS0VOIjoiZXlKaGJHY2lPaUpJVXpVeE1pSXNJblI1Y0NJNklrcFhWQ0o5LmV5SnpkV0lpT2lKQk5USXhOak14TXpRaUxDSmxlSEFpT2pFMk9UYzBOell3TVRZc0ltbGhkQ0k2TVRZNU56UXpNamMxTml3aWFuUnBJam9pWVdKbU5tVmhNMll0TnprelpDMDBObU0xTFRneFlUVXRZMlUxT1Rjell6azVOV1V6SWl3aWRHOXJaVzRpT2lKU1JVWlNSVk5JTFZSUFMwVk9JaXdpZFhObGNsOTBlWEJsSWpvaVkyeHBaVzUwSWl3aWRHOXJaVzVmZEhsd1pTSTZJblJ5WVdSbFgzSmxabkpsYzJoZmRHOXJaVzRpZlEuTTRYb1dkTHVnS043YnJFSW1TZXMwc190X29DNTF1amdmc1NmbUFpOU5SRTVkYXNBUDVTUWhkejN1VHdEaGtyakVDWXZxTHFhTTBiMzBYN3BHMnNaX1EiLCJpYXQiOjE2OTc0MzI4MTZ9.wiFmh17e52K7YZbWaX4JD949RRDVd3C76gZ7C3RBpmygIN164jbpC0N1tHEWn_QLh4Fk8bQfAeSGRT1pTjxJag', + api_key: "VG2s34Cq", // 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: 'eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI6IkE1MjE2MzEzNCIs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1ltTXpZalprSWl3aWRHOXJaVzRpT2lKU1JVWlNSVk5JTFZSUFMwVk9JaXdpZFhObGNsOTBlWEJsSWpvaVkyeHBaVzUwSWl3aWRHOXJaVzVmZEhsd1pTSTZJblJ5WVdSbFgzSmxabkpsYzJoZmRHOXJaVzRpZlEuNUk5X1I4RHV6NDd6bDE4X0FaOVpaS0VkLWxqRVVRWnEwU3hSSHVaWVB1OEdfbV9VbFd5em11WEdCSi1rSVhZZE1NOFRNWkltSzZKYng5WHZmSmNndVEiLCJpYXQiOjE2OTc1MTc3NDR9.nRzIcjFpKJ9j_xJhKEkzQw5-TFyVK4gwmtYvzoSt5q-5I8CBv8XebNMEDgwwVg25pE8QuIU3qWGfIw8HB70Jww', }); // // If user does not have valid access token and refresh token then use generateSession method // } // smart_api -// .generateSession('A52163134', '4321', '919073') +// .generateSession('A52163134', '4321', '123295') // .then((data) => { // console.log(data); // return smart_api.getProfile(); @@ -60,23 +60,28 @@ 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(); +// return smart_api.getTradeBook(); // // // Portfolio Methods - smart_api - .getHolding() - .then((data) => { - console.log("Success: ", data); - }) - .catch((err) => { - console.log("Error:", err); - }); +// smart_api +// .getHolding() +// .then((data) => { +// console.log("Success: ", data); +// }) +// .catch((err) => { +// console.log("Error:", err); +// }); -// // // return smart_api.getPosition(); +// smart_api.getPosition().then((data) => { +// console.log("Success: ", data); +// }) +// .catch((err) => { +// console.log("Error:", err); +// }); // // // return smart_api.convertPosition({ // // // "exchange": "NSE", @@ -89,74 +94,115 @@ let smart_api = new SmartAPI({ // // // }); // // // GTT Methods -// // // return smart_api.createRule({ -// // // "tradingsymbol" : "SBIN-EQ", -// // // "symboltoken" : "3045", -// // // "exchange" : "NSE", -// // // "producttype" : "MARGIN", -// // // "transactiontype" : "BUY", -// // // "price" : 100000, -// // // "qty" : 10, -// // // "disclosedqty": 10, -// // // "triggerprice" : 200000, -// // // "timeperiod" : 365 -// // // }) -// // // return smart_api.modifyRule({ -// // // "id" : 1000014, -// // // "symboltoken" : "3045", -// // // "exchange" : "NSE", -// // // "qty" : 10 - -// // // }) -// // // return smart_api.cancelRule({ -// // // "id" : 1000014, -// // // "symboltoken" : "3045", -// // // "exchange" : "NSE" -// // // }) -// // // return smart_api.ruleDetails({ -// // // "id" : 25 -// // // }) -// // // return smart_api.ruleList({ -// // // "status" : ["NEW","CANCELLED"], -// // // "page" : 1, -// // // "count" : 10 -// // // }) - -// // // Historical Methods -// // // return smart_api.getCandleData({ -// // // "exchange": "NSE", -// // // "symboltoken": "3045", -// // // "interval": "ONE_MINUTE", -// // // "fromdate": "2021-02-10 09:00", -// // // "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); - // }) - - // get all holding method - // smart_api.getAllHolding().then((data)=>{ - // console.log(data); - // }) + // smart_api + // .createRule({ + // tradingsymbol: "SBIN-EQ", + // symboltoken: "3045", + // exchange: "NSE", + // producttype: "MARGIN", + // transactiontype: "BUY", + // price: 100000, + // qty: 10, + // disclosedqty: 10, + // triggerprice: 200000, + // timeperiod: 365, + // }) + // .then((data) => { + // console.log("Success cancel: ", data); + // }) + // .catch((err) => { + // console.log("Error:", err); + // }); +// smart_api +// .modifyRule({ +// id: 1440101, +// symboltoken: "3045", +// exchange: "NSE", +// qty: 10, +// }) +// .then((data) => { +// console.log("Success modify: ", data); +// }) +// .catch((err) => { +// console.log("Error:", err); +// }); +// smart_api +// .cancelRule({ +// id: 1440101, +// symboltoken: "3045", +// exchange: "NSE", +// }) +// .then((data) => { +// console.log("Success cancel: ", data); +// }) +// .catch((err) => { +// console.log("Error:", err); +// }); +// smart_api +// .ruleDetails({ +// id: 1440395, +// }) +// .then((data) => { +// console.log("Success cancel: ", data); +// }) +// .catch((err) => { +// console.log("Error:", err); +// }); + // smart_api + // .ruleList({ + // status: ["NEW", "CANCELLED"], + // page: 1, + // count: 10, + // }) + // .then((data) => { + // console.log("Success cancel: ", data); + // }) + // .catch((err) => { + // console.log("Error:", err); + // }); + + //Historical Methods + // smart_api + // .getCandleData({ + // exchange: "NSE", + // symboltoken: "3045", + // interval: "ONE_MINUTE", + // fromdate: "2021-02-10 09:00", + // todate: "2021-02-10 09:20", + // }) + // .then((data) => { + // console.log("Success cancel: ", data); + // }) + // .catch((err) => { + // console.log("Error:", err); + // }); + + +// 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); @@ -252,8 +298,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 ########################### diff --git a/test/test.js b/test/test.js index c24dc13..c67d42c 100644 --- a/test/test.js +++ b/test/test.js @@ -6,9 +6,9 @@ let smart_api = new SmartAPI({ api_key: "VG2s34Cq", // OPTIONAL : If user has valid access token and refresh token then it can be directly passed to the constructor access_token: - "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI6IkE1MjE2MzEzNCIsInJvbGVzIjowLCJ1c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X1EiLCJpYXQiOjE2OTc0MzI4MTZ9.wiFmh17e52K7YZbWaX4JD949RRDVd3C76gZ7C3RBpmygIN164jbpC0N1tHEWn_QLh4Fk8bQfAeSGRT1pTjxJag", + "eyJhbGciOiJIUzUxMiJ9.eyJ0b2tlbiI6IlJFRlJFU0gtVE9LRU4iLCJSRUZSRVNILVRPS0VOIjoiZXlKaGJHY2lPaUpJVXpVeE1pSXNJblI1Y0NJNklrcFhWQ0o5LmV5SnpkV0lpT2lKQk5USXhOak14TXpRaUxDSmxlSEFpT2pFMk9UYzFOakE1TkRRc0ltbGhkQ0k2TVRZNU56VXhOelk0TkN3aWFuUnBJam9pTVRRMU5qTmpNR1l0TUdSa01TMDBORE0wTFRrek9XTXRPRFl6TVRSa1ltTXpZalprSWl3aWRHOXJaVzRpT2lKU1JVWlNSVk5JTFZSUFMwVk9JaXdpZFhObGNsOTBlWEJsSWpvaVkyeHBaVzUwSWl3aWRHOXJaVzVmZEhsd1pTSTZJblJ5WVdSbFgzSmxabkpsYzJoZmRHOXJaVzRpZlEuNUk5X1I4RHV6NDd6bDE4X0FaOVpaS0VkLWxqRVVRWnEwU3hSSHVaWVB1OEdfbV9VbFd5em11WEdCSi1rSVhZZE1NOFRNWkltSzZKYng5WHZmSmNndVEiLCJpYXQiOjE2OTc1MTc3NDR9.nRzIcjFpKJ9j_xJhKEkzQw5-TFyVK4gwmtYvzoSt5q-5I8CBv8XebNMEDgwwVg25pE8QuIU3qWGfIw8HB70Jww", }); // generateSession api @@ -70,6 +70,32 @@ describe("getProfile", function () { }); }); +// getRMS +describe("getRMS", function () { + let res; + before(async function () { + res = await smart_api.getRMS(); + }); + + it("Get RMS successful", function () { + if (res.status) { + expect(res).to.have.property("status", true); + expect(res).to.have.property("message", "SUCCESS"); + expect(res).to.have.property("errorcode", ""); + expect(res).to.have.property("data"); + } + }); + + it("Get RMS failed", function () { + if (res.success === false) { + expect(res).to.have.property("success", false); + expect(res).to.have.property("message"); + expect(res).to.have.property("errorCode"); + expect(res).to.have.property("data"); + } + }); +}); + // placeOrder api describe("placeOrder", function () { let res; @@ -256,4 +282,298 @@ describe("getHolding", function () { }); }); +// getPosition api +describe("getPosition", function () { + let res; + before(async function () { + res = await smart_api.getPosition(); + }); + + it("Get position successful", function () { + if (res.status) { + expect(res).to.have.property("status", true); + expect(res).to.have.property("message", "SUCCESS"); + expect(res).to.have.property("errorcode", ""); + expect(res).to.have.property("data"); + } + }); + + it("Get position failed", function () { + if (res.success === false) { + expect(res).to.have.property("success", false); + expect(res).to.have.property("message"); + expect(res).to.have.property("errorCode"); + expect(res).to.have.property("data"); + } + }); +}); + +// createRule api +describe("createRule", function () { + let res; + before(async function () { + res = await smart_api.createRule({ + tradingsymbol: "SBIN-EQ", + symboltoken: "3045", + exchange: "NSE", + producttype: "MARGIN", + transactiontype: "BUY", + price: 100000, + qty: 10, + disclosedqty: 10, + triggerprice: 200000, + timeperiod: 365, + }); + }); + + it("Create rule successful", function () { + if (res.status) { + expect(res).to.have.property("status", true); + expect(res).to.have.property("message", "SUCCESS"); + expect(res).to.have.property("errorcode", ""); + expect(res).to.have.property("data"); + } + }); + + it("Create rule failed", function () { + if (res.success === false) { + expect(res).to.have.property("success", false); + expect(res).to.have.property("message"); + expect(res).to.have.property("errorCode"); + expect(res).to.have.property("data"); + } + }); +}); + +// modifyRule api +describe("modifyRule", function () { + let res; + before(async function () { + res = await smart_api.modifyRule({ + id: 1440101, + symboltoken: "3045", + exchange: "NSE", + qty: 10, + }); + }); + + it("Modify rule successful", function () { + if (res.status) { + expect(res).to.have.property("status", true); + expect(res).to.have.property("message", "SUCCESS"); + expect(res).to.have.property("errorcode", ""); + expect(res).to.have.property("data"); + } + }); + + it("Modify rule failed", function () { + if (res.success === false) { + expect(res).to.have.property("success", false); + expect(res).to.have.property("message"); + expect(res).to.have.property("errorCode"); + expect(res).to.have.property("data"); + } + }); +}); + +// cancelRule api +describe("cancelRule", function () { + let res; + before(async function () { + res = await smart_api.cancelRule({ + id: 1440101, + symboltoken: "3045", + exchange: "NSE", + }); + }); + + it("Cancel rule successful", function () { + if (res.status) { + expect(res).to.have.property("status", true); + expect(res).to.have.property("message", "SUCCESS"); + expect(res).to.have.property("errorcode", ""); + expect(res).to.have.property("data"); + } + }); + + it("Cancel rule failed", function () { + if (res.success === false) { + expect(res).to.have.property("success", false); + expect(res).to.have.property("message"); + expect(res).to.have.property("errorCode"); + expect(res).to.have.property("data"); + } + }); +}); + +// ruleDetails api +describe("ruleDetails", function () { + let res; + before(async function () { + res = await smart_api.ruleDetails({ + id: 1440395, + }); + }); + + it("Rule details successful", function () { + if (res.status) { + expect(res).to.have.property("status", true); + expect(res).to.have.property("message", "SUCCESS"); + expect(res).to.have.property("errorcode", ""); + expect(res).to.have.property("data"); + } + }); + + it("Rule details failed", function () { + if (res.status === false) { + expect(res).to.have.property("status", false); + expect(res).to.have.property("message"); + expect(res).to.have.property("errorcode"); + expect(res).to.have.property("data"); + } + }); +}); + +// ruleList api +describe("ruleList", function () { + let res; + before(async function () { + res = await smart_api.ruleList({ + status: ["NEW", "CANCELLED"], + page: 1, + count: 10, + }); + }); + + it("Rule list successful", function () { + if (res.status === true) { + expect(res).to.have.property("status", true); + expect(res).to.have.property("message", "SUCCESS"); + expect(res).to.have.property("errorcode", ""); + expect(res).to.have.property("data"); + } + }); + + it("Rule list failed", function () { + if (res.status === 500) { + expect(res).to.have.property("status", 500); + expect(res).to.have.property("message"); + } + }); +}); + +// getCandleData api +describe("getCandleData", function () { + let res; + before(async function () { + res = await smart_api.getCandleData({ + exchange: "NSE", + symboltoken: "3045", + interval: "ONE_MINUTE", + fromdate: "2021-02-10 09:00", + todate: "2021-02-10 09:20", + }); + }); + + it("Get candle data successful", function () { + if (res.status === true) { + expect(res).to.have.property("status", true); + expect(res).to.have.property("message", "SUCCESS"); + expect(res).to.have.property("errorcode", ""); + expect(res).to.have.property("data"); + } + }); + + it("Get candle data failed", function () { + if (res.status === false) { + expect(res).to.have.property("status", false); + expect(res).to.have.property("message"); + expect(res).to.have.property("errorcode"); + expect(res).to.have.property("data"); + } + }); +}); + +// marketData api +describe("marketData", function () { + let res; + before(async function () { + res = await smart_api.marketData({ + mode: "FULL", + exchangeTokens: { + NSE: ["3045"], + }, + }); + }); + + it("Market data successful", function () { + if (res.status === true) { + expect(res).to.have.property("status", true); + expect(res).to.have.property("message", "SUCCESS"); + expect(res).to.have.property("errorcode", ""); + expect(res).to.have.property("data"); + } + }); + + it("Market data failed", function () { + if (res.status === false) { + expect(res).to.have.property("status", false); + expect(res).to.have.property("message"); + expect(res).to.have.property("errorcode"); + expect(res).to.have.property("data"); + } + }); +}); + +// searchScrip api +describe("searchScrip", function () { + let res; + before(async function () { + res = await smart_api.searchScrip({ + exchange: "BSE", + searchscrip: "Titan", + }); + }); + + it("Search scrip successful", function () { + if (res) { + expect(res) + } + }); + + it("Search scrip failed", function () { + if (res.status === false) { + expect(res).to.have.property("status", false); + expect(res).to.have.property("message"); + expect(res).to.have.property("errorcode"); + expect(res).to.have.property("data"); + } + }); +}); + +// getAllHolding api +describe("getAllHolding", function () { + let res; + before(async function () { + res = await smart_api.getAllHolding(); + }); + + it("Get all holding successful", function () { + if (res.status === true) { + expect(res).to.have.property("status", true); + expect(res).to.have.property("message", "SUCCESS"); + expect(res).to.have.property("errorcode", ""); + expect(res).to.have.property("data"); + } + }); + + it("Get all holding failed", function () { + if (res.success === false) { + expect(res).to.have.property("success", false); + expect(res).to.have.property("message"); + expect(res).to.have.property("errorCode"); + expect(res).to.have.property("data"); + } + }); +}); From a4368c1648d3dc7bdaffc67396e5d321fe71f749 Mon Sep 17 00:00:00 2001 From: Amol Date: Fri, 20 Oct 2023 10:56:41 +0530 Subject: [PATCH 5/7] testcase for websocket --- lib/websocket2.0.js | 5 +- test/test.js | 1143 +++++++++++++++++++++++-------------------- 2 files changed, 628 insertions(+), 520 deletions(-) diff --git a/lib/websocket2.0.js b/lib/websocket2.0.js index a7a7a2c..5a04300 100644 --- a/lib/websocket2.0.js +++ b/lib/websocket2.0.js @@ -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) => { @@ -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) { diff --git a/test/test.js b/test/test.js index c67d42c..9b8c63c 100644 --- a/test/test.js +++ b/test/test.js @@ -1,4 +1,4 @@ -let { SmartAPI, WebSocketClient, WebSocketV2 } = require("../lib"); +let { SmartAPI, WebSocketV2 } = require("../lib"); var chai = require("chai"); var expect = chai.expect; @@ -6,12 +6,12 @@ let smart_api = new SmartAPI({ api_key: "VG2s34Cq", // OPTIONAL : If user has valid access token and refresh token then it can be directly passed to the constructor access_token: - "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI6IkE1MjE2MzEzNCIsInJvbGVzIjowLCJ1c2VydHlwZSI6IlVTRVIiLCJ0b2tlbiI6ImV5SmhiR2NpT2lKSVV6VXhNaUlzSW5SNWNDSTZJa3BYVkNKOS5leUp6ZFdJaU9pSkJOVEl4TmpNeE16UWlMQ0psZUhBaU9qRTJPVGMyTVRVMU1qUXNJbWxoZENJNk1UWTVOelV4TnpZNE5Dd2lhblJwSWpvaVpHTTVZVGc1Wm1FdE5UVXdOQzAwTm1KbExUaGhZMll0TkRObU5ERXlZVGsyT0dKbElpd2liMjF1WlcxaGJtRm5aWEpwWkNJNk9Dd2ljMjkxY21ObGFXUWlPaUl6SWl3aWRYTmxjbDkwZVhCbElqb2lZMnhwWlc1MElpd2lkRzlyWlc1ZmRIbHdaU0k2SW5SeVlXUmxYMkZqWTJWemMxOTBiMnRsYmlJc0ltZHRYMmxrSWpvNExDSnpiM1Z5WTJVaU9pSXpJbjAuS1VtazN5Y1MwRUpHdDgxb3FIZEFyNnRUVTE4Q0VYWHREQmJnWUJ4UDlWaWcySm9kX2dONmlIZ3NrMEFSY0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xabkpsYzJoZmRHOXJaVzRpZlEucURXWlRqcWd6QlM1S3BOTVlsQ054ZnZveFZieGgxRmR6OFlPRkszTG5FcU9zVlAydWR1OFlfbDFJbjc5ZXU0Y3RJeXJBSVNrU0tNeXZya2szZG9nclEiLCJpYXQiOjE2OTc2OTI4MjV9.EoWC5AssEE1DJHES7tZST_BzNxgdfvB5tMxg_jH3T3tPYij-ypjX2qTvP6qzwzmdmKMVzGPRUT5QtHzqHd84Bg", }); -// generateSession api +// // generateSession api // describe("generateSession", function () { // let res; // before(async function () { @@ -44,536 +44,641 @@ let smart_api = new SmartAPI({ // }); // }); -// getProfile api -describe("getProfile", function () { - let res; - before(async function () { - res = await smart_api.getProfile(); - }); - - it("Get Profile successful", function () { - if (res.status) { - expect(res).to.have.property("status", true); - expect(res).to.have.property("message", "SUCCESS"); - expect(res).to.have.property("errorcode", ""); - expect(res).to.have.property("data"); - } - }); - - it("Get Profile failed", function () { - if (res.success === false) { - expect(res).to.have.property("success", false); - expect(res).to.have.property("message"); - expect(res).to.have.property("errorCode"); - expect(res).to.have.property("data"); - } - }); -}); +// // getProfile api +// describe("getProfile", function () { +// let res; +// before(async function () { +// res = await smart_api.getProfile(); +// }); -// getRMS -describe("getRMS", function () { - let res; - before(async function () { - res = await smart_api.getRMS(); - }); - - it("Get RMS successful", function () { - if (res.status) { - expect(res).to.have.property("status", true); - expect(res).to.have.property("message", "SUCCESS"); - expect(res).to.have.property("errorcode", ""); - expect(res).to.have.property("data"); - } - }); - - it("Get RMS failed", function () { - if (res.success === false) { - expect(res).to.have.property("success", false); - expect(res).to.have.property("message"); - expect(res).to.have.property("errorCode"); - expect(res).to.have.property("data"); - } - }); -}); +// it("Get Profile successful", function () { +// if (res.status) { +// expect(res).to.have.property("status", true); +// expect(res).to.have.property("message", "SUCCESS"); +// expect(res).to.have.property("errorcode", ""); +// expect(res).to.have.property("data"); +// } +// }); -// placeOrder api -describe("placeOrder", function () { - let res; - before(async function () { - res = await smart_api.placeOrder({ - variety: "NORMAL", - tradingsymbol: "SBIN-EQ", - symboltoken: "3045", - transactiontype: "BUY", - exchange: "NSE", - ordertype: "LIMIT", - producttype: "INTRADAY", - duration: "DAY", - price: "19500", - squareoff: "0", - stoploss: "0", - quantity: "1", - }); - }); - - it("Place Order successful", function () { - if (res.status) { - expect(res).to.have.property("status", true); - expect(res).to.have.property("message", "SUCCESS"); - expect(res).to.have.property("errorcode", ""); - expect(res).to.have.property("data"); - } - }); - - it("Place order failed", function () { - if (res.status === false) { - expect(res).to.have.property("status", false); - expect(res).to.have.property("message"); - expect(res).to.have.property("errorcode"); - expect(res).to.have.property("data", null); - } - }); -}); +// it("Get Profile failed", function () { +// if (res.success === false) { +// expect(res).to.have.property("success", false); +// expect(res).to.have.property("message"); +// expect(res).to.have.property("errorCode"); +// expect(res).to.have.property("data"); +// } +// }); +// }); -// modifyOrder api -describe("modifyOrder", function () { - let res; - before(async function () { - res = await smart_api.modifyOrder({ - orderid: "231016000616769", - variety: "NORMAL", - tradingsymbol: "SBIN-EQ", - symboltoken: "3045", - transactiontype: "BUY", - exchange: "NSE", - ordertype: "LIMIT", - producttype: "INTRADAY", - duration: "DAY", - price: "19500", - squareoff: "0", - stoploss: "0", - quantity: "2", - }); - }); - - it("Modify Order successful", function () { - if (res.status) { - expect(res).to.have.property("status", true); - expect(res).to.have.property("message", "SUCCESS"); - expect(res).to.have.property("errorcode", ""); - expect(res).to.have.property("data"); - } - }); - - it("Modify order failed", function () { - if (res.status === false) { - expect(res).to.have.property("status", false); - expect(res).to.have.property("message"); - expect(res).to.have.property("errorcode"); - expect(res).to.have.property("data", null); - } - }); -}); +// // getRMS +// describe("getRMS", function () { +// let res; +// before(async function () { +// res = await smart_api.getRMS(); +// }); -// cancelOrder api -describe("cancelOrder", function () { - let res; - before(async function () { - res = await smart_api.cancelOrder({ - variety: "NORMAL", - orderid: "231016000616769", - }); - }); - - it("Cancel Order successful", function () { - if (res.status) { - expect(res).to.have.property("status", true); - expect(res).to.have.property("message", "SUCCESS"); - expect(res).to.have.property("errorcode", ""); - expect(res).to.have.property("data"); - } - }); - - it("Cancel order failed", function () { - if (res.status === false) { - expect(res).to.have.property("status", false); - expect(res).to.have.property("message"); - expect(res).to.have.property("errorcode"); - expect(res).to.have.property("data", null); - } - }); -}); +// it("Get RMS successful", function () { +// if (res.status) { +// expect(res).to.have.property("status", true); +// expect(res).to.have.property("message", "SUCCESS"); +// expect(res).to.have.property("errorcode", ""); +// expect(res).to.have.property("data"); +// } +// }); -// getOrderBook api -describe("getOrderBook", function () { - let res; - before(async function () { - res = await smart_api.getOrderBook(); - }); - - it("Get order book successful", function () { - if (res.status) { - expect(res).to.have.property("status", true); - expect(res).to.have.property("message", "SUCCESS"); - expect(res).to.have.property("errorcode", ""); - expect(res).to.have.property("data"); - } - }); - - it("Get order book failed", function () { - if (res.status === false) { - expect(res).to.have.property("status", false); - expect(res).to.have.property("message"); - expect(res).to.have.property("errorcode"); - expect(res).to.have.property("data", null); - } - }); -}); +// it("Get RMS failed", function () { +// if (res.success === false) { +// expect(res).to.have.property("success", false); +// expect(res).to.have.property("message"); +// expect(res).to.have.property("errorCode"); +// expect(res).to.have.property("data"); +// } +// }); +// }); -// getTradeBook api -describe("getTradeBook", function () { - let res; - before(async function () { - res = await smart_api.getTradeBook(); - }); - - it("Get trade book successful", function () { - if (res.status) { - expect(res).to.have.property("status", true); - expect(res).to.have.property("message", "SUCCESS"); - expect(res).to.have.property("errorcode", ""); - expect(res).to.have.property("data"); - } - }); - - it("Get trade book failed", function () { - if (res.status === false) { - expect(res).to.have.property("status", false); - expect(res).to.have.property("message"); - expect(res).to.have.property("errorcode"); - expect(res).to.have.property("data"); - } - }); -}); +// // placeOrder api +// describe("placeOrder", function () { +// let res; +// before(async function () { +// res = await smart_api.placeOrder({ +// variety: "NORMAL", +// tradingsymbol: "SBIN-EQ", +// symboltoken: "3045", +// transactiontype: "BUY", +// exchange: "NSE", +// ordertype: "LIMIT", +// producttype: "INTRADAY", +// duration: "DAY", +// price: "19500", +// squareoff: "0", +// stoploss: "0", +// quantity: "1", +// }); +// }); -// getHolding api -describe("getHolding", function () { - let res; - before(async function () { - res = await smart_api.getHolding(); - }); - - it("Get holding successful", function () { - if (res.status) { - expect(res).to.have.property("status", true); - expect(res).to.have.property("message", "SUCCESS"); - expect(res).to.have.property("errorcode", ""); - expect(res).to.have.property("data"); - } - }); - - it("Get holding failed", function () { - if (res.status === false) { - expect(res).to.have.property("status", false); - expect(res).to.have.property("message"); - expect(res).to.have.property("errorcode"); - expect(res).to.have.property("data"); - } - }); -}); +// it("Place Order successful", function () { +// if (res.status) { +// expect(res).to.have.property("status", true); +// expect(res).to.have.property("message", "SUCCESS"); +// expect(res).to.have.property("errorcode", ""); +// expect(res).to.have.property("data"); +// } +// }); -// getPosition api -describe("getPosition", function () { - let res; - before(async function () { - res = await smart_api.getPosition(); - }); - - it("Get position successful", function () { - if (res.status) { - expect(res).to.have.property("status", true); - expect(res).to.have.property("message", "SUCCESS"); - expect(res).to.have.property("errorcode", ""); - expect(res).to.have.property("data"); - } - }); - - it("Get position failed", function () { - if (res.success === false) { - expect(res).to.have.property("success", false); - expect(res).to.have.property("message"); - expect(res).to.have.property("errorCode"); - expect(res).to.have.property("data"); - } - }); -}); +// it("Place order failed", function () { +// if (res.status === false) { +// expect(res).to.have.property("status", false); +// expect(res).to.have.property("message"); +// expect(res).to.have.property("errorcode"); +// expect(res).to.have.property("data", null); +// } +// }); +// }); -// createRule api -describe("createRule", function () { - let res; - before(async function () { - res = await smart_api.createRule({ - tradingsymbol: "SBIN-EQ", - symboltoken: "3045", - exchange: "NSE", - producttype: "MARGIN", - transactiontype: "BUY", - price: 100000, - qty: 10, - disclosedqty: 10, - triggerprice: 200000, - timeperiod: 365, - }); - }); - - it("Create rule successful", function () { - if (res.status) { - expect(res).to.have.property("status", true); - expect(res).to.have.property("message", "SUCCESS"); - expect(res).to.have.property("errorcode", ""); - expect(res).to.have.property("data"); - } - }); - - it("Create rule failed", function () { - if (res.success === false) { - expect(res).to.have.property("success", false); - expect(res).to.have.property("message"); - expect(res).to.have.property("errorCode"); - expect(res).to.have.property("data"); - } - }); -}); +// // modifyOrder api +// describe("modifyOrder", function () { +// let res; +// before(async function () { +// res = await smart_api.modifyOrder({ +// orderid: "231016000616769", +// variety: "NORMAL", +// tradingsymbol: "SBIN-EQ", +// symboltoken: "3045", +// transactiontype: "BUY", +// exchange: "NSE", +// ordertype: "LIMIT", +// producttype: "INTRADAY", +// duration: "DAY", +// price: "19500", +// squareoff: "0", +// stoploss: "0", +// quantity: "2", +// }); +// }); -// modifyRule api -describe("modifyRule", function () { - let res; - before(async function () { - res = await smart_api.modifyRule({ - id: 1440101, - symboltoken: "3045", - exchange: "NSE", - qty: 10, - }); - }); - - it("Modify rule successful", function () { - if (res.status) { - expect(res).to.have.property("status", true); - expect(res).to.have.property("message", "SUCCESS"); - expect(res).to.have.property("errorcode", ""); - expect(res).to.have.property("data"); - } - }); - - it("Modify rule failed", function () { - if (res.success === false) { - expect(res).to.have.property("success", false); - expect(res).to.have.property("message"); - expect(res).to.have.property("errorCode"); - expect(res).to.have.property("data"); - } - }); -}); +// it("Modify Order successful", function () { +// if (res.status) { +// expect(res).to.have.property("status", true); +// expect(res).to.have.property("message", "SUCCESS"); +// expect(res).to.have.property("errorcode", ""); +// expect(res).to.have.property("data"); +// } +// }); -// cancelRule api -describe("cancelRule", function () { - let res; - before(async function () { - res = await smart_api.cancelRule({ - id: 1440101, - symboltoken: "3045", - exchange: "NSE", - }); - }); - - it("Cancel rule successful", function () { - if (res.status) { - expect(res).to.have.property("status", true); - expect(res).to.have.property("message", "SUCCESS"); - expect(res).to.have.property("errorcode", ""); - expect(res).to.have.property("data"); - } - }); - - it("Cancel rule failed", function () { - if (res.success === false) { - expect(res).to.have.property("success", false); - expect(res).to.have.property("message"); - expect(res).to.have.property("errorCode"); - expect(res).to.have.property("data"); - } - }); -}); +// it("Modify order failed", function () { +// if (res.status === false) { +// expect(res).to.have.property("status", false); +// expect(res).to.have.property("message"); +// expect(res).to.have.property("errorcode"); +// expect(res).to.have.property("data", null); +// } +// }); +// }); -// ruleDetails api -describe("ruleDetails", function () { - let res; - before(async function () { - res = await smart_api.ruleDetails({ - id: 1440395, - }); - }); - - it("Rule details successful", function () { - if (res.status) { - expect(res).to.have.property("status", true); - expect(res).to.have.property("message", "SUCCESS"); - expect(res).to.have.property("errorcode", ""); - expect(res).to.have.property("data"); - } - }); - - it("Rule details failed", function () { - if (res.status === false) { - expect(res).to.have.property("status", false); - expect(res).to.have.property("message"); - expect(res).to.have.property("errorcode"); - expect(res).to.have.property("data"); - } - }); -}); +// // cancelOrder api +// describe("cancelOrder", function () { +// let res; +// before(async function () { +// res = await smart_api.cancelOrder({ +// variety: "NORMAL", +// orderid: "231016000616769", +// }); +// }); -// ruleList api -describe("ruleList", function () { - let res; - before(async function () { - res = await smart_api.ruleList({ - status: ["NEW", "CANCELLED"], - page: 1, - count: 10, - }); - }); - - it("Rule list successful", function () { - if (res.status === true) { - expect(res).to.have.property("status", true); - expect(res).to.have.property("message", "SUCCESS"); - expect(res).to.have.property("errorcode", ""); - expect(res).to.have.property("data"); - } - }); - - it("Rule list failed", function () { - if (res.status === 500) { - expect(res).to.have.property("status", 500); - expect(res).to.have.property("message"); - } - }); -}); +// it("Cancel Order successful", function () { +// if (res.status) { +// expect(res).to.have.property("status", true); +// expect(res).to.have.property("message", "SUCCESS"); +// expect(res).to.have.property("errorcode", ""); +// expect(res).to.have.property("data"); +// } +// }); -// getCandleData api -describe("getCandleData", function () { - let res; - before(async function () { - res = await smart_api.getCandleData({ - exchange: "NSE", - symboltoken: "3045", - interval: "ONE_MINUTE", - fromdate: "2021-02-10 09:00", - todate: "2021-02-10 09:20", - }); - }); - - it("Get candle data successful", function () { - if (res.status === true) { - expect(res).to.have.property("status", true); - expect(res).to.have.property("message", "SUCCESS"); - expect(res).to.have.property("errorcode", ""); - expect(res).to.have.property("data"); - } - }); - - it("Get candle data failed", function () { - if (res.status === false) { - expect(res).to.have.property("status", false); - expect(res).to.have.property("message"); - expect(res).to.have.property("errorcode"); - expect(res).to.have.property("data"); - } - }); -}); +// it("Cancel order failed", function () { +// if (res.status === false) { +// expect(res).to.have.property("status", false); +// expect(res).to.have.property("message"); +// expect(res).to.have.property("errorcode"); +// expect(res).to.have.property("data", null); +// } +// }); +// }); -// marketData api -describe("marketData", function () { - let res; - before(async function () { - res = await smart_api.marketData({ - mode: "FULL", - exchangeTokens: { - NSE: ["3045"], - }, - }); - }); - - it("Market data successful", function () { - if (res.status === true) { - expect(res).to.have.property("status", true); - expect(res).to.have.property("message", "SUCCESS"); - expect(res).to.have.property("errorcode", ""); - expect(res).to.have.property("data"); - } - }); - - it("Market data failed", function () { - if (res.status === false) { - expect(res).to.have.property("status", false); - expect(res).to.have.property("message"); - expect(res).to.have.property("errorcode"); - expect(res).to.have.property("data"); - } - }); -}); +// // getOrderBook api +// describe("getOrderBook", function () { +// let res; +// before(async function () { +// res = await smart_api.getOrderBook(); +// }); -// searchScrip api -describe("searchScrip", function () { - let res; - before(async function () { - res = await smart_api.searchScrip({ - exchange: "BSE", - searchscrip: "Titan", - }); - }); - - it("Search scrip successful", function () { - if (res) { - expect(res) - } - }); - - it("Search scrip failed", function () { - if (res.status === false) { - expect(res).to.have.property("status", false); - expect(res).to.have.property("message"); - expect(res).to.have.property("errorcode"); - expect(res).to.have.property("data"); - } - }); -}); +// it("Get order book successful", function () { +// if (res.status) { +// expect(res).to.have.property("status", true); +// expect(res).to.have.property("message", "SUCCESS"); +// expect(res).to.have.property("errorcode", ""); +// expect(res).to.have.property("data"); +// } +// }); + +// it("Get order book failed", function () { +// if (res.status === false) { +// expect(res).to.have.property("status", false); +// expect(res).to.have.property("message"); +// expect(res).to.have.property("errorcode"); +// expect(res).to.have.property("data", null); +// } +// }); +// }); + +// // getTradeBook api +// describe("getTradeBook", function () { +// let res; +// before(async function () { +// res = await smart_api.getTradeBook(); +// }); + +// it("Get trade book successful", function () { +// if (res.status) { +// expect(res).to.have.property("status", true); +// expect(res).to.have.property("message", "SUCCESS"); +// expect(res).to.have.property("errorcode", ""); +// expect(res).to.have.property("data"); +// } +// }); + +// it("Get trade book failed", function () { +// if (res.status === false) { +// expect(res).to.have.property("status", false); +// expect(res).to.have.property("message"); +// expect(res).to.have.property("errorcode"); +// expect(res).to.have.property("data"); +// } +// }); +// }); + +// // getHolding api +// describe("getHolding", function () { +// let res; +// before(async function () { +// res = await smart_api.getHolding(); +// }); + +// it("Get holding successful", function () { +// if (res.status) { +// expect(res).to.have.property("status", true); +// expect(res).to.have.property("message", "SUCCESS"); +// expect(res).to.have.property("errorcode", ""); +// expect(res).to.have.property("data"); +// } +// }); + +// it("Get holding failed", function () { +// if (res.status === false) { +// expect(res).to.have.property("status", false); +// expect(res).to.have.property("message"); +// expect(res).to.have.property("errorcode"); +// expect(res).to.have.property("data"); +// } +// }); +// }); + +// // getPosition api +// describe("getPosition", function () { +// let res; +// before(async function () { +// res = await smart_api.getPosition(); +// }); + +// it("Get position successful", function () { +// if (res.status) { +// expect(res).to.have.property("status", true); +// expect(res).to.have.property("message", "SUCCESS"); +// expect(res).to.have.property("errorcode", ""); +// expect(res).to.have.property("data"); +// } +// }); + +// it("Get position failed", function () { +// if (res.success === false) { +// expect(res).to.have.property("success", false); +// expect(res).to.have.property("message"); +// expect(res).to.have.property("errorCode"); +// expect(res).to.have.property("data"); +// } +// }); +// }); + +// // convertPosition api +// describe("convertPosition", function () { +// let res; +// before(async function () { +// res = await smart_api.convertPosition({ +// exchange: "NSE", +// oldproducttype: "DELIVERY", +// newproducttype: "MARGIN", +// tradingsymbol: "SBIN-EQ", +// transactiontype: "BUY", +// quantity: 1, +// type: "DAY", +// }); +// }); + +// it("Convert position successful", function () { +// if (res.status) { +// expect(res).to.have.property("status", true); +// expect(res).to.have.property("message", "SUCCESS"); +// expect(res).to.have.property("errorcode", ""); +// expect(res).to.have.property("data"); +// } +// }); + +// it("Convert position failed", function () { +// if (res.success === false) { +// expect(res).to.have.property("success", false); +// expect(res).to.have.property("message"); +// expect(res).to.have.property("errorCode"); +// expect(res).to.have.property("data"); +// } +// if (res.status === false) { +// expect(res).to.have.property("status", false); +// expect(res).to.have.property("message"); +// expect(res).to.have.property("errorcode"); +// expect(res).to.have.property("data"); +// } +// }); +// }); + + +// // createRule api +// describe("createRule", function () { +// let res; +// before(async function () { +// res = await smart_api.createRule({ +// tradingsymbol: "SBIN-EQ", +// symboltoken: "3045", +// exchange: "NSE", +// producttype: "MARGIN", +// transactiontype: "BUY", +// price: 100000, +// qty: 10, +// disclosedqty: 10, +// triggerprice: 200000, +// timeperiod: 365, +// }); +// }); + +// it("Create rule successful", function () { +// if (res.status) { +// expect(res).to.have.property("status", true); +// expect(res).to.have.property("message", "SUCCESS"); +// expect(res).to.have.property("errorcode", ""); +// expect(res).to.have.property("data"); +// } +// }); + +// it("Create rule failed", function () { +// if (res.success === false) { +// expect(res).to.have.property("success", false); +// expect(res).to.have.property("message"); +// expect(res).to.have.property("errorCode"); +// expect(res).to.have.property("data"); +// } +// }); +// }); + +// // modifyRule api +// describe("modifyRule", function () { +// let res; +// before(async function () { +// res = await smart_api.modifyRule({ +// id: 1440101, +// symboltoken: "3045", +// exchange: "NSE", +// qty: 10, +// }); +// }); + +// it("Modify rule successful", function () { +// if (res.status) { +// expect(res).to.have.property("status", true); +// expect(res).to.have.property("message", "SUCCESS"); +// expect(res).to.have.property("errorcode", ""); +// expect(res).to.have.property("data"); +// } +// }); + +// it("Modify rule failed", function () { +// if (res.success === false) { +// expect(res).to.have.property("success", false); +// expect(res).to.have.property("message"); +// expect(res).to.have.property("errorCode"); +// expect(res).to.have.property("data"); +// } +// }); +// }); + +// // cancelRule api +// describe("cancelRule", function () { +// let res; +// before(async function () { +// res = await smart_api.cancelRule({ +// id: 1440101, +// symboltoken: "3045", +// exchange: "NSE", +// }); +// }); + +// it("Cancel rule successful", function () { +// if (res.status) { +// expect(res).to.have.property("status", true); +// expect(res).to.have.property("message", "SUCCESS"); +// expect(res).to.have.property("errorcode", ""); +// expect(res).to.have.property("data"); +// } +// }); + +// it("Cancel rule failed", function () { +// if (res.success === false) { +// expect(res).to.have.property("success", false); +// expect(res).to.have.property("message"); +// expect(res).to.have.property("errorCode"); +// expect(res).to.have.property("data"); +// } +// }); +// }); + +// // ruleDetails api +// describe("ruleDetails", function () { +// let res; +// before(async function () { +// res = await smart_api.ruleDetails({ +// id: 1440395, +// }); +// }); + +// it("Rule details successful", function () { +// if (res.status) { +// expect(res).to.have.property("status", true); +// expect(res).to.have.property("message", "SUCCESS"); +// expect(res).to.have.property("errorcode", ""); +// expect(res).to.have.property("data"); +// } +// }); + +// it("Rule details failed", function () { +// if (res.status === false) { +// expect(res).to.have.property("status", false); +// expect(res).to.have.property("message"); +// expect(res).to.have.property("errorcode"); +// expect(res).to.have.property("data"); +// } +// }); +// }); + +// // ruleList api +// describe("ruleList", function () { +// let res; +// before(async function () { +// res = await smart_api.ruleList({ +// status: ["NEW", "CANCELLED"], +// page: 1, +// count: 10, +// }); +// }); + +// it("Rule list successful", function () { +// if (res.status === true) { +// expect(res).to.have.property("status", true); +// expect(res).to.have.property("message", "SUCCESS"); +// expect(res).to.have.property("errorcode", ""); +// expect(res).to.have.property("data"); +// } +// }); + +// it("Rule list failed", function () { +// if (res.status === 500) { +// expect(res).to.have.property("status", 500); +// expect(res).to.have.property("message"); +// } +// }); +// }); + +// // getCandleData api +// describe("getCandleData", function () { +// let res; +// before(async function () { +// res = await smart_api.getCandleData({ +// exchange: "NSE", +// symboltoken: "3045", +// interval: "ONE_MINUTE", +// fromdate: "2021-02-10 09:00", +// todate: "2021-02-10 09:20", +// }); +// }); + +// it("Get candle data successful", function () { +// if (res.status === true) { +// expect(res).to.have.property("status", true); +// expect(res).to.have.property("message", "SUCCESS"); +// expect(res).to.have.property("errorcode", ""); +// expect(res).to.have.property("data"); +// } +// }); + +// it("Get candle data failed", function () { +// if (res.status === false) { +// expect(res).to.have.property("status", false); +// expect(res).to.have.property("message"); +// expect(res).to.have.property("errorcode"); +// expect(res).to.have.property("data"); +// } +// }); +// }); + +// // marketData api +// describe("marketData", function () { +// let res; +// before(async function () { +// res = await smart_api.marketData({ +// mode: "FULL", +// exchangeTokens: { +// NSE: ["3045"], +// }, +// }); +// }); + +// it("Market data successful", function () { +// if (res.status === true) { +// expect(res).to.have.property("status", true); +// expect(res).to.have.property("message", "SUCCESS"); +// expect(res).to.have.property("errorcode", ""); +// expect(res).to.have.property("data"); +// } +// }); + +// it("Market data failed", function () { +// if (res.status === false) { +// expect(res).to.have.property("status", false); +// expect(res).to.have.property("message"); +// expect(res).to.have.property("errorcode"); +// expect(res).to.have.property("data"); +// } +// }); +// }); + +// // searchScrip api +// describe("searchScrip", function () { +// let res; +// before(async function () { +// res = await smart_api.searchScrip({ +// exchange: "BSE", +// searchscrip: "Titan", +// }); +// }); + +// it("Search scrip successful", function () { +// if (res) { +// expect(res) +// } +// }); + +// it("Search scrip failed", function () { +// if (res.status === false) { +// expect(res).to.have.property("status", false); +// expect(res).to.have.property("message"); +// expect(res).to.have.property("errorcode"); +// expect(res).to.have.property("data"); +// } +// }); +// }); + +// // getAllHolding api +// describe("getAllHolding", function () { +// let res; +// before(async function () { +// res = await smart_api.getAllHolding(); +// }); + +// it("Get all holding successful", function () { +// if (res.status === true) { +// expect(res).to.have.property("status", true); +// expect(res).to.have.property("message", "SUCCESS"); +// expect(res).to.have.property("errorcode", ""); +// expect(res).to.have.property("data"); +// } +// }); + +// it("Get all holding failed", function () { +// if (res.success === false) { +// expect(res).to.have.property("success", false); +// expect(res).to.have.property("message"); +// expect(res).to.have.property("errorCode"); +// expect(res).to.have.property("data"); +// } +// }); +// }); + +// // logout api +// describe("logout", function () { +// let res; +// before(async function () { +// res = await smart_api.logout(); +// }); + +// it("Logout successful", function () { +// if (res.status) { +// expect(res).to.have.property("status", true); +// expect(res).to.have.property("message", "SUCCESS"); +// expect(res).to.have.property("errorcode", ""); +// expect(res).to.have.property("data"); +// } +// }); + +// it("Logout failed", function () { +// if (res.status === false) { +// expect(res).to.have.property("status", false); +// expect(res).to.have.property("message"); +// expect(res).to.have.property("errorcode"); +// expect(res).to.have.property("data"); +// } +// }); +// }); + + +// // WebSocketV2 +// describe("WebSocketV2", function () { +// let web_socket; +// let websocketConnection = false; + +// before(function () { +// web_socket = new WebSocketV2({ +// jwttoken: +// "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI6IkE1MjE2MzEzNCIsInJvbGVzIjowLCJ1c2VydHlwZSI6IlVTRVIiLCJ0b2tlbiI6ImV5SmhiR2NpT2lKSVV6VXhNaUlzSW5SNWNDSTZJa3BYVkNKOS5leUp6ZFdJaU9pSkJOVEl4TmpNeE16UWlMQ0psZUhBaU9qRTJPVGMzT0Rrd05EZ3NJbWxoZENJNk1UWTVOelk1TWpjMk5Td2lhblJwSWpvaU5qRmpORFpoTWpVdE9EUTRPQzAwWmprNExXRTBNREl0TmpsalpHSmpOalEyTkdRNElpd2liMjF1WlcxaGJtRm5aWEpwWkNJNk9Dd2ljMjkxY21ObGFXUWlPaUl6SWl3aWRYTmxjbDkwZVhCbElqb2lZMnhwWlc1MElpd2lkRzlyWlc1ZmRIbHdaU0k2SW5SeVlXUmxYMkZqWTJWemMxOTBiMnRsYmlJc0ltZHRYMmxrSWpvNExDSnpiM1Z5WTJVaU9pSXpJbjAubmJNZW9GMGNtNEQ4aW1VM2F1X0dqak0yYVltbnptdFR5NzRaMnpZbG4tTVRMa0E2MnFfdHQzSGt4S1RzVTFaaDkzT19UX3lFUUM0bEpTaE1sQVBlX0EiLCJBUEktS0VZIjoiVkcyczM0Q3EiLCJpYXQiOjE2OTc2OTI4MjUsImV4cCI6MTY5Nzc4OTA0OH0.iuJJ_QMQ_BMwKAA4YnbqI_L18LctwY95kp2_NbdBYfTGByfGdOo3XsHO0vfvQqXS76Y3n8stqrIip_Q4Om56cQ", +// apikey: "VG2s34Cq", +// clientcode: "A52163134", +// feedtype: +// "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI6IkE1MjE2MzEzNCIsImlhdCI6MTY5NzY5MjgyNSwiZXhwIjoxNjk3Nzc5MjI1fQ.ZGmie7MDMi8QTUcA3IdUZ5qb-4ZAO3KM7FWg3AUAF8h0nj68X8UxrxtY-gqXtsicKjTXTizpqGYA6bAvsD4ioQ", +// }); +// }); + +// it("Websocket connection successful", function () { +// return web_socket.connect().then((connected) => { +// if (connected) { +// websocketConnection = true; +// expect(connected).to.equal(true); +// setTimeout(() => { +// web_socket.close(); +// }, 3000); +// } +// }); +// }); + +// it("Websocket connection failed", function () { +// if(websocketConnection === false){ +// console.log('Connection failed') +// } +// }); + +// }); -// getAllHolding api -describe("getAllHolding", function () { - let res; - before(async function () { - res = await smart_api.getAllHolding(); - }); - - it("Get all holding successful", function () { - if (res.status === true) { - expect(res).to.have.property("status", true); - expect(res).to.have.property("message", "SUCCESS"); - expect(res).to.have.property("errorcode", ""); - expect(res).to.have.property("data"); - } - }); - - it("Get all holding failed", function () { - if (res.success === false) { - expect(res).to.have.property("success", false); - expect(res).to.have.property("message"); - expect(res).to.have.property("errorCode"); - expect(res).to.have.property("data"); - } - }); -}); From 8e18881f75118ba89841b4fa7e828e4c0fac3a29 Mon Sep 17 00:00:00 2001 From: Amol Date: Fri, 20 Oct 2023 14:12:17 +0530 Subject: [PATCH 6/7] testcases added for api and websocket --- example/{test.js => api_test.js} | 166 +++++++++++-------------------- test/{test.js => testcase.js} | 69 ++++++------- 2 files changed, 90 insertions(+), 145 deletions(-) rename example/{test.js => api_test.js} (53%) rename test/{test.js => testcase.js} (88%) diff --git a/example/test.js b/example/api_test.js similarity index 53% rename from example/test.js rename to example/api_test.js index ffdf8a2..d55d4c9 100644 --- a/example/test.js +++ b/example/api_test.js @@ -1,17 +1,17 @@ -let { SmartAPI, WebSocketClient, WebSocketV2 } = require('../lib'); +let { SmartAPI, WebSocketClient, WebSocketV2 } = require("../lib"); let smart_api = new SmartAPI({ - api_key: "VG2s34Cq", // 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: 'eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI6IkE1MjE2MzEzNCIsInJvbGVzIjowLCJ1c2VydHlwZSI6IlVTRVIiLCJ0b2tlbiI6ImV5SmhiR2NpT2lKSVV6VXhNaUlzSW5SNWNDSTZJa3BYVkNKOS5leUp6ZFdJaU9pSkJOVEl4TmpNeE16UWlMQ0psZUhBaU9qRTJPVGMyTVRVMU1qUXNJbWxoZENJNk1UWTVOelV4TnpZNE5Dd2lhblJwSWpvaVpHTTVZVGc1Wm1FdE5UVXdOQzAwTm1KbExUaGhZMll0TkRObU5ERXlZVGsyT0dKbElpd2liMjF1WlcxaGJtRm5aWEpwWkNJNk9Dd2ljMjkxY21ObGFXUWlPaUl6SWl3aWRYTmxjbDkwZVhCbElqb2lZMnhwWlc1MElpd2lkRzlyWlc1ZmRIbHdaU0k2SW5SeVlXUmxYMkZqWTJWemMxOTBiMnRsYmlJc0ltZHRYMmxrSWpvNExDSnpiM1Z5WTJVaU9pSXpJbjAuS1VtazN5Y1MwRUpHdDgxb3FIZEFyNnRUVTE4Q0VYWHREQmJnWUJ4UDlWaWcySm9kX2dONmlIZ3NrMEFSY0JCN0JiaVJmSktqRjB1VnhKTnZFQnNFdlEiLCJBUEktS0VZIjoiVkcyczM0Q3EiLCJpYXQiOjE2OTc1MTc3NDQsImV4cCI6MTY5NzYxNTUyNH0.Ykl_ADBV9ocMmGDInt8BwJR41xK3vMuTZ4dHkHLpUt5Gvq53EGXZ5OUSN017xrNo2iAYYOfJm3yDZfOeh5Fiwg', - refresh_token: 'eyJhbGciOiJIUzUxMiJ9.eyJ0b2tlbiI6IlJFRlJFU0gtVE9LRU4iLCJSRUZSRVNILVRPS0VOIjoiZXlKaGJHY2lPaUpJVXpVeE1pSXNJblI1Y0NJNklrcFhWQ0o5LmV5SnpkV0lpT2lKQk5USXhOak14TXpRaUxDSmxlSEFpT2pFMk9UYzFOakE1TkRRc0ltbGhkQ0k2TVRZNU56VXhOelk0TkN3aWFuUnBJam9pTVRRMU5qTmpNR1l0TUdSa01TMDBORE0wTFRrek9XTXRPRFl6TVRSa1ltTXpZalprSWl3aWRHOXJaVzRpT2lKU1JVWlNSVk5JTFZSUFMwVk9JaXdpZFhObGNsOTBlWEJsSWpvaVkyeHBaVzUwSWl3aWRHOXJaVzVmZEhsd1pTSTZJblJ5WVdSbFgzSmxabkpsYzJoZmRHOXJaVzRpZlEuNUk5X1I4RHV6NDd6bDE4X0FaOVpaS0VkLWxqRVVRWnEwU3hSSHVaWVB1OEdfbV9VbFd5em11WEdCSi1rSVhZZE1NOFRNWkltSzZKYng5WHZmSmNndVEiLCJpYXQiOjE2OTc1MTc3NDR9.nRzIcjFpKJ9j_xJhKEkzQw5-TFyVK4gwmtYvzoSt5q-5I8CBv8XebNMEDgwwVg25pE8QuIU3qWGfIw8HB70Jww', + 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 // } // smart_api -// .generateSession('A52163134', '4321', '123295') +// .generateSession('CLIENT_CODE', 'PASSWORD', 'TOTP') // .then((data) => { // console.log(data); // return smart_api.getProfile(); @@ -64,24 +64,12 @@ let smart_api = new SmartAPI({ // console.log(data); // }) -// return smart_api.getTradeBook(); +// // // return smart_api.getTradeBook(); // // // Portfolio Methods -// smart_api -// .getHolding() -// .then((data) => { -// console.log("Success: ", data); -// }) -// .catch((err) => { -// console.log("Error:", err); -// }); +// // // return smart_api.getHolding(); -// smart_api.getPosition().then((data) => { -// console.log("Success: ", data); -// }) -// .catch((err) => { -// console.log("Error:", err); -// }); +// // // return smart_api.getPosition(); // // // return smart_api.convertPosition({ // // // "exchange": "NSE", @@ -94,89 +82,47 @@ let smart_api = new SmartAPI({ // // // }); // // // GTT Methods - // smart_api - // .createRule({ - // tradingsymbol: "SBIN-EQ", - // symboltoken: "3045", - // exchange: "NSE", - // producttype: "MARGIN", - // transactiontype: "BUY", - // price: 100000, - // qty: 10, - // disclosedqty: 10, - // triggerprice: 200000, - // timeperiod: 365, - // }) - // .then((data) => { - // console.log("Success cancel: ", data); - // }) - // .catch((err) => { - // console.log("Error:", err); - // }); -// smart_api -// .modifyRule({ -// id: 1440101, -// symboltoken: "3045", -// exchange: "NSE", -// qty: 10, -// }) -// .then((data) => { -// console.log("Success modify: ", data); -// }) -// .catch((err) => { -// console.log("Error:", err); -// }); -// smart_api -// .cancelRule({ -// id: 1440101, -// symboltoken: "3045", -// exchange: "NSE", -// }) -// .then((data) => { -// console.log("Success cancel: ", data); -// }) -// .catch((err) => { -// console.log("Error:", err); -// }); -// smart_api -// .ruleDetails({ -// id: 1440395, -// }) -// .then((data) => { -// console.log("Success cancel: ", data); -// }) -// .catch((err) => { -// console.log("Error:", err); -// }); - // smart_api - // .ruleList({ - // status: ["NEW", "CANCELLED"], - // page: 1, - // count: 10, - // }) - // .then((data) => { - // console.log("Success cancel: ", data); - // }) - // .catch((err) => { - // console.log("Error:", err); - // }); - - //Historical Methods - // smart_api - // .getCandleData({ - // exchange: "NSE", - // symboltoken: "3045", - // interval: "ONE_MINUTE", - // fromdate: "2021-02-10 09:00", - // todate: "2021-02-10 09:20", - // }) - // .then((data) => { - // console.log("Success cancel: ", data); - // }) - // .catch((err) => { - // console.log("Error:", err); - // }); +// // // return smart_api.createRule({ +// // // "tradingsymbol" : "SBIN-EQ", +// // // "symboltoken" : "3045", +// // // "exchange" : "NSE", +// // // "producttype" : "MARGIN", +// // // "transactiontype" : "BUY", +// // // "price" : 100000, +// // // "qty" : 10, +// // // "disclosedqty": 10, +// // // "triggerprice" : 200000, +// // // "timeperiod" : 365 +// // // }) +// // // return smart_api.modifyRule({ +// // // "id" : 1000014, +// // // "symboltoken" : "3045", +// // // "exchange" : "NSE", +// // // "qty" : 10 +// // // }) +// // // return smart_api.cancelRule({ +// // // "id" : 1000014, +// // // "symboltoken" : "3045", +// // // "exchange" : "NSE" +// // // }) +// // // return smart_api.ruleDetails({ +// // // "id" : 25 +// // // }) +// // // return smart_api.ruleList({ +// // // "status" : ["NEW","CANCELLED"], +// // // "page" : 1, +// // // "count" : 10 +// // // }) + +// // // Historical Methods +// // // return smart_api.getCandleData({ +// // // "exchange": "NSE", +// // // "symboltoken": "3045", +// // // "interval": "ONE_MINUTE", +// // // "fromdate": "2021-02-10 09:00", +// // // "todate": "2021-02-10 09:20" +// // // }) // Market Data Methods // smart_api.marketData({ @@ -192,12 +138,14 @@ let smart_api = new SmartAPI({ // }); // search Scrip Methods -// smart_api.searchScrip({ -// "exchange": "BSE", -// "searchscrip":"Titan" -// }).then((data)=>{ -// console.log(data); -// }) +smart_api + .searchScrip({ + exchange: "BSE", + searchscrip: "Titan", + }) + .then((data) => { + console.log(data); + }); // get all holding method // smart_api.getAllHolding().then((data)=>{ diff --git a/test/test.js b/test/testcase.js similarity index 88% rename from test/test.js rename to test/testcase.js index 9b8c63c..c5cd62a 100644 --- a/test/test.js +++ b/test/testcase.js @@ -5,17 +5,16 @@ var expect = chai.expect; let smart_api = new SmartAPI({ api_key: "VG2s34Cq", // OPTIONAL : If user has valid access token and refresh token then it can be directly passed to the constructor - access_token: - "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI6IkE1MjE2MzEzNCIsInJvbGVzIjowLCJ1c2VydHlwZSI6IlVTRVIiLCJ0b2tlbiI6ImV5SmhiR2NpT2lKSVV6VXhNaUlzSW5SNWNDSTZJa3BYVkNKOS5leUp6ZFdJaU9pSkJOVEl4TmpNeE16UWlMQ0psZUhBaU9qRTJPVGMzT0Rrd05EZ3NJbWxoZENJNk1UWTVOelk1TWpjMk5Td2lhblJwSWpvaU5qRmpORFpoTWpVdE9EUTRPQzAwWmprNExXRTBNREl0TmpsalpHSmpOalEyTkdRNElpd2liMjF1WlcxaGJtRm5aWEpwW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AssEE1DJHES7tZST_BzNxgdfvB5tMxg_jH3T3tPYij-ypjX2qTvP6qzwzmdmKMVzGPRUT5QtHzqHd84Bg", + access_token:'', + refresh_token:'', }); // // generateSession api // describe("generateSession", function () { // let res; // before(async function () { -// res = await smart_api.generateSession("A52163134", "4321", "378315"); +// res = await smart_api.generateSession("A52163134", "4321", "197313"); +// console.log(res); // if (res.status) { // const { jwtToken, refreshToken } = res.data; @@ -44,31 +43,31 @@ let smart_api = new SmartAPI({ // }); // }); -// // getProfile api -// describe("getProfile", function () { -// let res; -// before(async function () { -// res = await smart_api.getProfile(); -// }); - -// it("Get Profile successful", function () { -// if (res.status) { -// expect(res).to.have.property("status", true); -// expect(res).to.have.property("message", "SUCCESS"); -// expect(res).to.have.property("errorcode", ""); -// expect(res).to.have.property("data"); -// } -// }); - -// it("Get Profile failed", function () { -// if (res.success === false) { -// expect(res).to.have.property("success", false); -// expect(res).to.have.property("message"); -// expect(res).to.have.property("errorCode"); -// expect(res).to.have.property("data"); -// } -// }); -// }); +// getProfile api +describe("getProfile", function () { + let res; + before(async function () { + res = await smart_api.getProfile(); + }); + + it("Get Profile successful", function () { + if (res.status) { + expect(res).to.have.property("status", true); + expect(res).to.have.property("message", "SUCCESS"); + expect(res).to.have.property("errorcode", ""); + expect(res).to.have.property("data"); + } + }); + + it("Get Profile failed", function () { + if (res.success === false) { + expect(res).to.have.property("success", false); + expect(res).to.have.property("message"); + expect(res).to.have.property("errorCode"); + expect(res).to.have.property("data"); + } + }); +}); // // getRMS // describe("getRMS", function () { @@ -626,11 +625,10 @@ let smart_api = new SmartAPI({ // }); // it("Logout successful", function () { -// if (res.status) { -// expect(res).to.have.property("status", true); -// expect(res).to.have.property("message", "SUCCESS"); -// expect(res).to.have.property("errorcode", ""); -// expect(res).to.have.property("data"); +// if (res.status || res.status === 500) { +// expect(res).to.have.property("status"); +// expect(res).to.have.property("message"); + // } // }); @@ -644,7 +642,6 @@ let smart_api = new SmartAPI({ // }); // }); - // // WebSocketV2 // describe("WebSocketV2", function () { // let web_socket; From d8acf0686a1b38ce87ee767ac9414dc1b9418ce4 Mon Sep 17 00:00:00 2001 From: Amol Date: Fri, 20 Oct 2023 14:26:35 +0530 Subject: [PATCH 7/7] Removed hardcoded values --- test/testcase.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/test/testcase.js b/test/testcase.js index c5cd62a..596ac69 100644 --- a/test/testcase.js +++ b/test/testcase.js @@ -3,17 +3,17 @@ var chai = require("chai"); var expect = chai.expect; let smart_api = new SmartAPI({ - api_key: "VG2s34Cq", + api_key: "smartapi_key", // OPTIONAL : If user has valid access token and refresh token then it can be directly passed to the constructor - access_token:'', - refresh_token:'', + access_token: "YOUR_ACCESS_TOKEN", + refresh_token: "YOUR_REFRESH_TOKEN", }); // // generateSession api // describe("generateSession", function () { // let res; // before(async function () { -// res = await smart_api.generateSession("A52163134", "4321", "197313"); +// res = await smart_api.generateSession('CLIENT_CODE', 'PASSWORD', 'TOTP'); // console.log(res); // if (res.status) { // const { jwtToken, refreshToken } = res.data; @@ -649,12 +649,10 @@ describe("getProfile", function () { // before(function () { // web_socket = new WebSocketV2({ -// jwttoken: -// "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI6IkE1MjE2MzEzNCIsInJvbGVzIjowLCJ1c2VydHlwZSI6IlVTRVIiLCJ0b2tlbiI6ImV5SmhiR2NpT2lKSVV6VXhNaUlzSW5SNWNDSTZJa3BYVkNKOS5leUp6ZFdJaU9pSkJOVEl4TmpNeE16UWlMQ0psZUhBaU9qRTJPVGMzT0Rrd05EZ3NJbWxoZENJNk1UWTVOelk1TWpjMk5Td2lhblJwSWpvaU5qRmpORFpoTWpVdE9EUTRPQzAwWmprNExXRTBNREl0TmpsalpHSmpOalEyTkdRNElpd2liMjF1WlcxaGJtRm5aWEpwWkNJNk9Dd2ljMjkxY21ObGFXUWlPaUl6SWl3aWRYTmxjbDkwZVhCbElqb2lZMnhwWlc1MElpd2lkRzlyWlc1ZmRIbHdaU0k2SW5SeVlXUmxYMkZqWTJWemMxOTBiMnRsYmlJc0ltZHRYMmxrSWpvNExDSnpiM1Z5WTJVaU9pSXpJbjAubmJNZW9GMGNtNEQ4aW1VM2F1X0dqak0yYVltbnptdFR5NzRaMnpZbG4tTVRMa0E2MnFfdHQzSGt4S1RzVTFaaDkzT19UX3lFUUM0bEpTaE1sQVBlX0EiLCJBUEktS0VZIjoiVkcyczM0Q3EiLCJpYXQiOjE2OTc2OTI4MjUsImV4cCI6MTY5Nzc4OTA0OH0.iuJJ_QMQ_BMwKAA4YnbqI_L18LctwY95kp2_NbdBYfTGByfGdOo3XsHO0vfvQqXS76Y3n8stqrIip_Q4Om56cQ", -// apikey: "VG2s34Cq", -// clientcode: "A52163134", -// feedtype: -// "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI6IkE1MjE2MzEzNCIsImlhdCI6MTY5NzY5MjgyNSwiZXhwIjoxNjk3Nzc5MjI1fQ.ZGmie7MDMi8QTUcA3IdUZ5qb-4ZAO3KM7FWg3AUAF8h0nj68X8UxrxtY-gqXtsicKjTXTizpqGYA6bAvsD4ioQ", +// clientcode: "CLIENT_CODE", +// jwttoken: 'JWT_TOKEN', +// apikey: "API_KEY", +// feedtype: "FEED_TYPE", // }); // });