api_connect_nodejs 2.0.13 → 2.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +30 -30
  2. package/conf/settings.ini +17 -20
  3. package/enums/actionType.js +10 -10
  4. package/enums/assetType.js +25 -25
  5. package/enums/chartExchangeType.js +16 -16
  6. package/enums/chartType.js +13 -13
  7. package/enums/eodIntervalType.js +11 -11
  8. package/enums/exchangeType.js +15 -15
  9. package/enums/intradayIntervalType.js +14 -14
  10. package/enums/marketCapType.js +12 -12
  11. package/enums/orderType.js +21 -21
  12. package/enums/productType.js +24 -24
  13. package/enums/segementsType.js +13 -13
  14. package/enums/segmentType.js +10 -10
  15. package/enums/streamingConstants.js +13 -13
  16. package/enums/termsType.js +12 -12
  17. package/enums/validity.js +22 -22
  18. package/index.js +3 -3
  19. package/package.json +25 -25
  20. package/src/apiConnect.js +2682 -2559
  21. package/src/apiUtils.js +221 -221
  22. package/src/chart.js +404 -404
  23. package/src/config.js +347 -342
  24. package/src/feed/depthFeed.js +136 -136
  25. package/src/feed/feed.js +170 -170
  26. package/src/feed/liveNewsFeed.js +112 -112
  27. package/src/feed/miniQuoteFeed.js +122 -121
  28. package/src/feed/ordersFeed.js +125 -124
  29. package/src/feed/quotesFeed.js +123 -122
  30. package/src/http.js +260 -197
  31. package/src/iniparser.js +45 -45
  32. package/src/liveNews.js +362 -362
  33. package/src/logger.js +16 -16
  34. package/src/order.js +48 -48
  35. package/src/quote.js +75 -75
  36. package/src/report.js +49 -49
  37. package/src/researchCalls.js +175 -175
  38. package/src/watchlist.js +378 -378
  39. package/validations/apiConnectValidator.js +701 -698
  40. package/validations/chartValidator.js +125 -125
  41. package/validations/feedStreamerValidator.js +162 -162
  42. package/validations/liveNewsValidator.js +60 -60
  43. package/validations/quoteValidator.js +19 -19
  44. package/validations/reportValidator.js +35 -35
  45. package/validations/researchCallsValidator.js +86 -86
  46. package/validations/watchlistValidator.js +60 -60
package/src/http.js CHANGED
@@ -1,197 +1,260 @@
1
- const https = require("https");
2
- const JSZip = require("jszip");
3
- const fs = require("fs");
4
- class __Http {
5
- constructor(constants, baseurl) {
6
- this.__constants = constants;
7
- this.__baseurl = baseurl;
8
- }
9
-
10
- __fileName = "";
11
-
12
- get fileName() {
13
- return this.__VendorSession;
14
- }
15
-
16
- set fileName(val) {
17
- this.__VendorSession = val;
18
- }
19
-
20
- createHeaders(sendSource) {
21
- let headers = {
22
- "Content-Type": "application/json",
23
- "User-Agent":null,
24
- Authorization: this.__constants.JSession,
25
- SourceToken: this.__constants.VendorSession,
26
- AppIdKey: this.__constants.AppIdKey,
27
- };
28
- if (sendSource) headers.Source = this.__constants.ApiKey;
29
- return headers;
30
- }
31
-
32
- GetMethod(url, sendSource = true) {
33
- let headers = this.createHeaders(sendSource);
34
- const options = { hostname: this.__baseurl, path: url, headers: headers };
35
-
36
- return new Promise((resolve, reject) => {
37
- const req = https.get(options, (res) => {
38
- let body = [];
39
- res.on("data", (d) => {
40
- body.push(d);
41
- });
42
-
43
- res.on("end", () => {
44
- try {
45
- body = JSON.parse(Buffer.concat(body).toString());
46
- if (res.headers.appidkey) {
47
- this.__constants.AppIdKey = res.headers.appidkey;
48
- }
49
-
50
- if (res.statusCode === 200) {
51
- resolve(body);
52
- } else if (res.statusCode > 200 && res.statusCode <= 299) {
53
- resolve("");
54
- } else if (res.statusCode === 401 || res.statusCode === 403) {
55
- fs.unlinkSync(this.fileName);
56
- reject(body);
57
- } else {
58
- reject(body);
59
- }
60
- } catch (e) {
61
- reject(e);
62
- }
63
- });
64
- });
65
-
66
- req.on("error", reject);
67
- req.end();
68
- });
69
- }
70
-
71
- PostMethod(url, data, sendSource = true) {
72
- let headers = this.createHeaders(sendSource);
73
- const options = {
74
- hostname: this.__baseurl,
75
- path: url,
76
- method: "POST",
77
- headers: headers,
78
- };
79
- return this.__postPutDeleteMethod(options, data);
80
- }
81
-
82
- PutMethod(url, data) {
83
- let headers = this.createHeaders();
84
- const options = {
85
- hostname: this.__baseurl,
86
- path: url,
87
- method: "PUT",
88
- headers: headers,
89
- };
90
-
91
- return this.__postPutDeleteMethod(options, data);
92
- }
93
-
94
- DeleteMethod(url, data, sendSource = true) {
95
- let headers = this.createHeaders(sendSource);
96
- headers["Content-Length"] = Buffer.byteLength(JSON.stringify(data));
97
- const options = {
98
- hostname: this.__baseurl,
99
- path: url,
100
- method: "DELETE",
101
- headers: headers,
102
- };
103
-
104
- return this.__postPutDeleteMethod(options, data);
105
- }
106
-
107
- __postPutDeleteMethod(options, data) {
108
- return new Promise((resolve, reject) => {
109
- const req = https.request(options, (res) => {
110
- let body = [];
111
- res.on("data", (d) => {
112
- body.push(d);
113
- });
114
-
115
- res.on("end", () => {
116
- try {
117
- body = JSON.parse(Buffer.concat(body).toString());
118
-
119
- if (res.headers.appidkey) {
120
- this.__constants.AppIdKey = res.headers.appidkey;
121
- }
122
-
123
- if (res.statusCode === 200) {
124
- resolve(body);
125
- } else if (res.statusCode === 401 || res.statusCode === 403) {
126
- try {
127
- fs.unlinkSync(this.fileName);
128
- } catch {
129
- } finally {
130
- reject(body);
131
- }
132
- } else {
133
- console.log("Error : ", body);
134
- reject(body);
135
- }
136
- } catch (e) {
137
- reject(e);
138
- }
139
- });
140
- });
141
- req.on("error", reject);
142
-
143
- req.write(JSON.stringify(data));
144
- req.end();
145
- });
146
- }
147
-
148
- GetZipFileMethod(url, fileName) {
149
- let headers = this.createHeaders();
150
- const options = {
151
- hostname: this.__baseurl,
152
- path: url,
153
- headers: headers,
154
- secureProtocol: "TLSv1_2_method",
155
- };
156
- return new Promise((resolve, reject) => {
157
- let body = [];
158
- const req = https.get(
159
- options,
160
- (res) => {
161
- res.on("data", (d) => {
162
- body.push(d);
163
- });
164
- res.on("end", () => {
165
- if (res.statusCode === 200) {
166
- let buf = Buffer.concat(body);
167
-
168
- function saveCSV(b) {
169
- fs.writeFile(fileName, b, "binary", function (err) {
170
- if (err) {
171
- reject("could not extract file");
172
- } else {
173
- resolve();
174
- }
175
- });
176
- }
177
-
178
- JSZip.loadAsync(buf)
179
- .then((zip) => zip.file(fileName).async("nodebuffer"))
180
- .then(saveCSV);
181
- } else {
182
- reject(body);
183
- }
184
- });
185
- },
186
- (err) => {
187
- console.log("err", err);
188
- }
189
- );
190
-
191
- req.on("error", reject);
192
- req.end();
193
- });
194
- }
195
- }
196
-
197
- module.exports = __Http;
1
+ const https = require("https");
2
+ const JSZip = require("jszip");
3
+ const fs = require("fs");
4
+ class __Http {
5
+ constructor(constants, baseurl) {
6
+ this.__constants = constants;
7
+ this.__baseurl = baseurl;
8
+ }
9
+
10
+ __fileName = "";
11
+
12
+ get fileName() {
13
+ return this.__VendorSession;
14
+ }
15
+
16
+ set fileName(val) {
17
+ this.__VendorSession = val;
18
+ }
19
+
20
+ createHeaders(sendSource) {
21
+ let headers = {
22
+ "Content-Type": "application/json",
23
+ "User-Agent":null,
24
+ Authorization: this.__constants.JSession,
25
+ SourceToken: this.__constants.VendorSession,
26
+ AppIdKey: this.__constants.AppIdKey,
27
+ };
28
+ if (sendSource) headers.Source = this.__constants.ApiKey;
29
+ return headers;
30
+ }
31
+
32
+ GetMethod(url, sendSource = true) {
33
+ let headers = this.createHeaders(sendSource);
34
+ const options = { hostname: this.__baseurl, path: url, headers: headers };
35
+
36
+ return new Promise((resolve, reject) => {
37
+ const req = https.get(options, (res) => {
38
+ let body = [];
39
+ res.on("data", (d) => {
40
+ body.push(d);
41
+ });
42
+
43
+ // res.on("end", () => {
44
+ // try {
45
+ // body = JSON.parse(Buffer.concat(body).toString());
46
+ // if (res.headers.appidkey) {
47
+ // this.__constants.AppIdKey = res.headers.appidkey;
48
+ // }
49
+
50
+ // if (res.statusCode === 200) {
51
+ // resolve(body);
52
+ // } else if (res.statusCode > 200 && res.statusCode <= 299) {
53
+ // resolve("");
54
+ // } else if (res.statusCode === 401 || res.statusCode === 403) {
55
+ // fs.unlinkSync(this.fileName);
56
+ // reject(body);
57
+ // } else {
58
+ // reject(body);
59
+ // }
60
+ // } catch (e) {
61
+ // reject(e);
62
+ // }
63
+ // });
64
+
65
+ res.on("end", () => {
66
+ const rawResponse = Buffer.concat(body).toString();
67
+ let parsedBody;
68
+
69
+ try {
70
+ parsedBody = JSON.parse(rawResponse);
71
+ } catch (err) {
72
+ parsedBody = {
73
+ status: "error",
74
+ code: res?.statusCode || 500,
75
+ message: res?.statusMessage || "Invalid Response"
76
+ };
77
+ }
78
+
79
+ if (res.headers.appidkey) {
80
+ this.__constants.AppIdKey = res.headers.appidkey;
81
+ }
82
+
83
+ if (res.statusCode === 200) {
84
+ resolve(parsedBody);
85
+ } else if (res.statusCode > 200 && res.statusCode <= 299) {
86
+ resolve("");
87
+ } else if (res.statusCode === 401 || res.statusCode === 403) {
88
+ fs.unlinkSync(this.fileName);
89
+ reject(parsedBody);
90
+ } else {
91
+ reject(parsedBody);
92
+ }
93
+ });
94
+
95
+
96
+ });
97
+
98
+ req.on("error", reject);
99
+ req.end();
100
+ });
101
+ }
102
+
103
+ PostMethod(url, data, sendSource = true) {
104
+ let headers = this.createHeaders(sendSource);
105
+ const options = {
106
+ hostname: this.__baseurl,
107
+ path: url,
108
+ method: "POST",
109
+ headers: headers,
110
+ };
111
+ return this.__postPutDeleteMethod(options, data);
112
+ }
113
+
114
+ PutMethod(url, data) {
115
+ let headers = this.createHeaders();
116
+ const options = {
117
+ hostname: this.__baseurl,
118
+ path: url,
119
+ method: "PUT",
120
+ headers: headers,
121
+ };
122
+
123
+ return this.__postPutDeleteMethod(options, data);
124
+ }
125
+
126
+ DeleteMethod(url, data, sendSource = true) {
127
+ let headers = this.createHeaders(sendSource);
128
+ headers["Content-Length"] = Buffer.byteLength(JSON.stringify(data));
129
+ const options = {
130
+ hostname: this.__baseurl,
131
+ path: url,
132
+ method: "DELETE",
133
+ headers: headers,
134
+ };
135
+
136
+ return this.__postPutDeleteMethod(options, data);
137
+ }
138
+
139
+ __postPutDeleteMethod(options, data) {
140
+ return new Promise((resolve, reject) => {
141
+ const req = https.request(options, (res) => {
142
+ let body = [];
143
+ res.on("data", (d) => {
144
+ body.push(d);
145
+ });
146
+
147
+ // res.on("end", () => {
148
+ // try {
149
+ // body = JSON.parse(Buffer.concat(body).toString());
150
+
151
+ // if (res.headers.appidkey) {
152
+ // this.__constants.AppIdKey = res.headers.appidkey;
153
+ // }
154
+
155
+ // if (res.statusCode === 200) {
156
+ // resolve(body);
157
+ // } else if (res.statusCode === 401 || res.statusCode === 403) {
158
+ // try {
159
+ // fs.unlinkSync(this.fileName);
160
+ // } catch {
161
+ // } finally {
162
+ // reject(body);
163
+ // }
164
+ // } else {
165
+ // console.log("Error : ", body);
166
+ // reject(body);
167
+ // }
168
+ // } catch (e) {
169
+ // reject(e);
170
+ // }
171
+ // });
172
+
173
+ res.on("end", () => {
174
+ const rawResponse = Buffer.concat(body).toString();
175
+ let parsedBody;
176
+
177
+ try {
178
+ parsedBody = JSON.parse(rawResponse);
179
+ } catch (err) {
180
+ parsedBody = {
181
+ status: "error",
182
+ code: res?.statusCode || 500,
183
+ message: res?.statusMessage || "Invalid Response"
184
+ };
185
+ }
186
+
187
+ if (res.headers.appidkey) {
188
+ this.__constants.AppIdKey = res.headers.appidkey;
189
+ }
190
+
191
+ if (res.statusCode === 200) {
192
+ resolve(parsedBody);
193
+ } else if (res.statusCode > 200 && res.statusCode <= 299) {
194
+ resolve("");
195
+ } else if (res.statusCode === 401 || res.statusCode === 403) {
196
+ fs.unlinkSync(this.fileName);
197
+ reject(parsedBody);
198
+ } else {
199
+ reject(parsedBody);
200
+ }
201
+ });
202
+
203
+ });
204
+ req.on("error", reject);
205
+
206
+ req.write(JSON.stringify(data));
207
+ req.end();
208
+ });
209
+ }
210
+
211
+ GetZipFileMethod(url, fileName) {
212
+ let headers = this.createHeaders();
213
+ const options = {
214
+ hostname: this.__baseurl,
215
+ path: url,
216
+ headers: headers,
217
+ secureProtocol: "TLSv1_2_method",
218
+ };
219
+ return new Promise((resolve, reject) => {
220
+ let body = [];
221
+ const req = https.get(
222
+ options,
223
+ (res) => {
224
+ res.on("data", (d) => {
225
+ body.push(d);
226
+ });
227
+ res.on("end", () => {
228
+ if (res.statusCode === 200) {
229
+ let buf = Buffer.concat(body);
230
+
231
+ function saveCSV(b) {
232
+ fs.writeFile(fileName, b, "binary", function (err) {
233
+ if (err) {
234
+ reject("could not extract file");
235
+ } else {
236
+ resolve();
237
+ }
238
+ });
239
+ }
240
+
241
+ JSZip.loadAsync(buf)
242
+ .then((zip) => zip.file(fileName).async("nodebuffer"))
243
+ .then(saveCSV);
244
+ } else {
245
+ reject(body);
246
+ }
247
+ });
248
+ },
249
+ (err) => {
250
+ console.log("err", err);
251
+ }
252
+ );
253
+
254
+ req.on("error", reject);
255
+ req.end();
256
+ });
257
+ }
258
+ }
259
+
260
+ module.exports = __Http;
package/src/iniparser.js CHANGED
@@ -1,45 +1,45 @@
1
- const fs = require("fs");
2
- const ini = require("ini");
3
-
4
- BasePathLogin = "";
5
- BasePathEq = "";
6
- BasePathComm = "";
7
- BasePathMf = "";
8
- BasePathContent = "";
9
- BasePathReport = "";
10
- ApiIdKey = "";
11
- LogLevel = "";
12
- hostName = "";
13
- port = "";
14
- formFactor = "";
15
-
16
- const ConfigParser = function () {
17
- var config = ini.parse(fs.readFileSync("./conf/settings.ini", "utf-8"));
18
- BasePathLogin = config.GLOBAL.BasePathLogin;
19
- BasePathEq = config.GLOBAL.BasePathEq;
20
- BasePathComm = config.GLOBAL.BasePathComm;
21
- BasePathMf = config.GLOBAL.BasePathMf;
22
- BasePathContent = config.GLOBAL.BasePathContent;
23
- BasePathReport = config.GLOBAL.BasePathReport;
24
- ApiIdKey = config.GLOBAL.ApiIdKey;
25
- LogLevel = config.GLOBAL.LogLevel;
26
- hostName = config.STREAM.hostName;
27
- port = config.STREAM.port;
28
- formFactor = config.STREAM.formFactor;
29
- };
30
-
31
- ConfigParser();
32
-
33
- module.exports = {
34
- BasePathLogin,
35
- BasePathEq,
36
- BasePathComm,
37
- BasePathMf,
38
- ApiIdKey,
39
- LogLevel,
40
- hostName,
41
- port,
42
- formFactor,
43
- BasePathContent,
44
- BasePathReport,
45
- };
1
+ const fs = require("fs");
2
+ const ini = require("ini");
3
+
4
+ BasePathLogin = "";
5
+ BasePathEq = "";
6
+ BasePathComm = "";
7
+ BasePathMf = "";
8
+ BasePathContent = "";
9
+ BasePathReport = "";
10
+ ApiIdKey = "";
11
+ LogLevel = "";
12
+ hostName = "";
13
+ port = "";
14
+ formFactor = "";
15
+
16
+ const ConfigParser = function () {
17
+ var config = ini.parse(fs.readFileSync("./conf/settings.ini", "utf-8"));
18
+ BasePathLogin = config.GLOBAL.BasePathLogin;
19
+ BasePathEq = config.GLOBAL.BasePathEq;
20
+ //BasePathComm = config.GLOBAL.BasePathComm;
21
+ BasePathMf = config.GLOBAL.BasePathMf;
22
+ BasePathContent = config.GLOBAL.BasePathContent;
23
+ BasePathReport = config.GLOBAL.BasePathReport;
24
+ ApiIdKey = config.GLOBAL.ApiIdKey;
25
+ LogLevel = config.GLOBAL.LogLevel;
26
+ hostName = config.STREAM.hostName;
27
+ port = config.STREAM.port;
28
+ formFactor = config.STREAM.formFactor;
29
+ };
30
+
31
+ ConfigParser();
32
+
33
+ module.exports = {
34
+ BasePathLogin,
35
+ BasePathEq,
36
+ //BasePathComm,
37
+ BasePathMf,
38
+ ApiIdKey,
39
+ LogLevel,
40
+ hostName,
41
+ port,
42
+ formFactor,
43
+ BasePathContent,
44
+ BasePathReport,
45
+ };