api_connect_nodejs 1.0.1 → 2.0.1

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 (43) hide show
  1. package/README.md +31 -31
  2. package/conf/settings.ini +19 -20
  3. package/enums/actionType.js +10 -10
  4. package/enums/assetType.js +25 -25
  5. package/enums/chartExchangeType.js +15 -15
  6. package/enums/chartType.js +13 -13
  7. package/enums/eodIntervalType.js +11 -11
  8. package/enums/exchangeType.js +14 -14
  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/streamingConstants.js +11 -0
  15. package/enums/termsType.js +12 -12
  16. package/enums/validity.js +22 -22
  17. package/index.js +3 -3
  18. package/package.json +25 -37
  19. package/src/{edelconnect.js → apiConnect.js} +2424 -2211
  20. package/src/{edelweissApiUtils.js → apiUtils.js} +129 -129
  21. package/src/chart.js +258 -258
  22. package/src/config.js +326 -326
  23. package/src/feed/feed.js +139 -0
  24. package/src/feed/liveNewsFeed.js +112 -0
  25. package/src/feed/ordersFeed.js +124 -0
  26. package/src/feed/quotesFeed.js +121 -0
  27. package/src/http.js +197 -196
  28. package/src/iniparser.js +42 -41
  29. package/src/liveNews.js +362 -362
  30. package/src/logger.js +16 -16
  31. package/src/order.js +48 -48
  32. package/src/researchCalls.js +175 -175
  33. package/src/watchlist.js +378 -378
  34. package/validations/{edelconnectValidator.js → apiConnectValidator.js} +508 -619
  35. package/validations/chartValidator.js +85 -85
  36. package/validations/feedStreamerValidator.js +68 -0
  37. package/validations/liveNewsValidator.js +60 -60
  38. package/validations/researchCallsValidator.js +86 -86
  39. package/validations/watchlistValidator.js +60 -60
  40. package/.prettierrc.json +0 -19
  41. package/gitignore +0 -23
  42. package/src/feed.js +0 -166
  43. package/validations/feedValidator.js +0 -31
package/src/http.js CHANGED
@@ -1,196 +1,197 @@
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
- Authorization: this.__constants.JSession,
24
- SourceToken: this.__constants.VendorSession,
25
- AppIdKey: this.__constants.AppIdKey,
26
- };
27
- if (sendSource) headers.Source = this.__constants.ApiKey;
28
- return headers;
29
- }
30
-
31
- GetMethod(url, sendSource = true) {
32
- let headers = this.createHeaders(sendSource);
33
- const options = { hostname: this.__baseurl, path: url, headers: headers };
34
-
35
- return new Promise((resolve, reject) => {
36
- const req = https.get(options, (res) => {
37
- let body = [];
38
- res.on("data", (d) => {
39
- body.push(d);
40
- });
41
-
42
- res.on("end", () => {
43
- try {
44
- body = JSON.parse(Buffer.concat(body).toString());
45
-
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
- reject(body);
134
- }
135
- } catch (e) {
136
- reject(e);
137
- }
138
- });
139
- });
140
- req.on("error", reject);
141
-
142
- req.write(JSON.stringify(data));
143
- req.end();
144
- });
145
- }
146
-
147
- GetZipFileMethod(url, fileName) {
148
- let headers = this.createHeaders();
149
- const options = {
150
- hostname: this.__baseurl,
151
- path: url,
152
- headers: headers,
153
- secureProtocol: "TLSv1_2_method",
154
- };
155
- return new Promise((resolve, reject) => {
156
- let body = [];
157
- const req = https.get(
158
- options,
159
- (res) => {
160
- res.on("data", (d) => {
161
- body.push(d);
162
- });
163
- res.on("end", () => {
164
- if (res.statusCode === 200) {
165
- let buf = Buffer.concat(body);
166
-
167
- function saveCSV(b) {
168
- fs.writeFile(fileName, b, "binary", function (err) {
169
- if (err) {
170
- reject("could not extract file");
171
- } else {
172
- resolve();
173
- }
174
- });
175
- }
176
-
177
- JSZip.loadAsync(buf)
178
- .then((zip) => zip.file(fileName).async("nodebuffer"))
179
- .then(saveCSV);
180
- } else {
181
- reject(body);
182
- }
183
- });
184
- },
185
- (err) => {
186
- console.log("err", err);
187
- }
188
- );
189
-
190
- req.on("error", reject);
191
- req.end();
192
- });
193
- }
194
- }
195
-
196
- 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
+
47
+ if (res.headers.appidkey) {
48
+ this.__constants.AppIdKey = res.headers.appidkey;
49
+ }
50
+
51
+ if (res.statusCode === 200) {
52
+ resolve(body);
53
+ } else if (res.statusCode > 200 && res.statusCode <= 299) {
54
+ resolve("");
55
+ } else if (res.statusCode === 401 || res.statusCode === 403) {
56
+ fs.unlinkSync(this.fileName);
57
+ reject(body);
58
+ } else {
59
+ reject(body);
60
+ }
61
+ } catch (e) {
62
+ reject(e);
63
+ }
64
+ });
65
+ });
66
+
67
+ req.on("error", reject);
68
+ req.end();
69
+ });
70
+ }
71
+
72
+ PostMethod(url, data, sendSource = true) {
73
+ let headers = this.createHeaders(sendSource);
74
+ const options = {
75
+ hostname: this.__baseurl,
76
+ path: url,
77
+ method: "POST",
78
+ headers: headers,
79
+ };
80
+ return this.__postPutDeleteMethod(options, data);
81
+ }
82
+
83
+ PutMethod(url, data) {
84
+ let headers = this.createHeaders();
85
+ const options = {
86
+ hostname: this.__baseurl,
87
+ path: url,
88
+ method: "PUT",
89
+ headers: headers,
90
+ };
91
+
92
+ return this.__postPutDeleteMethod(options, data);
93
+ }
94
+
95
+ DeleteMethod(url, data, sendSource = true) {
96
+ let headers = this.createHeaders(sendSource);
97
+ headers["Content-Length"] = Buffer.byteLength(JSON.stringify(data));
98
+ const options = {
99
+ hostname: this.__baseurl,
100
+ path: url,
101
+ method: "DELETE",
102
+ headers: headers,
103
+ };
104
+
105
+ return this.__postPutDeleteMethod(options, data);
106
+ }
107
+
108
+ __postPutDeleteMethod(options, data) {
109
+ return new Promise((resolve, reject) => {
110
+ const req = https.request(options, (res) => {
111
+ let body = [];
112
+ res.on("data", (d) => {
113
+ body.push(d);
114
+ });
115
+
116
+ res.on("end", () => {
117
+ try {
118
+ body = JSON.parse(Buffer.concat(body).toString());
119
+
120
+ if (res.headers.appidkey) {
121
+ this.__constants.AppIdKey = res.headers.appidkey;
122
+ }
123
+
124
+ if (res.statusCode === 200) {
125
+ resolve(body);
126
+ } else if (res.statusCode === 401 || res.statusCode === 403) {
127
+ try {
128
+ fs.unlinkSync(this.fileName);
129
+ } catch {
130
+ } finally {
131
+ reject(body);
132
+ }
133
+ } else {
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;
package/src/iniparser.js CHANGED
@@ -1,41 +1,42 @@
1
- const fs = require("fs");
2
- const ini = require("ini");
3
-
4
- BasePathLogin = "";
5
- BasePathEq = "";
6
- BasePathComm = "";
7
- BasePathMf = "";
8
- BasePathContent = "";
9
- ApiIdKey = "";
10
- LogLevel = "";
11
- hostName = "";
12
- port = "";
13
-
14
- const ConfigParser = function () {
15
- var config = ini.parse(fs.readFileSync("./conf/settings.ini", "utf-8"));
16
- BasePathLogin = config.GLOBAL.BasePathLogin;
17
- BasePathEq = config.GLOBAL.BasePathEq;
18
- BasePathComm = config.GLOBAL.BasePathComm;
19
- BasePathMf = config.GLOBAL.BasePathMf;
20
- BasePathContent = config.GLOBAL.BasePathContent;
21
- ApiIdKey = config.GLOBAL.ApiIdKey;
22
- LogLevel = config.GLOBAL.LogLevel;
23
- hostName = config.GLOBAL.hostName;
24
- port = config.GLOBAL.port;
25
- formFactor = config.GLOBAL.formFactor;
26
- };
27
-
28
- ConfigParser();
29
-
30
- module.exports = {
31
- BasePathLogin,
32
- BasePathEq,
33
- BasePathComm,
34
- BasePathMf,
35
- ApiIdKey,
36
- LogLevel,
37
- hostName,
38
- port,
39
- formFactor,
40
- BasePathContent,
41
- };
1
+ const fs = require("fs");
2
+ const ini = require("ini");
3
+
4
+ BasePathLogin = "";
5
+ BasePathEq = "";
6
+ BasePathComm = "";
7
+ BasePathMf = "";
8
+ BasePathContent = "";
9
+ ApiIdKey = "";
10
+ LogLevel = "";
11
+ hostName = "";
12
+ port = "";
13
+ formFactor = "";
14
+
15
+ const ConfigParser = function () {
16
+ var config = ini.parse(fs.readFileSync("./conf/settings.ini", "utf-8"));
17
+ BasePathLogin = config.GLOBAL.BasePathLogin;
18
+ BasePathEq = config.GLOBAL.BasePathEq;
19
+ BasePathComm = config.GLOBAL.BasePathComm;
20
+ BasePathMf = config.GLOBAL.BasePathMf;
21
+ BasePathContent = config.GLOBAL.BasePathContent;
22
+ ApiIdKey = config.GLOBAL.ApiIdKey;
23
+ LogLevel = config.GLOBAL.LogLevel;
24
+ hostName = config.STREAM.hostName;
25
+ port = config.STREAM.port;
26
+ formFactor = config.STREAM.formFactor;
27
+ };
28
+
29
+ ConfigParser();
30
+
31
+ module.exports = {
32
+ BasePathLogin,
33
+ BasePathEq,
34
+ BasePathComm,
35
+ BasePathMf,
36
+ ApiIdKey,
37
+ LogLevel,
38
+ hostName,
39
+ port,
40
+ formFactor,
41
+ BasePathContent,
42
+ };