api_connect_nodejs 2.0.1 → 2.0.2
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.
- package/README.md +30 -30
- package/conf/settings.ini +19 -19
- package/enums/actionType.js +10 -10
- package/enums/assetType.js +25 -25
- package/enums/chartExchangeType.js +15 -15
- package/enums/chartType.js +13 -13
- package/enums/eodIntervalType.js +11 -11
- package/enums/exchangeType.js +14 -14
- package/enums/intradayIntervalType.js +14 -14
- package/enums/marketCapType.js +12 -12
- package/enums/orderType.js +21 -21
- package/enums/productType.js +24 -24
- package/enums/segementsType.js +13 -13
- package/enums/streamingConstants.js +11 -11
- package/enums/termsType.js +12 -12
- package/enums/validity.js +22 -22
- package/index.js +3 -3
- package/package.json +25 -25
- package/src/apiConnect.js +2430 -2424
- package/src/apiUtils.js +129 -129
- package/src/chart.js +258 -258
- package/src/config.js +326 -326
- package/src/feed/feed.js +139 -139
- package/src/feed/liveNewsFeed.js +112 -112
- package/src/feed/ordersFeed.js +124 -124
- package/src/feed/quotesFeed.js +121 -121
- package/src/http.js +197 -197
- package/src/iniparser.js +42 -42
- package/src/liveNews.js +362 -362
- package/src/logger.js +16 -16
- package/src/order.js +48 -48
- package/src/researchCalls.js +175 -175
- package/src/watchlist.js +378 -378
- package/validations/apiConnectValidator.js +508 -508
- package/validations/chartValidator.js +85 -85
- package/validations/feedStreamerValidator.js +68 -68
- package/validations/liveNewsValidator.js +60 -60
- package/validations/researchCallsValidator.js +86 -86
- package/validations/watchlistValidator.js +60 -60
package/src/watchlist.js
CHANGED
|
@@ -1,378 +1,378 @@
|
|
|
1
|
-
const log4js = require("./logger.js");
|
|
2
|
-
const {
|
|
3
|
-
validateGetWatchlistScrips,
|
|
4
|
-
validateGroupNameAndSymbolList,
|
|
5
|
-
validateDeleteWatchlistGroups,
|
|
6
|
-
} = require("../validations/watchlistValidator");
|
|
7
|
-
class Watchlist {
|
|
8
|
-
constructor(http, config, constants) {
|
|
9
|
-
this.__http = http;
|
|
10
|
-
this.__config = config;
|
|
11
|
-
this.__constants = constants;
|
|
12
|
-
this.accId = "";
|
|
13
|
-
this.accType = "";
|
|
14
|
-
this.profileId = "";
|
|
15
|
-
this.getUserAccData();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
//Return Watchlist Formatted Response
|
|
19
|
-
watchlistFormattedResponse = (res) => {
|
|
20
|
-
log4js.debug("Inside watchlistFormattedResponse ");
|
|
21
|
-
let response = {};
|
|
22
|
-
response["msgID"] = res.msgID;
|
|
23
|
-
response["srvTm"] = res.srvTm;
|
|
24
|
-
response["data"] = res.data;
|
|
25
|
-
log4js.debug("getWatchlistGroups formatted response - " + response);
|
|
26
|
-
return response;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
//Get User Account Data
|
|
30
|
-
getUserAccData = () => {
|
|
31
|
-
//If user has eq acc id (acc type is EQ or COMEQ)
|
|
32
|
-
if (this.__constants.eqAccId.length > 0) {
|
|
33
|
-
this.accId = this.__constants.eqAccId;
|
|
34
|
-
this.accType = "EQ";
|
|
35
|
-
} else {
|
|
36
|
-
//if user has co acc id (acc type is CO)
|
|
37
|
-
this.accId = this.__constants.coAccId;
|
|
38
|
-
this.accType = "CO";
|
|
39
|
-
}
|
|
40
|
-
this.profileId = this.__constants.profileId;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Retrieving watchlist for a particular client
|
|
45
|
-
* @function getWatchlistGroups
|
|
46
|
-
* @returns All groups
|
|
47
|
-
*/
|
|
48
|
-
getWatchlistGroups = async () => {
|
|
49
|
-
let response = {};
|
|
50
|
-
try {
|
|
51
|
-
const url = this.__config.getWatchlistGroupsUrl(this.accId, this.accType);
|
|
52
|
-
log4js.debug("getWatchlistGroups url - " + url);
|
|
53
|
-
|
|
54
|
-
const res = await this.__http.GetMethod(url);
|
|
55
|
-
log4js.debug("getWatchlistGroups response - " + res);
|
|
56
|
-
if (Object.keys(res).length !== 0 && res.hasOwnProperty("data")) {
|
|
57
|
-
response = this.watchlistFormattedResponse(res);
|
|
58
|
-
} else {
|
|
59
|
-
response = res;
|
|
60
|
-
}
|
|
61
|
-
} catch (error) {
|
|
62
|
-
log4js.debug("getWatchlistGroups error - " + error);
|
|
63
|
-
return Promise.reject(error);
|
|
64
|
-
}
|
|
65
|
-
return response;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Retrieving symbol details of a watchlist
|
|
70
|
-
* @function getWatchlistGroups
|
|
71
|
-
* @returns All scrips of Group
|
|
72
|
-
*/
|
|
73
|
-
getWatchlistScrips = async (grpNm) => {
|
|
74
|
-
let response = {};
|
|
75
|
-
try {
|
|
76
|
-
// Validation
|
|
77
|
-
const validateResponse = validateGetWatchlistScrips(grpNm);
|
|
78
|
-
if (validateResponse.error) {
|
|
79
|
-
log4js.debug(
|
|
80
|
-
"getWatchlistScrips validation error -" +
|
|
81
|
-
validateResponse.error.details
|
|
82
|
-
);
|
|
83
|
-
return Promise.reject(validateResponse.error.details);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const url = this.__config.getWatchlistScripsUrl(
|
|
87
|
-
this.accId,
|
|
88
|
-
this.accType,
|
|
89
|
-
this.profileId,
|
|
90
|
-
grpNm
|
|
91
|
-
);
|
|
92
|
-
log4js.debug("getWatchlistScrips url - " + url);
|
|
93
|
-
|
|
94
|
-
const res = await this.__http.GetMethod(url);
|
|
95
|
-
if (Object.keys(res).length !== 0 && res.hasOwnProperty("data")) {
|
|
96
|
-
response = this.watchlistFormattedResponse(res);
|
|
97
|
-
} else {
|
|
98
|
-
response = res;
|
|
99
|
-
}
|
|
100
|
-
log4js.debug("getWatchlistScrips response - " + response);
|
|
101
|
-
} catch (error) {
|
|
102
|
-
log4js.debug("getWatchlistScrips error - " + error);
|
|
103
|
-
return Promise.reject(error);
|
|
104
|
-
}
|
|
105
|
-
return response;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
//Create RequestBody
|
|
109
|
-
createWatchlistGroupRequestBody = (
|
|
110
|
-
accId,
|
|
111
|
-
accType,
|
|
112
|
-
profileId,
|
|
113
|
-
grpNm,
|
|
114
|
-
symLst
|
|
115
|
-
) => {
|
|
116
|
-
return {
|
|
117
|
-
accId: accId,
|
|
118
|
-
accTyp: accType,
|
|
119
|
-
prfId: profileId,
|
|
120
|
-
grpNm: grpNm,
|
|
121
|
-
symLst: symLst,
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
createWatchlistGroup = async (grpNm, symLst) => {
|
|
126
|
-
let response = {};
|
|
127
|
-
try {
|
|
128
|
-
// Validation
|
|
129
|
-
const validateResponse = validateGroupNameAndSymbolList(grpNm, symLst);
|
|
130
|
-
if (validateResponse.error) {
|
|
131
|
-
log4js.debug(
|
|
132
|
-
"createWatchlistGroup validation error -" +
|
|
133
|
-
validateResponse.error.details
|
|
134
|
-
);
|
|
135
|
-
console.log(validateResponse.error.details);
|
|
136
|
-
return Promise.reject(validateResponse.error.details);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const url = this.__config.watchlistGroupUrl(grpNm);
|
|
140
|
-
log4js.debug("createWatchlistGroup url - " + url);
|
|
141
|
-
|
|
142
|
-
const requestBody = this.createWatchlistGroupRequestBody(
|
|
143
|
-
this.accId,
|
|
144
|
-
this.accType,
|
|
145
|
-
this.profileId,
|
|
146
|
-
grpNm,
|
|
147
|
-
symLst
|
|
148
|
-
);
|
|
149
|
-
const res = await this.__http.PostMethod(url, requestBody);
|
|
150
|
-
if (Object.keys(res).length !== 0 && res.hasOwnProperty("data")) {
|
|
151
|
-
response = this.watchlistFormattedResponse(res);
|
|
152
|
-
} else {
|
|
153
|
-
response = res;
|
|
154
|
-
}
|
|
155
|
-
log4js.debug("createWatchlistGroup response - " + response);
|
|
156
|
-
} catch (error) {
|
|
157
|
-
log4js.debug("createWatchlistGroup error - " + error);
|
|
158
|
-
return Promise.reject(error);
|
|
159
|
-
}
|
|
160
|
-
return response;
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
//Get Current Unix Time Stamp
|
|
164
|
-
getCurrentUnixTimeStamp = () => {
|
|
165
|
-
const ts = Math.round(new Date().getTime());
|
|
166
|
-
return ts;
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
actionWiseWatchlistRequestBody = (
|
|
170
|
-
accId,
|
|
171
|
-
accType,
|
|
172
|
-
grpNm,
|
|
173
|
-
symLst,
|
|
174
|
-
prfId,
|
|
175
|
-
newGroupName,
|
|
176
|
-
modifyAction
|
|
177
|
-
) => {
|
|
178
|
-
const uts = this.getCurrentUnixTimeStamp();
|
|
179
|
-
let requestBody = {
|
|
180
|
-
accId: accId,
|
|
181
|
-
accTyp: accType,
|
|
182
|
-
act: modifyAction,
|
|
183
|
-
grpNm: grpNm,
|
|
184
|
-
symLst: symLst,
|
|
185
|
-
updatedOn: uts,
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
if (modifyAction === "add") {
|
|
189
|
-
requestBody["prfId"] = prfId;
|
|
190
|
-
} else if (modifyAction === "modify") {
|
|
191
|
-
requestBody["newGrpNm"] = newGroupName;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return requestBody;
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
addSymbolWatchlist = async (grpNm, symLst) => {
|
|
198
|
-
let response = {};
|
|
199
|
-
try {
|
|
200
|
-
// Validation
|
|
201
|
-
const validateResponse = validateGroupNameAndSymbolList(grpNm, symLst);
|
|
202
|
-
if (validateResponse.error) {
|
|
203
|
-
log4js.debug(
|
|
204
|
-
"addSymbolWatchlist validation error -" +
|
|
205
|
-
validateResponse.error.details
|
|
206
|
-
);
|
|
207
|
-
console.log(validateResponse.error.details);
|
|
208
|
-
return Promise.reject(validateResponse.error.details);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
const url = this.__config.watchlistGroupUrl(grpNm);
|
|
212
|
-
log4js.debug("addSymbolWatchlist url - " + url);
|
|
213
|
-
|
|
214
|
-
const requestBody = this.actionWiseWatchlistRequestBody(
|
|
215
|
-
this.accId,
|
|
216
|
-
this.accType,
|
|
217
|
-
grpNm,
|
|
218
|
-
symLst,
|
|
219
|
-
null,
|
|
220
|
-
null,
|
|
221
|
-
"add"
|
|
222
|
-
);
|
|
223
|
-
|
|
224
|
-
const res = await this.__http.PutMethod(url, requestBody);
|
|
225
|
-
if (Object.keys(res).length !== 0 && res.hasOwnProperty("data")) {
|
|
226
|
-
response = this.watchlistFormattedResponse(res);
|
|
227
|
-
} else {
|
|
228
|
-
response = res;
|
|
229
|
-
}
|
|
230
|
-
log4js.debug("addSymbolWatchlist response - " + response);
|
|
231
|
-
} catch (error) {
|
|
232
|
-
log4js.debug("addSymbolWatchlist error - " + error);
|
|
233
|
-
return Promise.reject(error);
|
|
234
|
-
}
|
|
235
|
-
return response;
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
deleteSymbolWatchlist = async (grpNm, symLst) => {
|
|
239
|
-
let response = {};
|
|
240
|
-
try {
|
|
241
|
-
// Validation
|
|
242
|
-
const validateResponse = validateGroupNameAndSymbolList(grpNm, symLst);
|
|
243
|
-
if (validateResponse.error) {
|
|
244
|
-
log4js.debug(
|
|
245
|
-
"deleteSymbolWatchlist validation error -" +
|
|
246
|
-
validateResponse.error.details
|
|
247
|
-
);
|
|
248
|
-
console.log(validateResponse.error.details);
|
|
249
|
-
return Promise.reject(validateResponse.error.details);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const url = this.__config.watchlistGroupUrl(grpNm);
|
|
253
|
-
log4js.debug("deleteSymbolWatchlist url - " + url);
|
|
254
|
-
|
|
255
|
-
const requestBody = this.actionWiseWatchlistRequestBody(
|
|
256
|
-
this.accId,
|
|
257
|
-
this.accType,
|
|
258
|
-
grpNm,
|
|
259
|
-
symLst,
|
|
260
|
-
null,
|
|
261
|
-
null,
|
|
262
|
-
"del"
|
|
263
|
-
);
|
|
264
|
-
|
|
265
|
-
const res = await this.__http.PutMethod(url, requestBody);
|
|
266
|
-
if (Object.keys(res).length !== 0 && res.hasOwnProperty("data")) {
|
|
267
|
-
response = this.watchlistFormattedResponse(res);
|
|
268
|
-
} else {
|
|
269
|
-
response = res;
|
|
270
|
-
}
|
|
271
|
-
log4js.debug("DeleteSymbolWatchlist response - " + response);
|
|
272
|
-
} catch (error) {
|
|
273
|
-
log4js.debug("DeleteSymbolWatchlist error - " + error);
|
|
274
|
-
return Promise.reject(error);
|
|
275
|
-
}
|
|
276
|
-
return response;
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
deleteWatchlistGroups = async (groups) => {
|
|
280
|
-
let response = {};
|
|
281
|
-
try {
|
|
282
|
-
// Validation
|
|
283
|
-
const validateResponse = validateDeleteWatchlistGroups(groups);
|
|
284
|
-
if (validateResponse.error) {
|
|
285
|
-
log4js.debug(
|
|
286
|
-
"deleteWatchlistGroups validation error -" +
|
|
287
|
-
validateResponse.error.details
|
|
288
|
-
);
|
|
289
|
-
console.log(validateResponse.error.details);
|
|
290
|
-
return Promise.reject(validateResponse.error.details);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
const url = this.__config.deleteWatchlistgroups();
|
|
294
|
-
log4js.debug("deleteWatchlistGroups url - " + url);
|
|
295
|
-
|
|
296
|
-
const requestBody = {
|
|
297
|
-
accId: this.accId,
|
|
298
|
-
prfID: this.profileId,
|
|
299
|
-
accTyp: this.accType,
|
|
300
|
-
delGrp: groups,
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
const res = await this.__http.DeleteMethod(url, requestBody);
|
|
304
|
-
if (Object.keys(res).length !== 0 && res.hasOwnProperty("data")) {
|
|
305
|
-
response = this.watchlistFormattedResponse(res);
|
|
306
|
-
} else {
|
|
307
|
-
response = res;
|
|
308
|
-
}
|
|
309
|
-
log4js.debug("deleteWatchlistGroups response - " + response);
|
|
310
|
-
} catch (error) {
|
|
311
|
-
log4js.debug("deleteWatchlistGroups error - " + error);
|
|
312
|
-
return Promise.reject(error);
|
|
313
|
-
}
|
|
314
|
-
return response;
|
|
315
|
-
};
|
|
316
|
-
|
|
317
|
-
//Rename watchlist group
|
|
318
|
-
renameWatchlistGroup = async (grpNm, newGrpNm) => {
|
|
319
|
-
let response = {};
|
|
320
|
-
log4js.debug("inside renameWatchlistGroup method");
|
|
321
|
-
try {
|
|
322
|
-
// Validation
|
|
323
|
-
const validateResponse = validateRenameGroup(grpNm, newGrpNm);
|
|
324
|
-
if (validateResponse.error) {
|
|
325
|
-
log4js.debug(
|
|
326
|
-
"renameWatchlistGroup validation error -" +
|
|
327
|
-
validateResponse.error.details
|
|
328
|
-
);
|
|
329
|
-
return Promise.reject(validateResponse.error.details);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
const oldGroupSymbolsResponse = await this.getWatchlistScrips(grpNm);
|
|
333
|
-
let oldSymbols = [];
|
|
334
|
-
|
|
335
|
-
if (
|
|
336
|
-
Object.keys(oldGroupSymbolsResponse).length !== 0 &&
|
|
337
|
-
oldGroupSymbolsResponse.hasOwnProperty("data") &&
|
|
338
|
-
oldGroupSymbolsResponse.data.hasOwnProperty("syLst")
|
|
339
|
-
) {
|
|
340
|
-
oldSymbols = oldGroupSymbolsResponse.data.syLst.map((item) => {
|
|
341
|
-
return item.sym;
|
|
342
|
-
});
|
|
343
|
-
} else {
|
|
344
|
-
return Promise.reject(
|
|
345
|
-
"Failed to retrieve old group data. Please try again."
|
|
346
|
-
);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
const url = this.__config.watchlistGroupUrl(grpNm);
|
|
350
|
-
log4js.debug("renameWatchlistGroup url - " + url);
|
|
351
|
-
|
|
352
|
-
const requestBody = {
|
|
353
|
-
accId: this.accId,
|
|
354
|
-
accTyp: this.accType,
|
|
355
|
-
act: "modify",
|
|
356
|
-
grpNm: grpNm,
|
|
357
|
-
newGrpNm: newGrpNm,
|
|
358
|
-
symLst: oldSymbols,
|
|
359
|
-
updatedOn: this.getCurrentUnixTimeStamp(),
|
|
360
|
-
};
|
|
361
|
-
log4js.debug("renameWatchlistGroup requestBody - " + requestBody);
|
|
362
|
-
|
|
363
|
-
const res = await this.__http.PutMethod(url, requestBody);
|
|
364
|
-
if (Object.keys(res).length === 0 && res.hasOwnProperty("data")) {
|
|
365
|
-
response = this.watchlistFormattedResponse(res);
|
|
366
|
-
} else {
|
|
367
|
-
response = res;
|
|
368
|
-
}
|
|
369
|
-
log4js.debug("renameWatchlistGroup response - " + response);
|
|
370
|
-
} catch (error) {
|
|
371
|
-
log4js.debug("renameWatchlistGroup error - " + error);
|
|
372
|
-
return Promise.reject(error);
|
|
373
|
-
}
|
|
374
|
-
return response;
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
module.exports = Watchlist;
|
|
1
|
+
const log4js = require("./logger.js");
|
|
2
|
+
const {
|
|
3
|
+
validateGetWatchlistScrips,
|
|
4
|
+
validateGroupNameAndSymbolList,
|
|
5
|
+
validateDeleteWatchlistGroups,
|
|
6
|
+
} = require("../validations/watchlistValidator");
|
|
7
|
+
class Watchlist {
|
|
8
|
+
constructor(http, config, constants) {
|
|
9
|
+
this.__http = http;
|
|
10
|
+
this.__config = config;
|
|
11
|
+
this.__constants = constants;
|
|
12
|
+
this.accId = "";
|
|
13
|
+
this.accType = "";
|
|
14
|
+
this.profileId = "";
|
|
15
|
+
this.getUserAccData();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//Return Watchlist Formatted Response
|
|
19
|
+
watchlistFormattedResponse = (res) => {
|
|
20
|
+
log4js.debug("Inside watchlistFormattedResponse ");
|
|
21
|
+
let response = {};
|
|
22
|
+
response["msgID"] = res.msgID;
|
|
23
|
+
response["srvTm"] = res.srvTm;
|
|
24
|
+
response["data"] = res.data;
|
|
25
|
+
log4js.debug("getWatchlistGroups formatted response - " + response);
|
|
26
|
+
return response;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
//Get User Account Data
|
|
30
|
+
getUserAccData = () => {
|
|
31
|
+
//If user has eq acc id (acc type is EQ or COMEQ)
|
|
32
|
+
if (this.__constants.eqAccId.length > 0) {
|
|
33
|
+
this.accId = this.__constants.eqAccId;
|
|
34
|
+
this.accType = "EQ";
|
|
35
|
+
} else {
|
|
36
|
+
//if user has co acc id (acc type is CO)
|
|
37
|
+
this.accId = this.__constants.coAccId;
|
|
38
|
+
this.accType = "CO";
|
|
39
|
+
}
|
|
40
|
+
this.profileId = this.__constants.profileId;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Retrieving watchlist for a particular client
|
|
45
|
+
* @function getWatchlistGroups
|
|
46
|
+
* @returns All groups
|
|
47
|
+
*/
|
|
48
|
+
getWatchlistGroups = async () => {
|
|
49
|
+
let response = {};
|
|
50
|
+
try {
|
|
51
|
+
const url = this.__config.getWatchlistGroupsUrl(this.accId, this.accType);
|
|
52
|
+
log4js.debug("getWatchlistGroups url - " + url);
|
|
53
|
+
|
|
54
|
+
const res = await this.__http.GetMethod(url);
|
|
55
|
+
log4js.debug("getWatchlistGroups response - " + res);
|
|
56
|
+
if (Object.keys(res).length !== 0 && res.hasOwnProperty("data")) {
|
|
57
|
+
response = this.watchlistFormattedResponse(res);
|
|
58
|
+
} else {
|
|
59
|
+
response = res;
|
|
60
|
+
}
|
|
61
|
+
} catch (error) {
|
|
62
|
+
log4js.debug("getWatchlistGroups error - " + error);
|
|
63
|
+
return Promise.reject(error);
|
|
64
|
+
}
|
|
65
|
+
return response;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Retrieving symbol details of a watchlist
|
|
70
|
+
* @function getWatchlistGroups
|
|
71
|
+
* @returns All scrips of Group
|
|
72
|
+
*/
|
|
73
|
+
getWatchlistScrips = async (grpNm) => {
|
|
74
|
+
let response = {};
|
|
75
|
+
try {
|
|
76
|
+
// Validation
|
|
77
|
+
const validateResponse = validateGetWatchlistScrips(grpNm);
|
|
78
|
+
if (validateResponse.error) {
|
|
79
|
+
log4js.debug(
|
|
80
|
+
"getWatchlistScrips validation error -" +
|
|
81
|
+
validateResponse.error.details
|
|
82
|
+
);
|
|
83
|
+
return Promise.reject(validateResponse.error.details);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const url = this.__config.getWatchlistScripsUrl(
|
|
87
|
+
this.accId,
|
|
88
|
+
this.accType,
|
|
89
|
+
this.profileId,
|
|
90
|
+
grpNm
|
|
91
|
+
);
|
|
92
|
+
log4js.debug("getWatchlistScrips url - " + url);
|
|
93
|
+
|
|
94
|
+
const res = await this.__http.GetMethod(url);
|
|
95
|
+
if (Object.keys(res).length !== 0 && res.hasOwnProperty("data")) {
|
|
96
|
+
response = this.watchlistFormattedResponse(res);
|
|
97
|
+
} else {
|
|
98
|
+
response = res;
|
|
99
|
+
}
|
|
100
|
+
log4js.debug("getWatchlistScrips response - " + response);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
log4js.debug("getWatchlistScrips error - " + error);
|
|
103
|
+
return Promise.reject(error);
|
|
104
|
+
}
|
|
105
|
+
return response;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
//Create RequestBody
|
|
109
|
+
createWatchlistGroupRequestBody = (
|
|
110
|
+
accId,
|
|
111
|
+
accType,
|
|
112
|
+
profileId,
|
|
113
|
+
grpNm,
|
|
114
|
+
symLst
|
|
115
|
+
) => {
|
|
116
|
+
return {
|
|
117
|
+
accId: accId,
|
|
118
|
+
accTyp: accType,
|
|
119
|
+
prfId: profileId,
|
|
120
|
+
grpNm: grpNm,
|
|
121
|
+
symLst: symLst,
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
createWatchlistGroup = async (grpNm, symLst) => {
|
|
126
|
+
let response = {};
|
|
127
|
+
try {
|
|
128
|
+
// Validation
|
|
129
|
+
const validateResponse = validateGroupNameAndSymbolList(grpNm, symLst);
|
|
130
|
+
if (validateResponse.error) {
|
|
131
|
+
log4js.debug(
|
|
132
|
+
"createWatchlistGroup validation error -" +
|
|
133
|
+
validateResponse.error.details
|
|
134
|
+
);
|
|
135
|
+
console.log(validateResponse.error.details);
|
|
136
|
+
return Promise.reject(validateResponse.error.details);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const url = this.__config.watchlistGroupUrl(grpNm);
|
|
140
|
+
log4js.debug("createWatchlistGroup url - " + url);
|
|
141
|
+
|
|
142
|
+
const requestBody = this.createWatchlistGroupRequestBody(
|
|
143
|
+
this.accId,
|
|
144
|
+
this.accType,
|
|
145
|
+
this.profileId,
|
|
146
|
+
grpNm,
|
|
147
|
+
symLst
|
|
148
|
+
);
|
|
149
|
+
const res = await this.__http.PostMethod(url, requestBody);
|
|
150
|
+
if (Object.keys(res).length !== 0 && res.hasOwnProperty("data")) {
|
|
151
|
+
response = this.watchlistFormattedResponse(res);
|
|
152
|
+
} else {
|
|
153
|
+
response = res;
|
|
154
|
+
}
|
|
155
|
+
log4js.debug("createWatchlistGroup response - " + response);
|
|
156
|
+
} catch (error) {
|
|
157
|
+
log4js.debug("createWatchlistGroup error - " + error);
|
|
158
|
+
return Promise.reject(error);
|
|
159
|
+
}
|
|
160
|
+
return response;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
//Get Current Unix Time Stamp
|
|
164
|
+
getCurrentUnixTimeStamp = () => {
|
|
165
|
+
const ts = Math.round(new Date().getTime());
|
|
166
|
+
return ts;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
actionWiseWatchlistRequestBody = (
|
|
170
|
+
accId,
|
|
171
|
+
accType,
|
|
172
|
+
grpNm,
|
|
173
|
+
symLst,
|
|
174
|
+
prfId,
|
|
175
|
+
newGroupName,
|
|
176
|
+
modifyAction
|
|
177
|
+
) => {
|
|
178
|
+
const uts = this.getCurrentUnixTimeStamp();
|
|
179
|
+
let requestBody = {
|
|
180
|
+
accId: accId,
|
|
181
|
+
accTyp: accType,
|
|
182
|
+
act: modifyAction,
|
|
183
|
+
grpNm: grpNm,
|
|
184
|
+
symLst: symLst,
|
|
185
|
+
updatedOn: uts,
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
if (modifyAction === "add") {
|
|
189
|
+
requestBody["prfId"] = prfId;
|
|
190
|
+
} else if (modifyAction === "modify") {
|
|
191
|
+
requestBody["newGrpNm"] = newGroupName;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return requestBody;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
addSymbolWatchlist = async (grpNm, symLst) => {
|
|
198
|
+
let response = {};
|
|
199
|
+
try {
|
|
200
|
+
// Validation
|
|
201
|
+
const validateResponse = validateGroupNameAndSymbolList(grpNm, symLst);
|
|
202
|
+
if (validateResponse.error) {
|
|
203
|
+
log4js.debug(
|
|
204
|
+
"addSymbolWatchlist validation error -" +
|
|
205
|
+
validateResponse.error.details
|
|
206
|
+
);
|
|
207
|
+
console.log(validateResponse.error.details);
|
|
208
|
+
return Promise.reject(validateResponse.error.details);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const url = this.__config.watchlistGroupUrl(grpNm);
|
|
212
|
+
log4js.debug("addSymbolWatchlist url - " + url);
|
|
213
|
+
|
|
214
|
+
const requestBody = this.actionWiseWatchlistRequestBody(
|
|
215
|
+
this.accId,
|
|
216
|
+
this.accType,
|
|
217
|
+
grpNm,
|
|
218
|
+
symLst,
|
|
219
|
+
null,
|
|
220
|
+
null,
|
|
221
|
+
"add"
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
const res = await this.__http.PutMethod(url, requestBody);
|
|
225
|
+
if (Object.keys(res).length !== 0 && res.hasOwnProperty("data")) {
|
|
226
|
+
response = this.watchlistFormattedResponse(res);
|
|
227
|
+
} else {
|
|
228
|
+
response = res;
|
|
229
|
+
}
|
|
230
|
+
log4js.debug("addSymbolWatchlist response - " + response);
|
|
231
|
+
} catch (error) {
|
|
232
|
+
log4js.debug("addSymbolWatchlist error - " + error);
|
|
233
|
+
return Promise.reject(error);
|
|
234
|
+
}
|
|
235
|
+
return response;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
deleteSymbolWatchlist = async (grpNm, symLst) => {
|
|
239
|
+
let response = {};
|
|
240
|
+
try {
|
|
241
|
+
// Validation
|
|
242
|
+
const validateResponse = validateGroupNameAndSymbolList(grpNm, symLst);
|
|
243
|
+
if (validateResponse.error) {
|
|
244
|
+
log4js.debug(
|
|
245
|
+
"deleteSymbolWatchlist validation error -" +
|
|
246
|
+
validateResponse.error.details
|
|
247
|
+
);
|
|
248
|
+
console.log(validateResponse.error.details);
|
|
249
|
+
return Promise.reject(validateResponse.error.details);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const url = this.__config.watchlistGroupUrl(grpNm);
|
|
253
|
+
log4js.debug("deleteSymbolWatchlist url - " + url);
|
|
254
|
+
|
|
255
|
+
const requestBody = this.actionWiseWatchlistRequestBody(
|
|
256
|
+
this.accId,
|
|
257
|
+
this.accType,
|
|
258
|
+
grpNm,
|
|
259
|
+
symLst,
|
|
260
|
+
null,
|
|
261
|
+
null,
|
|
262
|
+
"del"
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
const res = await this.__http.PutMethod(url, requestBody);
|
|
266
|
+
if (Object.keys(res).length !== 0 && res.hasOwnProperty("data")) {
|
|
267
|
+
response = this.watchlistFormattedResponse(res);
|
|
268
|
+
} else {
|
|
269
|
+
response = res;
|
|
270
|
+
}
|
|
271
|
+
log4js.debug("DeleteSymbolWatchlist response - " + response);
|
|
272
|
+
} catch (error) {
|
|
273
|
+
log4js.debug("DeleteSymbolWatchlist error - " + error);
|
|
274
|
+
return Promise.reject(error);
|
|
275
|
+
}
|
|
276
|
+
return response;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
deleteWatchlistGroups = async (groups) => {
|
|
280
|
+
let response = {};
|
|
281
|
+
try {
|
|
282
|
+
// Validation
|
|
283
|
+
const validateResponse = validateDeleteWatchlistGroups(groups);
|
|
284
|
+
if (validateResponse.error) {
|
|
285
|
+
log4js.debug(
|
|
286
|
+
"deleteWatchlistGroups validation error -" +
|
|
287
|
+
validateResponse.error.details
|
|
288
|
+
);
|
|
289
|
+
console.log(validateResponse.error.details);
|
|
290
|
+
return Promise.reject(validateResponse.error.details);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const url = this.__config.deleteWatchlistgroups();
|
|
294
|
+
log4js.debug("deleteWatchlistGroups url - " + url);
|
|
295
|
+
|
|
296
|
+
const requestBody = {
|
|
297
|
+
accId: this.accId,
|
|
298
|
+
prfID: this.profileId,
|
|
299
|
+
accTyp: this.accType,
|
|
300
|
+
delGrp: groups,
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
const res = await this.__http.DeleteMethod(url, requestBody);
|
|
304
|
+
if (Object.keys(res).length !== 0 && res.hasOwnProperty("data")) {
|
|
305
|
+
response = this.watchlistFormattedResponse(res);
|
|
306
|
+
} else {
|
|
307
|
+
response = res;
|
|
308
|
+
}
|
|
309
|
+
log4js.debug("deleteWatchlistGroups response - " + response);
|
|
310
|
+
} catch (error) {
|
|
311
|
+
log4js.debug("deleteWatchlistGroups error - " + error);
|
|
312
|
+
return Promise.reject(error);
|
|
313
|
+
}
|
|
314
|
+
return response;
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
//Rename watchlist group
|
|
318
|
+
renameWatchlistGroup = async (grpNm, newGrpNm) => {
|
|
319
|
+
let response = {};
|
|
320
|
+
log4js.debug("inside renameWatchlistGroup method");
|
|
321
|
+
try {
|
|
322
|
+
// Validation
|
|
323
|
+
const validateResponse = validateRenameGroup(grpNm, newGrpNm);
|
|
324
|
+
if (validateResponse.error) {
|
|
325
|
+
log4js.debug(
|
|
326
|
+
"renameWatchlistGroup validation error -" +
|
|
327
|
+
validateResponse.error.details
|
|
328
|
+
);
|
|
329
|
+
return Promise.reject(validateResponse.error.details);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const oldGroupSymbolsResponse = await this.getWatchlistScrips(grpNm);
|
|
333
|
+
let oldSymbols = [];
|
|
334
|
+
|
|
335
|
+
if (
|
|
336
|
+
Object.keys(oldGroupSymbolsResponse).length !== 0 &&
|
|
337
|
+
oldGroupSymbolsResponse.hasOwnProperty("data") &&
|
|
338
|
+
oldGroupSymbolsResponse.data.hasOwnProperty("syLst")
|
|
339
|
+
) {
|
|
340
|
+
oldSymbols = oldGroupSymbolsResponse.data.syLst.map((item) => {
|
|
341
|
+
return item.sym;
|
|
342
|
+
});
|
|
343
|
+
} else {
|
|
344
|
+
return Promise.reject(
|
|
345
|
+
"Failed to retrieve old group data. Please try again."
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const url = this.__config.watchlistGroupUrl(grpNm);
|
|
350
|
+
log4js.debug("renameWatchlistGroup url - " + url);
|
|
351
|
+
|
|
352
|
+
const requestBody = {
|
|
353
|
+
accId: this.accId,
|
|
354
|
+
accTyp: this.accType,
|
|
355
|
+
act: "modify",
|
|
356
|
+
grpNm: grpNm,
|
|
357
|
+
newGrpNm: newGrpNm,
|
|
358
|
+
symLst: oldSymbols,
|
|
359
|
+
updatedOn: this.getCurrentUnixTimeStamp(),
|
|
360
|
+
};
|
|
361
|
+
log4js.debug("renameWatchlistGroup requestBody - " + requestBody);
|
|
362
|
+
|
|
363
|
+
const res = await this.__http.PutMethod(url, requestBody);
|
|
364
|
+
if (Object.keys(res).length === 0 && res.hasOwnProperty("data")) {
|
|
365
|
+
response = this.watchlistFormattedResponse(res);
|
|
366
|
+
} else {
|
|
367
|
+
response = res;
|
|
368
|
+
}
|
|
369
|
+
log4js.debug("renameWatchlistGroup response - " + response);
|
|
370
|
+
} catch (error) {
|
|
371
|
+
log4js.debug("renameWatchlistGroup error - " + error);
|
|
372
|
+
return Promise.reject(error);
|
|
373
|
+
}
|
|
374
|
+
return response;
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
module.exports = Watchlist;
|