smartapi-javascript
Advanced tools
+3
-1
@@ -33,3 +33,5 @@ module.exports.API = { | ||
| search_scrip : '/rest/secure/angelbroking/order/v1/searchScrip', | ||
| get_all_holding : '/rest/secure/angelbroking/portfolio/v1/getAllHolding', | ||
| get_all_holding : '/rest/secure/angelbroking/portfolio/v1/getAllHolding', | ||
| ind_order_details: '/rest/secure/angelbroking/order/v1/details', | ||
| margin_api : 'rest/secure/angelbroking/margin/v1/batch' | ||
| // "api.token": "/session/token", | ||
@@ -36,0 +38,0 @@ // "api.token.invalidate": "/session/token", |
+32
-4
@@ -153,2 +153,26 @@ let { SmartAPI, WebSocketClient, WebSocketV2 } = require('../lib'); | ||
| // }) | ||
| // get individual order details | ||
| // smart_api.indOrderDetails("GuiOrderID").then((data) => { | ||
| // console.log(data); | ||
| // }); | ||
| // // margin api Method | ||
| // smart_api | ||
| // .marginApi({ | ||
| // positions: [ | ||
| // { | ||
| // exchange: "NFO", | ||
| // qty: 1500, | ||
| // price: 0, | ||
| // productType: "CARRYFORWARD", | ||
| // token: "154388", | ||
| // tradeType: "SELL", | ||
| // } | ||
| // ], | ||
| // }) | ||
| // .then((data) => { | ||
| // console.log(data); | ||
| // }); | ||
| // }) | ||
@@ -232,2 +256,5 @@ // .then((data) => { | ||
| // //For handling custom error | ||
| // web_socket.customError(); | ||
| // web_socket.connect().then(() => { | ||
@@ -241,3 +268,2 @@ // let json_req = { | ||
| // }; | ||
| // web_socket.fetchData(json_req); | ||
@@ -251,6 +277,8 @@ | ||
| // setTimeout(() => { | ||
| // web_socket.close(); | ||
| // }, 10000); | ||
| // setTimeout(() => { | ||
| // web_socket.close(); | ||
| // }, 10000); | ||
| // }).catch((err)=>{ | ||
| // console.log('Custom error :',err.message); | ||
| // }); | ||
| // ########################### Socket V2 Sample Code End Here ########################### |
@@ -480,2 +480,21 @@ 'use strict'; | ||
| * Description | ||
| * @method indOrderDetails | ||
| * @param {string} qParams | ||
| */ | ||
| self.indOrderDetails = function (qParams) { | ||
| return get_request_qParams("ind_order_details", qParams); | ||
| }; | ||
| /** | ||
| * Description | ||
| * @method marginApi | ||
| * @param {object} params | ||
| * @param {array} positions | ||
| */ | ||
| self.marginApi = function (params) { | ||
| return post_request("margin_api", params); | ||
| }; | ||
| /** | ||
| * Description | ||
| * @method ruleList | ||
@@ -513,2 +532,10 @@ * @param {object} params | ||
| function get_request_qParams(route, qParams) { | ||
| return request_util_qParams( | ||
| route, | ||
| "GET", | ||
| qParams | ||
| ); | ||
| } | ||
| function request_util( | ||
@@ -556,4 +583,39 @@ route, | ||
| } | ||
| function request_util_qParams( | ||
| route, | ||
| method, | ||
| qParams | ||
| ) { | ||
| let url = API[route], | ||
| payload = null; | ||
| if (qParams) { | ||
| url = `${url}/${qParams}`; | ||
| } | ||
| let options = { | ||
| method: method, | ||
| url: url, | ||
| // params: queryParams, | ||
| data: JSON.stringify(payload), | ||
| // Set auth header | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| Accept: "application/json", | ||
| "X-UserType": "USER", | ||
| "X-SourceID": "WEB", | ||
| "X-PrivateKey": self.api_key, // ? self.api_key : 'smartapi_key' | ||
| }, | ||
| }; | ||
| // console.log('options', options); | ||
| if (self.access_token) { | ||
| options["headers"]["Authorization"] = "Bearer " + self.access_token; | ||
| } | ||
| return requestInstance.request(options); | ||
| } | ||
| }; | ||
| module.exports = SmartApi; |
+18
-8
@@ -28,2 +28,3 @@ let WebSocket = require('ws'); | ||
| let open = 1; | ||
| let customErrorHandler = false; | ||
@@ -80,12 +81,17 @@ this.connect = function () { | ||
| ws.onerror = function (evt) { | ||
| if (evt?.message?.match(/\d{3}/)?.[0] == 401) { | ||
| throw new Error(evt.message); | ||
| if (customErrorHandler) { | ||
| reject(evt); | ||
| } | ||
| try { | ||
| if (ws?._readyState === open) { | ||
| ws.close(); | ||
| else { | ||
| if (evt?.message?.match(/\d{3}/)?.[0] == 401) { | ||
| throw new Error(evt.message); | ||
| } | ||
| clearInterval(reset); | ||
| } catch (error) { | ||
| throw new Error(error); | ||
| try { | ||
| if (ws?._readyState === open) { | ||
| ws.close(); | ||
| } | ||
| clearInterval(reset); | ||
| } catch (error) { | ||
| throw new Error(error); | ||
| } | ||
| } | ||
@@ -171,2 +177,6 @@ }; | ||
| }; | ||
| this.customError = function () { | ||
| customErrorHandler = true; | ||
| }; | ||
| } catch (error) { | ||
@@ -173,0 +183,0 @@ throw new Error(error); |
+1
-1
| { | ||
| "name": "smartapi-javascript", | ||
| "version": "1.0.18", | ||
| "version": "1.0.19", | ||
| "description": "", | ||
@@ -5,0 +5,0 @@ "main": "./lib/", |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
52116
4.35%1485
6.45%