From ce2d4b5da5d70e6d0dd52f3dccc3867971abe107 Mon Sep 17 00:00:00 2001 From: Amol Date: Wed, 19 Jul 2023 12:49:02 +0530 Subject: [PATCH 1/3] market data api added --- config/api.js | 2 ++ example/test.js | 67 ++++++++++++++++++++++++++--------------- lib/smartapi-connect.js | 11 +++++++ 3 files changed, 56 insertions(+), 24 deletions(-) diff --git a/config/api.js b/config/api.js index d348287..767d57a 100644 --- a/config/api.js +++ b/config/api.js @@ -28,6 +28,8 @@ module.exports.API = { rule_list: '/rest/secure/angelbroking/gtt/v1/ruleList', candle_data: '/rest/secure/angelbroking/historical/v1/getCandleData', + market_data : '/rest/secure/angelbroking/market/v1/quote' + // "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 46dd0af..eba85c4 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 + api_key: '5VB3xxLM', // 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" + access_token: 'eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI6IlI1MDg0MTQ4MiIsInJvbGVzIjowLCJ1c2VydHlwZSI6IlVTRVIiLCJpYXQiOjE2ODk2NjIyNzAsImV4cCI6MTY4OTc0ODY3MH0.pkDzNnwpFjRZfNbWoqHNAbyBY_19c72tSfQTBNp4lNksnoE9KEFXmJGno0aRr5M5eiOM9goMkVg6UV2yLB-WwA', + refresh_token: 'eyJhbGciOiJIUzUxMiJ9.eyJ0b2tlbiI6IlJFRlJFU0gtVE9LRU4iLCJpYXQiOjE2ODk2NjIyNzB9.EEoGGRhV2l4VzC6U6NcLGKC3tVjq9ZHYNN2i1B-Da4qXMwol72co3C79X-JPeDMT-6yxKekxtI3kVrPkOe507w' }); // // If user does not have valid access token and refresh token then use generateSession method // } // smart_api -// .generateSession('CLIENT_CODE', 'PASSWORD', 'TOTP') +// .generateSession('R50841482', '7255', '259563') // .then((data) => { // console.log(data); // return smart_api.getProfile(); @@ -60,6 +60,10 @@ let smart_api = new SmartAPI({ // // // return smart_api.getOrderBook(); + // smart_api.getOrderBook().then((data)=>{ + // console.log(data); + // }) + // // // return smart_api.getTradeBook(); // // // Portfolio Methods @@ -119,6 +123,21 @@ let smart_api = new SmartAPI({ // // // "fromdate": "2021-02-10 09:00", // // // "todate": "2021-02-10 09:20" // // // }) + + + // Market Data Methods + smart_api.marketData({ + "mode": "LTP", + "exchangeTokens": { + "NSE": [ + "3045" + ] + } + }).then((data) => { + console.log(JSON.stringify(data, null, 2)); + // console.log(JSON.stringify(data)) + }); + // }) // .then((data) => { // console.log('PROFILE::', data); @@ -190,32 +209,32 @@ let smart_api = new SmartAPI({ // } // ########################### Socket V2 Sample Code Start Here ########################### -let web_socket = new WebSocketV2({ - jwttoken: 'JWT_TOKEN', - apikey: 'API_KEY', - clientcode: 'Client_code', - feedtype: 'FEED_TYPE', -}); +// let web_socket = new WebSocketV2({ +// jwttoken: 'JWT_TOKEN', +// apikey: 'API_KEY', +// clientcode: 'Client_code', +// feedtype: 'FEED_TYPE', +// }); -web_socket.connect().then(() => { - let json_req = { - correlationID: 'abcde12345', - action: 1, - mode: 2, - exchangeType: 1, - tokens: ['1594'], - }; +// web_socket.connect().then(() => { +// let json_req = { +// correlationID: 'abcde12345', +// action: 1, +// mode: 2, +// exchangeType: 1, +// tokens: ['1594'], +// }; - web_socket.fetchData(json_req); +// web_socket.fetchData(json_req); - web_socket.on('tick', receiveTick); +// web_socket.on('tick', receiveTick); - function receiveTick(data) { - console.log('receiveTick:::::', data); - } +// function receiveTick(data) { +// console.log('receiveTick:::::', data); +// } // setTimeout(() => { // web_socket.close(); // }, 10000); -}); +// }); // ########################### Socket V2 Sample Code End Here ########################### diff --git a/lib/smartapi-connect.js b/lib/smartapi-connect.js index 6d07d68..2c22511 100644 --- a/lib/smartapi-connect.js +++ b/lib/smartapi-connect.js @@ -427,6 +427,17 @@ var SmartApi = function (params) { }; }; + /** + * Description + * @method marketData + * @param {object} params + * @param {string} mode + * @param {string} exchangeTokens + */ + self.marketData = function (params){ + return post_request('market_data',params); + }; + /** * Description * @method ruleList From 1abb3f11710d34d1d352ac09f6d6d9bba45958bc Mon Sep 17 00:00:00 2001 From: Amol Date: Fri, 21 Jul 2023 11:39:33 +0530 Subject: [PATCH 2/3] market-data api added --- config/api.js | 1 - example/test.js | 30 +++++++++++++++--------------- lib/smartapi-connect.js | 8 ++++---- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/config/api.js b/config/api.js index 767d57a..f574df9 100644 --- a/config/api.js +++ b/config/api.js @@ -29,7 +29,6 @@ module.exports.API = { candle_data: '/rest/secure/angelbroking/historical/v1/getCandleData', market_data : '/rest/secure/angelbroking/market/v1/quote' - // "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 eba85c4..d0f3005 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: '5VB3xxLM', // PROVIDE YOUR API KEY HERE + 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: 'eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI6IlI1MDg0MTQ4MiIsInJvbGVzIjowLCJ1c2VydHlwZSI6IlVTRVIiLCJpYXQiOjE2ODk2NjIyNzAsImV4cCI6MTY4OTc0ODY3MH0.pkDzNnwpFjRZfNbWoqHNAbyBY_19c72tSfQTBNp4lNksnoE9KEFXmJGno0aRr5M5eiOM9goMkVg6UV2yLB-WwA', - refresh_token: 'eyJhbGciOiJIUzUxMiJ9.eyJ0b2tlbiI6IlJFRlJFU0gtVE9LRU4iLCJpYXQiOjE2ODk2NjIyNzB9.EEoGGRhV2l4VzC6U6NcLGKC3tVjq9ZHYNN2i1B-Da4qXMwol72co3C79X-JPeDMT-6yxKekxtI3kVrPkOe507w' + // 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('R50841482', '7255', '259563') +// .generateSession('CLIENT_CODE', 'PASSWORD', 'TOTP') // .then((data) => { // console.log(data); // return smart_api.getProfile(); @@ -126,17 +126,17 @@ let smart_api = new SmartAPI({ // Market Data Methods - smart_api.marketData({ - "mode": "LTP", - "exchangeTokens": { - "NSE": [ - "3045" - ] - } - }).then((data) => { - console.log(JSON.stringify(data, null, 2)); - // console.log(JSON.stringify(data)) - }); + // smart_api.marketData({ + // "mode": "FULL", + // "exchangeTokens": { + // "NSE": [ + // "3045" + // ] + // } + // }).then((data) => { + // console.log(JSON.stringify(data, null, 2)); + // // console.log(JSON.stringify(data)) + // }); // }) // .then((data) => { diff --git a/lib/smartapi-connect.js b/lib/smartapi-connect.js index 2c22511..4f36908 100644 --- a/lib/smartapi-connect.js +++ b/lib/smartapi-connect.js @@ -100,7 +100,7 @@ var SmartApi = function (params) { return response?.data; } } catch (error) { - return null; + return []; } }, (error) => { @@ -114,11 +114,11 @@ var SmartApi = function (params) { errorObj.status = 500; errorObj.message = 'Error'; } - // return errorObj; + return errorObj; - return Promise.reject(errorObj); + // return Promise.reject(errorObj); } catch (error) { - return null; + return []; } } ); From ec659691e9ab4a8851d28dab673823afcc18955b Mon Sep 17 00:00:00 2001 From: Amol Date: Fri, 4 Aug 2023 14:02:50 +0530 Subject: [PATCH 3/3] test file renamed --- example/{test.js => testsuite.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename example/{test.js => testsuite.js} (100%) diff --git a/example/test.js b/example/testsuite.js similarity index 100% rename from example/test.js rename to example/testsuite.js