api_connect_nodejs 2.0.2 → 2.0.5
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 +14 -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 +2397 -2430
- package/src/apiUtils.js +221 -129
- package/src/chart.js +258 -258
- package/src/config.js +321 -326
- package/src/feed/depthFeed.js +137 -0
- package/src/feed/feed.js +162 -139
- package/src/feed/liveNewsFeed.js +112 -112
- package/src/feed/miniQuoteFeed.js +121 -0
- package/src/feed/ordersFeed.js +124 -124
- package/src/feed/quotesFeed.js +226 -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/quote.js +75 -0
- package/src/researchCalls.js +175 -175
- package/src/watchlist.js +378 -378
- package/validations/apiConnectValidator.js +521 -508
- package/validations/chartValidator.js +85 -85
- package/validations/feedStreamerValidator.js +162 -68
- package/validations/liveNewsValidator.js +60 -60
- package/validations/quoteValidator.js +19 -0
- package/validations/researchCallsValidator.js +86 -86
- package/validations/watchlistValidator.js +60 -60
package/src/liveNews.js
CHANGED
|
@@ -1,362 +1,362 @@
|
|
|
1
|
-
const log4js = require("./logger.js");
|
|
2
|
-
class LiveNews {
|
|
3
|
-
constructor(fileName, http, config, constants) {
|
|
4
|
-
this.fileName = fileName;
|
|
5
|
-
this.__http = http;
|
|
6
|
-
this.__config = config;
|
|
7
|
-
this.__constants = constants;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
//Get News Categories Data
|
|
11
|
-
getNewsCategoriesData = async () => {
|
|
12
|
-
let newsCategories = {};
|
|
13
|
-
try {
|
|
14
|
-
const fileExist = this.__constants.fileExistOrNot(this.fileName);
|
|
15
|
-
if (fileExist) {
|
|
16
|
-
newsCategories = {};
|
|
17
|
-
const obj = this.__constants.readFile(this.fileName);
|
|
18
|
-
let jsonObj = JSON.parse(obj);
|
|
19
|
-
if (jsonObj.hasOwnProperty("newsCategories")) {
|
|
20
|
-
newsCategories = jsonObj["newsCategories"];
|
|
21
|
-
} else {
|
|
22
|
-
const url = this.__config.LiveNewsURL();
|
|
23
|
-
newsCategories = await this.__http.GetMethod(url);
|
|
24
|
-
if (Object.keys(newsCategories).length !== 0) {
|
|
25
|
-
jsonObj["newsCategories"] = newsCategories;
|
|
26
|
-
this.__constants.writeInFile(
|
|
27
|
-
this.fileName,
|
|
28
|
-
JSON.stringify(jsonObj)
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
} catch (error) {
|
|
34
|
-
log4js.debug("error - " + error);
|
|
35
|
-
}
|
|
36
|
-
return newsCategories;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
//Return filteredCategories and with exc and inc categories
|
|
40
|
-
filterNewsCategories = async (response, filter) => {
|
|
41
|
-
const finalResponse = {};
|
|
42
|
-
let filteredCategories = [];
|
|
43
|
-
let excAndincCategories = {};
|
|
44
|
-
|
|
45
|
-
//Exclude Categories
|
|
46
|
-
const excludeCategory = ["Results", "Stocks in News", "My Holdings"];
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
const data = response.data;
|
|
50
|
-
const allNews = data.newsFilters.concat(data.ctLst);
|
|
51
|
-
const filterNews = allNews.filter((item) => {
|
|
52
|
-
//exclude categories
|
|
53
|
-
if (!excludeCategory.includes(item.dpNm)) {
|
|
54
|
-
filteredCategories.push(item.dpNm);
|
|
55
|
-
if (item.hasOwnProperty("inc")) {
|
|
56
|
-
excAndincCategories[item.dpNm] = item.inc;
|
|
57
|
-
} else {
|
|
58
|
-
excAndincCategories[item.dpNm] = [item.cat];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
if (!filter) {
|
|
63
|
-
finalResponse["excAndincCategories"] = excAndincCategories;
|
|
64
|
-
}
|
|
65
|
-
finalResponse["categories"] = filteredCategories;
|
|
66
|
-
} catch (error) {
|
|
67
|
-
log4js.debug("error - " + error);
|
|
68
|
-
}
|
|
69
|
-
finalResponse["msgID"] = response.msgID;
|
|
70
|
-
finalResponse["srvTm"] = response.srvTm;
|
|
71
|
-
return finalResponse;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
//Get news categories data
|
|
75
|
-
getNewsCategories = async (filter = false) => {
|
|
76
|
-
let finalResponse = {};
|
|
77
|
-
try {
|
|
78
|
-
let newsCategories = await this.getNewsCategoriesData();
|
|
79
|
-
if (Object.keys(newsCategories).length !== 0) {
|
|
80
|
-
finalResponse["data"] = await this.filterNewsCategories(
|
|
81
|
-
newsCategories,
|
|
82
|
-
filter
|
|
83
|
-
);
|
|
84
|
-
} else {
|
|
85
|
-
finalResponse["data"] = newsCategories;
|
|
86
|
-
}
|
|
87
|
-
} catch (error) {
|
|
88
|
-
log4js.debug("error - " + error);
|
|
89
|
-
}
|
|
90
|
-
return finalResponse;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
getCategoryObject = async (category) => {
|
|
94
|
-
let object = {};
|
|
95
|
-
try {
|
|
96
|
-
const res = await this.getNewsCategoriesData();
|
|
97
|
-
if (res.hasOwnProperty("data")) {
|
|
98
|
-
const data = res.data;
|
|
99
|
-
const newsCategories = data.ctLst.concat(data.newsFilters);
|
|
100
|
-
let filterRes = newsCategories.filter((item) => item.dpNm === category);
|
|
101
|
-
object = filterRes[0];
|
|
102
|
-
}
|
|
103
|
-
} catch (error) {
|
|
104
|
-
return Promise.reject(error);
|
|
105
|
-
}
|
|
106
|
-
return object;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
getNewsRequestBody = async (category, searchText, pageNumber) => {
|
|
110
|
-
let requestBody = {};
|
|
111
|
-
try {
|
|
112
|
-
const response = await this.getCategoryObject(category);
|
|
113
|
-
if (Object.keys(response).length !== 0) {
|
|
114
|
-
if (response.hasOwnProperty("exc") && response.hasOwnProperty("inc")) {
|
|
115
|
-
requestBody["exclCategory"] = response.exc;
|
|
116
|
-
requestBody["inclCategory"] = response.inc;
|
|
117
|
-
requestBody["validRequest"] = response.lgrq;
|
|
118
|
-
requestBody["group"] = response.uiTyp;
|
|
119
|
-
} else {
|
|
120
|
-
requestBody["exclCategory"] = [];
|
|
121
|
-
requestBody["inclCategory"] = category;
|
|
122
|
-
requestBody["group"] = response.uiTyp;
|
|
123
|
-
}
|
|
124
|
-
requestBody["searchText"] = searchText;
|
|
125
|
-
requestBody["page"] = pageNumber;
|
|
126
|
-
}
|
|
127
|
-
} catch (error) {
|
|
128
|
-
return Promise.reject(error);
|
|
129
|
-
}
|
|
130
|
-
return requestBody;
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
getGeneralNewsData = async (category, searchText, pageNumber) => {
|
|
134
|
-
let result = {};
|
|
135
|
-
try {
|
|
136
|
-
const requestBody = await this.getNewsRequestBody(
|
|
137
|
-
category,
|
|
138
|
-
searchText,
|
|
139
|
-
pageNumber
|
|
140
|
-
);
|
|
141
|
-
const url = this.__config.GeneralLiveNewsURL();
|
|
142
|
-
const response = await this.__http.PostMethod(url, requestBody);
|
|
143
|
-
result = response;
|
|
144
|
-
} catch (error) {
|
|
145
|
-
return Promise.reject(error);
|
|
146
|
-
}
|
|
147
|
-
return result;
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
getEqHoldings = async (searchText, pageNumber) => {
|
|
151
|
-
let result = {};
|
|
152
|
-
try {
|
|
153
|
-
const requestBody = await this.getNewsRequestBody(
|
|
154
|
-
"My Holdings",
|
|
155
|
-
searchText,
|
|
156
|
-
pageNumber
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
const url = this.__config.NewsEqHoldingsURL();
|
|
160
|
-
const response = await this.__http.PostMethod(url, requestBody);
|
|
161
|
-
result = response;
|
|
162
|
-
} catch (error) {
|
|
163
|
-
return Promise.reject(error);
|
|
164
|
-
}
|
|
165
|
-
return result;
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
newsResponseBody = () => {
|
|
169
|
-
return {
|
|
170
|
-
data: {
|
|
171
|
-
content: [],
|
|
172
|
-
first: null,
|
|
173
|
-
last: null,
|
|
174
|
-
number: null,
|
|
175
|
-
size: null,
|
|
176
|
-
totalElements: null,
|
|
177
|
-
totalPages: null,
|
|
178
|
-
},
|
|
179
|
-
msgID: null,
|
|
180
|
-
srvTm: null,
|
|
181
|
-
};
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
filterLiveNewsResponse = (
|
|
185
|
-
category,
|
|
186
|
-
excAndincCategories,
|
|
187
|
-
response,
|
|
188
|
-
holdings
|
|
189
|
-
) => {
|
|
190
|
-
//Get Response Body
|
|
191
|
-
let responseBody = this.newsResponseBody();
|
|
192
|
-
|
|
193
|
-
let content = [];
|
|
194
|
-
const excludeCategory = ["Result", "STOCK_IN_NEWS", "My Holdings"];
|
|
195
|
-
if (response.hasOwnProperty("data")) {
|
|
196
|
-
const responseData = response.data;
|
|
197
|
-
responseBody.msgID = response.msgID;
|
|
198
|
-
responseBody.srvTm = response.srvTm;
|
|
199
|
-
if (responseData.hasOwnProperty("listResponse")) {
|
|
200
|
-
let data = responseBody.data;
|
|
201
|
-
const listResponse = responseData.listResponse;
|
|
202
|
-
if (listResponse.hasOwnProperty("content")) {
|
|
203
|
-
const responseContent = listResponse.content;
|
|
204
|
-
//If Holdings value is true
|
|
205
|
-
if (holdings) {
|
|
206
|
-
//In Response , we will not get categoryName "All", so we will return data wtihout filter
|
|
207
|
-
if (category === "All" || category === '') {
|
|
208
|
-
content = responseContent;
|
|
209
|
-
} else {
|
|
210
|
-
content = responseContent.filter((object) => {
|
|
211
|
-
if (excAndincCategories.includes(object.category)) {
|
|
212
|
-
return object;
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
} else {
|
|
217
|
-
//Holdings false and category "All" then exclude Result, STOCK_IN_NEWS and My Holdings
|
|
218
|
-
if (category === "All") {
|
|
219
|
-
content = responseContent.filter((object) => {
|
|
220
|
-
if (!excludeCategory.includes(object.category)) {
|
|
221
|
-
return object;
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
} else {
|
|
225
|
-
//Holdings false and category not All
|
|
226
|
-
content = responseContent;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
data.first = listResponse.first;
|
|
232
|
-
data.last = listResponse.last;
|
|
233
|
-
data.number = listResponse.number;
|
|
234
|
-
data.size = listResponse.size;
|
|
235
|
-
data.totalElements = listResponse.totalElements;
|
|
236
|
-
data.totalPages = listResponse.totalPages;
|
|
237
|
-
data.content = content;
|
|
238
|
-
if (content.length === 0) {
|
|
239
|
-
let msg =
|
|
240
|
-
"There are no news available for" +
|
|
241
|
-
category +
|
|
242
|
-
" for page " +
|
|
243
|
-
responseBody.data.number +
|
|
244
|
-
", Please try in other pages.";
|
|
245
|
-
data["msg"] = msg;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
} else {
|
|
249
|
-
responseBody.data.content = content;
|
|
250
|
-
}
|
|
251
|
-
return responseBody;
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
formatLatestCorporateActions = (res) => {
|
|
255
|
-
let response = {};
|
|
256
|
-
response["msgID"] = res.msgID;
|
|
257
|
-
response["srvTm"] = res.srvTm;
|
|
258
|
-
response["data"] = res.data;
|
|
259
|
-
log4js.debug("getLatestCorporateActions formatted response - " + response);
|
|
260
|
-
return response;
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
getLatestCorporateActions = async (symbol) => {
|
|
264
|
-
let result = {};
|
|
265
|
-
try {
|
|
266
|
-
const url = this.__config.LatestCorporateActions(symbol);
|
|
267
|
-
const response = await this.__http.GetMethod(url, false);
|
|
268
|
-
if (
|
|
269
|
-
Object.keys(response).length !== 0 &&
|
|
270
|
-
response.hasOwnProperty("data")
|
|
271
|
-
) {
|
|
272
|
-
result = this.formatLatestCorporateActions(response);
|
|
273
|
-
} else {
|
|
274
|
-
result = response;
|
|
275
|
-
}
|
|
276
|
-
} catch (error) {
|
|
277
|
-
return Promise.reject(error);
|
|
278
|
-
}
|
|
279
|
-
return result;
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
getReqBodyForResultsAndStocks = (searchText, pageNumber) => {
|
|
283
|
-
return {
|
|
284
|
-
exclCategory: [],
|
|
285
|
-
validRequest: false,
|
|
286
|
-
inclCategory: ["Result", "STOCK_IN_NEWS"],
|
|
287
|
-
page: pageNumber,
|
|
288
|
-
group: "G",
|
|
289
|
-
searchText: searchText,
|
|
290
|
-
};
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
getNewsForResultsAndStocks = async (searchText, pageNumber) => {
|
|
294
|
-
let result = {};
|
|
295
|
-
try {
|
|
296
|
-
let requestBody = await this.getReqBodyForResultsAndStocks(
|
|
297
|
-
searchText,
|
|
298
|
-
pageNumber
|
|
299
|
-
);
|
|
300
|
-
|
|
301
|
-
const url = this.__config.GeneralLiveNewsURL();
|
|
302
|
-
const response = await this.__http.PostMethod(url, requestBody);
|
|
303
|
-
result = response;
|
|
304
|
-
} catch (error) {
|
|
305
|
-
return Promise.reject(error);
|
|
306
|
-
}
|
|
307
|
-
return result;
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
filterNewsForResultsAndStocks = async (response, holdings) => {
|
|
311
|
-
//Get Response Body
|
|
312
|
-
let responseBody = this.newsResponseBody();
|
|
313
|
-
responseBody.msgID = response.msgID;
|
|
314
|
-
responseBody.srvTm = response.srvTm;
|
|
315
|
-
|
|
316
|
-
let content = [];
|
|
317
|
-
if (response.hasOwnProperty("data")) {
|
|
318
|
-
const responseData = response.data;
|
|
319
|
-
let data = responseBody.data;
|
|
320
|
-
let listOrGroupResponse = {};
|
|
321
|
-
//If Holdings true
|
|
322
|
-
if (holdings) {
|
|
323
|
-
if (responseData.hasOwnProperty("listResponse")) {
|
|
324
|
-
listOrGroupResponse = responseData.listResponse;
|
|
325
|
-
if (listOrGroupResponse.hasOwnProperty("content")) {
|
|
326
|
-
content = listOrGroupResponse.content.filter((object) => {
|
|
327
|
-
if (["Result", "STOCK_IN_NEWS"].includes(object.category)) {
|
|
328
|
-
return object;
|
|
329
|
-
}
|
|
330
|
-
});
|
|
331
|
-
data.content = content;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
} else {
|
|
335
|
-
if (responseData.hasOwnProperty("groupResponse")) {
|
|
336
|
-
listOrGroupResponse = responseData.groupResponse;
|
|
337
|
-
content = listOrGroupResponse.content;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
data.first = listOrGroupResponse.first;
|
|
342
|
-
data.last = listOrGroupResponse.last;
|
|
343
|
-
data.number = listOrGroupResponse.number;
|
|
344
|
-
data.size = listOrGroupResponse.size;
|
|
345
|
-
data.totalElements = listOrGroupResponse.totalElements;
|
|
346
|
-
data.totalPages = listOrGroupResponse.totalPages;
|
|
347
|
-
if (content.length === 0) {
|
|
348
|
-
let msg =
|
|
349
|
-
"There are no news available for Results and Stocks in News for page " +
|
|
350
|
-
responseBody.data.number +
|
|
351
|
-
", Please try in other pages.";
|
|
352
|
-
data["msg"] = msg;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
responseBody.data = data;
|
|
356
|
-
}
|
|
357
|
-
responseBody.data.content = content;
|
|
358
|
-
return responseBody;
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
module.exports = LiveNews;
|
|
1
|
+
const log4js = require("./logger.js");
|
|
2
|
+
class LiveNews {
|
|
3
|
+
constructor(fileName, http, config, constants) {
|
|
4
|
+
this.fileName = fileName;
|
|
5
|
+
this.__http = http;
|
|
6
|
+
this.__config = config;
|
|
7
|
+
this.__constants = constants;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//Get News Categories Data
|
|
11
|
+
getNewsCategoriesData = async () => {
|
|
12
|
+
let newsCategories = {};
|
|
13
|
+
try {
|
|
14
|
+
const fileExist = this.__constants.fileExistOrNot(this.fileName);
|
|
15
|
+
if (fileExist) {
|
|
16
|
+
newsCategories = {};
|
|
17
|
+
const obj = this.__constants.readFile(this.fileName);
|
|
18
|
+
let jsonObj = JSON.parse(obj);
|
|
19
|
+
if (jsonObj.hasOwnProperty("newsCategories")) {
|
|
20
|
+
newsCategories = jsonObj["newsCategories"];
|
|
21
|
+
} else {
|
|
22
|
+
const url = this.__config.LiveNewsURL();
|
|
23
|
+
newsCategories = await this.__http.GetMethod(url);
|
|
24
|
+
if (Object.keys(newsCategories).length !== 0) {
|
|
25
|
+
jsonObj["newsCategories"] = newsCategories;
|
|
26
|
+
this.__constants.writeInFile(
|
|
27
|
+
this.fileName,
|
|
28
|
+
JSON.stringify(jsonObj)
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
} catch (error) {
|
|
34
|
+
log4js.debug("error - " + error);
|
|
35
|
+
}
|
|
36
|
+
return newsCategories;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
//Return filteredCategories and with exc and inc categories
|
|
40
|
+
filterNewsCategories = async (response, filter) => {
|
|
41
|
+
const finalResponse = {};
|
|
42
|
+
let filteredCategories = [];
|
|
43
|
+
let excAndincCategories = {};
|
|
44
|
+
|
|
45
|
+
//Exclude Categories
|
|
46
|
+
const excludeCategory = ["Results", "Stocks in News", "My Holdings"];
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
const data = response.data;
|
|
50
|
+
const allNews = data.newsFilters.concat(data.ctLst);
|
|
51
|
+
const filterNews = allNews.filter((item) => {
|
|
52
|
+
//exclude categories
|
|
53
|
+
if (!excludeCategory.includes(item.dpNm)) {
|
|
54
|
+
filteredCategories.push(item.dpNm);
|
|
55
|
+
if (item.hasOwnProperty("inc")) {
|
|
56
|
+
excAndincCategories[item.dpNm] = item.inc;
|
|
57
|
+
} else {
|
|
58
|
+
excAndincCategories[item.dpNm] = [item.cat];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
if (!filter) {
|
|
63
|
+
finalResponse["excAndincCategories"] = excAndincCategories;
|
|
64
|
+
}
|
|
65
|
+
finalResponse["categories"] = filteredCategories;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
log4js.debug("error - " + error);
|
|
68
|
+
}
|
|
69
|
+
finalResponse["msgID"] = response.msgID;
|
|
70
|
+
finalResponse["srvTm"] = response.srvTm;
|
|
71
|
+
return finalResponse;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
//Get news categories data
|
|
75
|
+
getNewsCategories = async (filter = false) => {
|
|
76
|
+
let finalResponse = {};
|
|
77
|
+
try {
|
|
78
|
+
let newsCategories = await this.getNewsCategoriesData();
|
|
79
|
+
if (Object.keys(newsCategories).length !== 0) {
|
|
80
|
+
finalResponse["data"] = await this.filterNewsCategories(
|
|
81
|
+
newsCategories,
|
|
82
|
+
filter
|
|
83
|
+
);
|
|
84
|
+
} else {
|
|
85
|
+
finalResponse["data"] = newsCategories;
|
|
86
|
+
}
|
|
87
|
+
} catch (error) {
|
|
88
|
+
log4js.debug("error - " + error);
|
|
89
|
+
}
|
|
90
|
+
return finalResponse;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
getCategoryObject = async (category) => {
|
|
94
|
+
let object = {};
|
|
95
|
+
try {
|
|
96
|
+
const res = await this.getNewsCategoriesData();
|
|
97
|
+
if (res.hasOwnProperty("data")) {
|
|
98
|
+
const data = res.data;
|
|
99
|
+
const newsCategories = data.ctLst.concat(data.newsFilters);
|
|
100
|
+
let filterRes = newsCategories.filter((item) => item.dpNm === category);
|
|
101
|
+
object = filterRes[0];
|
|
102
|
+
}
|
|
103
|
+
} catch (error) {
|
|
104
|
+
return Promise.reject(error);
|
|
105
|
+
}
|
|
106
|
+
return object;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
getNewsRequestBody = async (category, searchText, pageNumber) => {
|
|
110
|
+
let requestBody = {};
|
|
111
|
+
try {
|
|
112
|
+
const response = await this.getCategoryObject(category);
|
|
113
|
+
if (Object.keys(response).length !== 0) {
|
|
114
|
+
if (response.hasOwnProperty("exc") && response.hasOwnProperty("inc")) {
|
|
115
|
+
requestBody["exclCategory"] = response.exc;
|
|
116
|
+
requestBody["inclCategory"] = response.inc;
|
|
117
|
+
requestBody["validRequest"] = response.lgrq;
|
|
118
|
+
requestBody["group"] = response.uiTyp;
|
|
119
|
+
} else {
|
|
120
|
+
requestBody["exclCategory"] = [];
|
|
121
|
+
requestBody["inclCategory"] = category;
|
|
122
|
+
requestBody["group"] = response.uiTyp;
|
|
123
|
+
}
|
|
124
|
+
requestBody["searchText"] = searchText;
|
|
125
|
+
requestBody["page"] = pageNumber;
|
|
126
|
+
}
|
|
127
|
+
} catch (error) {
|
|
128
|
+
return Promise.reject(error);
|
|
129
|
+
}
|
|
130
|
+
return requestBody;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
getGeneralNewsData = async (category, searchText, pageNumber) => {
|
|
134
|
+
let result = {};
|
|
135
|
+
try {
|
|
136
|
+
const requestBody = await this.getNewsRequestBody(
|
|
137
|
+
category,
|
|
138
|
+
searchText,
|
|
139
|
+
pageNumber
|
|
140
|
+
);
|
|
141
|
+
const url = this.__config.GeneralLiveNewsURL();
|
|
142
|
+
const response = await this.__http.PostMethod(url, requestBody);
|
|
143
|
+
result = response;
|
|
144
|
+
} catch (error) {
|
|
145
|
+
return Promise.reject(error);
|
|
146
|
+
}
|
|
147
|
+
return result;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
getEqHoldings = async (searchText, pageNumber) => {
|
|
151
|
+
let result = {};
|
|
152
|
+
try {
|
|
153
|
+
const requestBody = await this.getNewsRequestBody(
|
|
154
|
+
"My Holdings",
|
|
155
|
+
searchText,
|
|
156
|
+
pageNumber
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
const url = this.__config.NewsEqHoldingsURL();
|
|
160
|
+
const response = await this.__http.PostMethod(url, requestBody);
|
|
161
|
+
result = response;
|
|
162
|
+
} catch (error) {
|
|
163
|
+
return Promise.reject(error);
|
|
164
|
+
}
|
|
165
|
+
return result;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
newsResponseBody = () => {
|
|
169
|
+
return {
|
|
170
|
+
data: {
|
|
171
|
+
content: [],
|
|
172
|
+
first: null,
|
|
173
|
+
last: null,
|
|
174
|
+
number: null,
|
|
175
|
+
size: null,
|
|
176
|
+
totalElements: null,
|
|
177
|
+
totalPages: null,
|
|
178
|
+
},
|
|
179
|
+
msgID: null,
|
|
180
|
+
srvTm: null,
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
filterLiveNewsResponse = (
|
|
185
|
+
category,
|
|
186
|
+
excAndincCategories,
|
|
187
|
+
response,
|
|
188
|
+
holdings
|
|
189
|
+
) => {
|
|
190
|
+
//Get Response Body
|
|
191
|
+
let responseBody = this.newsResponseBody();
|
|
192
|
+
|
|
193
|
+
let content = [];
|
|
194
|
+
const excludeCategory = ["Result", "STOCK_IN_NEWS", "My Holdings"];
|
|
195
|
+
if (response.hasOwnProperty("data")) {
|
|
196
|
+
const responseData = response.data;
|
|
197
|
+
responseBody.msgID = response.msgID;
|
|
198
|
+
responseBody.srvTm = response.srvTm;
|
|
199
|
+
if (responseData.hasOwnProperty("listResponse")) {
|
|
200
|
+
let data = responseBody.data;
|
|
201
|
+
const listResponse = responseData.listResponse;
|
|
202
|
+
if (listResponse.hasOwnProperty("content")) {
|
|
203
|
+
const responseContent = listResponse.content;
|
|
204
|
+
//If Holdings value is true
|
|
205
|
+
if (holdings) {
|
|
206
|
+
//In Response , we will not get categoryName "All", so we will return data wtihout filter
|
|
207
|
+
if (category === "All" || category === '') {
|
|
208
|
+
content = responseContent;
|
|
209
|
+
} else {
|
|
210
|
+
content = responseContent.filter((object) => {
|
|
211
|
+
if (excAndincCategories.includes(object.category)) {
|
|
212
|
+
return object;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
} else {
|
|
217
|
+
//Holdings false and category "All" then exclude Result, STOCK_IN_NEWS and My Holdings
|
|
218
|
+
if (category === "All") {
|
|
219
|
+
content = responseContent.filter((object) => {
|
|
220
|
+
if (!excludeCategory.includes(object.category)) {
|
|
221
|
+
return object;
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
} else {
|
|
225
|
+
//Holdings false and category not All
|
|
226
|
+
content = responseContent;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
data.first = listResponse.first;
|
|
232
|
+
data.last = listResponse.last;
|
|
233
|
+
data.number = listResponse.number;
|
|
234
|
+
data.size = listResponse.size;
|
|
235
|
+
data.totalElements = listResponse.totalElements;
|
|
236
|
+
data.totalPages = listResponse.totalPages;
|
|
237
|
+
data.content = content;
|
|
238
|
+
if (content.length === 0) {
|
|
239
|
+
let msg =
|
|
240
|
+
"There are no news available for" +
|
|
241
|
+
category +
|
|
242
|
+
" for page " +
|
|
243
|
+
responseBody.data.number +
|
|
244
|
+
", Please try in other pages.";
|
|
245
|
+
data["msg"] = msg;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
} else {
|
|
249
|
+
responseBody.data.content = content;
|
|
250
|
+
}
|
|
251
|
+
return responseBody;
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
formatLatestCorporateActions = (res) => {
|
|
255
|
+
let response = {};
|
|
256
|
+
response["msgID"] = res.msgID;
|
|
257
|
+
response["srvTm"] = res.srvTm;
|
|
258
|
+
response["data"] = res.data;
|
|
259
|
+
log4js.debug("getLatestCorporateActions formatted response - " + response);
|
|
260
|
+
return response;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
getLatestCorporateActions = async (symbol) => {
|
|
264
|
+
let result = {};
|
|
265
|
+
try {
|
|
266
|
+
const url = this.__config.LatestCorporateActions(symbol);
|
|
267
|
+
const response = await this.__http.GetMethod(url, false);
|
|
268
|
+
if (
|
|
269
|
+
Object.keys(response).length !== 0 &&
|
|
270
|
+
response.hasOwnProperty("data")
|
|
271
|
+
) {
|
|
272
|
+
result = this.formatLatestCorporateActions(response);
|
|
273
|
+
} else {
|
|
274
|
+
result = response;
|
|
275
|
+
}
|
|
276
|
+
} catch (error) {
|
|
277
|
+
return Promise.reject(error);
|
|
278
|
+
}
|
|
279
|
+
return result;
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
getReqBodyForResultsAndStocks = (searchText, pageNumber) => {
|
|
283
|
+
return {
|
|
284
|
+
exclCategory: [],
|
|
285
|
+
validRequest: false,
|
|
286
|
+
inclCategory: ["Result", "STOCK_IN_NEWS"],
|
|
287
|
+
page: pageNumber,
|
|
288
|
+
group: "G",
|
|
289
|
+
searchText: searchText,
|
|
290
|
+
};
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
getNewsForResultsAndStocks = async (searchText, pageNumber) => {
|
|
294
|
+
let result = {};
|
|
295
|
+
try {
|
|
296
|
+
let requestBody = await this.getReqBodyForResultsAndStocks(
|
|
297
|
+
searchText,
|
|
298
|
+
pageNumber
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
const url = this.__config.GeneralLiveNewsURL();
|
|
302
|
+
const response = await this.__http.PostMethod(url, requestBody);
|
|
303
|
+
result = response;
|
|
304
|
+
} catch (error) {
|
|
305
|
+
return Promise.reject(error);
|
|
306
|
+
}
|
|
307
|
+
return result;
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
filterNewsForResultsAndStocks = async (response, holdings) => {
|
|
311
|
+
//Get Response Body
|
|
312
|
+
let responseBody = this.newsResponseBody();
|
|
313
|
+
responseBody.msgID = response.msgID;
|
|
314
|
+
responseBody.srvTm = response.srvTm;
|
|
315
|
+
|
|
316
|
+
let content = [];
|
|
317
|
+
if (response.hasOwnProperty("data")) {
|
|
318
|
+
const responseData = response.data;
|
|
319
|
+
let data = responseBody.data;
|
|
320
|
+
let listOrGroupResponse = {};
|
|
321
|
+
//If Holdings true
|
|
322
|
+
if (holdings) {
|
|
323
|
+
if (responseData.hasOwnProperty("listResponse")) {
|
|
324
|
+
listOrGroupResponse = responseData.listResponse;
|
|
325
|
+
if (listOrGroupResponse.hasOwnProperty("content")) {
|
|
326
|
+
content = listOrGroupResponse.content.filter((object) => {
|
|
327
|
+
if (["Result", "STOCK_IN_NEWS"].includes(object.category)) {
|
|
328
|
+
return object;
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
data.content = content;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
} else {
|
|
335
|
+
if (responseData.hasOwnProperty("groupResponse")) {
|
|
336
|
+
listOrGroupResponse = responseData.groupResponse;
|
|
337
|
+
content = listOrGroupResponse.content;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
data.first = listOrGroupResponse.first;
|
|
342
|
+
data.last = listOrGroupResponse.last;
|
|
343
|
+
data.number = listOrGroupResponse.number;
|
|
344
|
+
data.size = listOrGroupResponse.size;
|
|
345
|
+
data.totalElements = listOrGroupResponse.totalElements;
|
|
346
|
+
data.totalPages = listOrGroupResponse.totalPages;
|
|
347
|
+
if (content.length === 0) {
|
|
348
|
+
let msg =
|
|
349
|
+
"There are no news available for Results and Stocks in News for page " +
|
|
350
|
+
responseBody.data.number +
|
|
351
|
+
", Please try in other pages.";
|
|
352
|
+
data["msg"] = msg;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
responseBody.data = data;
|
|
356
|
+
}
|
|
357
|
+
responseBody.data.content = content;
|
|
358
|
+
return responseBody;
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
module.exports = LiveNews;
|