api_connect_nodejs 2.0.12 → 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.
- package/README.md +30 -30
- package/conf/settings.ini +17 -20
- package/enums/actionType.js +10 -10
- package/enums/assetType.js +25 -25
- package/enums/chartExchangeType.js +16 -16
- package/enums/chartType.js +13 -13
- package/enums/eodIntervalType.js +11 -11
- package/enums/exchangeType.js +15 -15
- 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/segmentType.js +10 -10
- package/enums/streamingConstants.js +13 -13
- 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 +2682 -2559
- package/src/apiUtils.js +221 -221
- package/src/chart.js +404 -404
- package/src/config.js +347 -342
- package/src/feed/depthFeed.js +136 -136
- package/src/feed/feed.js +170 -154
- package/src/feed/liveNewsFeed.js +112 -112
- package/src/feed/miniQuoteFeed.js +122 -121
- package/src/feed/ordersFeed.js +125 -124
- package/src/feed/quotesFeed.js +123 -122
- package/src/http.js +260 -197
- package/src/iniparser.js +45 -45
- package/src/liveNews.js +362 -362
- package/src/logger.js +16 -16
- package/src/order.js +48 -48
- package/src/quote.js +75 -75
- package/src/report.js +49 -49
- package/src/researchCalls.js +175 -175
- package/src/watchlist.js +378 -378
- package/validations/apiConnectValidator.js +701 -698
- package/validations/chartValidator.js +125 -125
- package/validations/feedStreamerValidator.js +162 -162
- package/validations/liveNewsValidator.js +60 -60
- package/validations/quoteValidator.js +19 -19
- package/validations/reportValidator.js +35 -35
- package/validations/researchCallsValidator.js +86 -86
- package/validations/watchlistValidator.js +60 -60
package/src/chart.js
CHANGED
|
@@ -1,404 +1,404 @@
|
|
|
1
|
-
const log4js = require("./logger.js");
|
|
2
|
-
const { futureAssetType } = require("../enums/assetType");
|
|
3
|
-
const {
|
|
4
|
-
validateChartIntraday,
|
|
5
|
-
validateChartEOD,
|
|
6
|
-
} = require("../validations/chartValidator");
|
|
7
|
-
|
|
8
|
-
class Chart {
|
|
9
|
-
constructor(http, config, constants) {
|
|
10
|
-
this.__http = http;
|
|
11
|
-
this.__config = config;
|
|
12
|
-
this.__constants = constants;
|
|
13
|
-
}
|
|
14
|
-
checkResponseHaveArrayOrNot = (pltPnts) => {
|
|
15
|
-
if (
|
|
16
|
-
Array.isArray(pltPnts.ltt) &&
|
|
17
|
-
Array.isArray(pltPnts.open) &&
|
|
18
|
-
Array.isArray(pltPnts.high) &&
|
|
19
|
-
Array.isArray(pltPnts.low) &&
|
|
20
|
-
Array.isArray(pltPnts.close) &&
|
|
21
|
-
Array.isArray(pltPnts.vol)
|
|
22
|
-
) {
|
|
23
|
-
return true;
|
|
24
|
-
} else {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Modifying the response
|
|
30
|
-
*/
|
|
31
|
-
modifyResponse = async (response) => {
|
|
32
|
-
try {
|
|
33
|
-
const modifyResponse = {};
|
|
34
|
-
let msgID = "";
|
|
35
|
-
let srvTm = "";
|
|
36
|
-
let nextTillDate = "";
|
|
37
|
-
const charts = [];
|
|
38
|
-
if (Object.keys(response).length !== 0) {
|
|
39
|
-
msgID = response["msgID"];
|
|
40
|
-
srvTm = response["srvTm"];
|
|
41
|
-
const data = response.data;
|
|
42
|
-
const pltPnts = data.pltPnts;
|
|
43
|
-
if (
|
|
44
|
-
Object.keys(data).length !== 0 &&
|
|
45
|
-
Object.keys(pltPnts).length !== 0
|
|
46
|
-
) {
|
|
47
|
-
const isArray = await this.checkResponseHaveArrayOrNot(pltPnts);
|
|
48
|
-
if (isArray && pltPnts.ltt.length > 0) {
|
|
49
|
-
modifyResponse["nextTillDate"] = pltPnts.ltt[0];
|
|
50
|
-
for (let i = 0; i < pltPnts.ltt.length; i++) {
|
|
51
|
-
const dataArray = [];
|
|
52
|
-
dataArray[0] = pltPnts.ltt[i];
|
|
53
|
-
dataArray[1] = pltPnts.open[i];
|
|
54
|
-
dataArray[2] = pltPnts.high[i];
|
|
55
|
-
dataArray[3] = pltPnts.low[i];
|
|
56
|
-
dataArray[4] = pltPnts.close[i];
|
|
57
|
-
dataArray[5] = pltPnts.vol[i];
|
|
58
|
-
charts.push(dataArray);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
modifyResponse["data"] = charts;
|
|
65
|
-
modifyResponse["msgID"] = msgID;
|
|
66
|
-
modifyResponse["srvTm"] = srvTm;
|
|
67
|
-
log4js.debug("modifyResponse :" + JSON.stringify(modifyResponse));
|
|
68
|
-
return modifyResponse;
|
|
69
|
-
} catch (e) {
|
|
70
|
-
return Promise.reject(e);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Modifying the response
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
datewithoutTime = function (inputDate) {
|
|
79
|
-
var d = new Date(inputDate);
|
|
80
|
-
d.setHours(0, 0, 0, 0);
|
|
81
|
-
return d;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
modifyResponseForCustomPeriod = async (response, toDate) => {
|
|
85
|
-
|
|
86
|
-
try {
|
|
87
|
-
const modifyResponse = {};
|
|
88
|
-
let msgID = "";
|
|
89
|
-
let srvTm = "";
|
|
90
|
-
var convertedToDate = new Date(toDate);
|
|
91
|
-
const charts = [];
|
|
92
|
-
if (Object.keys(response).length !== 0) {
|
|
93
|
-
msgID = response["msgID"];
|
|
94
|
-
srvTm = response["srvTm"];
|
|
95
|
-
const data = response.data;
|
|
96
|
-
const pltPnts = data.pltPnts;
|
|
97
|
-
if (
|
|
98
|
-
Object.keys(data).length !== 0 &&
|
|
99
|
-
Object.keys(pltPnts).length !== 0
|
|
100
|
-
) {
|
|
101
|
-
const isArray = await this.checkResponseHaveArrayOrNot(pltPnts);
|
|
102
|
-
if (isArray && pltPnts.ltt.length > 0) {
|
|
103
|
-
modifyResponse["nextTillDate"] = pltPnts.ltt[0];
|
|
104
|
-
for (let i = 0; i < pltPnts.ltt.length; i++) {
|
|
105
|
-
|
|
106
|
-
var convertedPlotPointDate = new Date(pltPnts.ltt[i]);
|
|
107
|
-
|
|
108
|
-
if(this.datewithoutTime(convertedPlotPointDate) > this.datewithoutTime(convertedToDate)) {
|
|
109
|
-
break
|
|
110
|
-
}
|
|
111
|
-
const dataArray = [];
|
|
112
|
-
dataArray[0] = pltPnts.ltt[i];
|
|
113
|
-
dataArray[1] = pltPnts.open[i];
|
|
114
|
-
dataArray[2] = pltPnts.high[i];
|
|
115
|
-
dataArray[3] = pltPnts.low[i];
|
|
116
|
-
dataArray[4] = pltPnts.close[i];
|
|
117
|
-
dataArray[5] = pltPnts.vol[i];
|
|
118
|
-
charts.push(dataArray);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
modifyResponse["data"] = charts;
|
|
125
|
-
modifyResponse["msgID"] = msgID;
|
|
126
|
-
modifyResponse["srvTm"] = srvTm;
|
|
127
|
-
log4js.debug("modifyResponse for Custom period:" + JSON.stringify(modifyResponse));
|
|
128
|
-
return modifyResponse;
|
|
129
|
-
} catch (e) {
|
|
130
|
-
return Promise.reject(e);
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
convertToBoolean = async (value) => {
|
|
135
|
-
if (value === "TRUE" || value === "true") {
|
|
136
|
-
return true;
|
|
137
|
-
}
|
|
138
|
-
if (value === "FALSE" || value === "false") {
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
//Chart RequestBody
|
|
144
|
-
chartRequestBody = () => {
|
|
145
|
-
return {
|
|
146
|
-
conti: false, // By default set as false
|
|
147
|
-
chTyp: "Interval", // By default set as Interval
|
|
148
|
-
ltt: null, // By default set as null
|
|
149
|
-
};
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
*
|
|
154
|
-
* @param {"M1" | "M3" | "M5" | "M15" | "M30" | "H1"} interval
|
|
155
|
-
* @param {"FUTSTK" | "FUTIDX" | "FUTCUR" | "FUTCOM" | "OPTIDX" | "OPTSTK" | "OPTCUR" | "OPTFUT" | "EQUITY" | "INDEX"} assetType
|
|
156
|
-
* @param {string} symbol
|
|
157
|
-
* @param {"NSE" | "BSE" | "NFO" | "BFO" | "CDS" | "MCX" | "NCDEX" | "INDEX"} exchangeType
|
|
158
|
-
* @param {string} tillDate
|
|
159
|
-
* @param {boolean} includeContinuousFuture
|
|
160
|
-
* @returns
|
|
161
|
-
*/
|
|
162
|
-
getIntradayChartAPI = async (
|
|
163
|
-
interval,
|
|
164
|
-
assetType,
|
|
165
|
-
symbol,
|
|
166
|
-
exchangeType,
|
|
167
|
-
tillDate,
|
|
168
|
-
includeContinuousFuture
|
|
169
|
-
) => {
|
|
170
|
-
let result = {};
|
|
171
|
-
try {
|
|
172
|
-
//Convert into boolean
|
|
173
|
-
includeContinuousFuture = await this.convertToBoolean(
|
|
174
|
-
includeContinuousFuture
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
//Convert null string into null object
|
|
178
|
-
if (tillDate.toLowerCase() === "null") {
|
|
179
|
-
tillDate = null;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Validate intraday chart params
|
|
184
|
-
*/
|
|
185
|
-
const validateResponse = validateChartIntraday(
|
|
186
|
-
interval,
|
|
187
|
-
assetType,
|
|
188
|
-
symbol,
|
|
189
|
-
exchangeType,
|
|
190
|
-
tillDate,
|
|
191
|
-
includeContinuousFuture
|
|
192
|
-
);
|
|
193
|
-
if (validateResponse.error) {
|
|
194
|
-
log4js.debug(
|
|
195
|
-
"intraday validation error - " + validateResponse.error.details
|
|
196
|
-
);
|
|
197
|
-
return Promise.reject(validateResponse.error.details);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
//Request Body
|
|
201
|
-
let requestBodyData = this.chartRequestBody();
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* If AssetType Amongst FUTIDX, FUTSTK,FUTCUR,FUTCOM then we take user input(includeContinuousFuture) otherwise set false
|
|
205
|
-
*/
|
|
206
|
-
if (!Object.values(futureAssetType).includes(assetType)) {
|
|
207
|
-
includeContinuousFuture = false;
|
|
208
|
-
} else {
|
|
209
|
-
requestBodyData.conti = includeContinuousFuture;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
requestBodyData.ltt = tillDate;
|
|
213
|
-
|
|
214
|
-
const url = this.__config.ChartURL(
|
|
215
|
-
interval,
|
|
216
|
-
exchangeType,
|
|
217
|
-
assetType,
|
|
218
|
-
symbol
|
|
219
|
-
);
|
|
220
|
-
log4js.debug("intraday URL -" + url);
|
|
221
|
-
|
|
222
|
-
const response = await this.__http.PostMethod(url, requestBodyData);
|
|
223
|
-
if (result.length !== 0) {
|
|
224
|
-
result = this.modifyResponse(response);
|
|
225
|
-
} else {
|
|
226
|
-
result = response;
|
|
227
|
-
}
|
|
228
|
-
return result;
|
|
229
|
-
} catch (error) {
|
|
230
|
-
log4js.debug("intraday error - " + error);
|
|
231
|
-
return Promise.reject(error);
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
*
|
|
237
|
-
* @param {"D1" | "W1" | "MN1"} interval
|
|
238
|
-
* @param {"FUTSTK" | "FUTIDX" | "FUTCUR" | "FUTCOM" | "OPTIDX" | "OPTSTK" | "OPTCUR" | "OPTFUT" | "EQUITY" | "INDEX"} assetType
|
|
239
|
-
* @param {string} symbol
|
|
240
|
-
* @param {"NSE" | "BSE" | "NFO" | "BFO" | "CDS" | "MCX" | "NCDEX" | "INDEX"} exchangeType
|
|
241
|
-
* @param {string} tillDate yyyy-MM-dd
|
|
242
|
-
* @param {boolean} includeContinuousFuture
|
|
243
|
-
* @returns
|
|
244
|
-
*/
|
|
245
|
-
getEODChartAPI = async (
|
|
246
|
-
interval,
|
|
247
|
-
assetType,
|
|
248
|
-
symbol,
|
|
249
|
-
exchangeType,
|
|
250
|
-
tillDate,
|
|
251
|
-
includeContinuousFuture
|
|
252
|
-
) => {
|
|
253
|
-
let result = {};
|
|
254
|
-
try {
|
|
255
|
-
//Convert into boolean
|
|
256
|
-
includeContinuousFuture = await this.convertToBoolean(
|
|
257
|
-
includeContinuousFuture
|
|
258
|
-
);
|
|
259
|
-
|
|
260
|
-
//Convert null string into null object
|
|
261
|
-
if (tillDate.toLowerCase() === "null") {
|
|
262
|
-
tillDate = null;
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Validate eod chart params
|
|
266
|
-
*/
|
|
267
|
-
const validateResponse = validateChartEOD(
|
|
268
|
-
interval,
|
|
269
|
-
assetType,
|
|
270
|
-
symbol,
|
|
271
|
-
exchangeType,
|
|
272
|
-
tillDate,
|
|
273
|
-
includeContinuousFuture
|
|
274
|
-
);
|
|
275
|
-
if (validateResponse.error) {
|
|
276
|
-
log4js.debug(
|
|
277
|
-
"EOD chart validation error - " + validateResponse.error.details
|
|
278
|
-
);
|
|
279
|
-
return Promise.reject(validateResponse.error.details);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
//Request Body
|
|
283
|
-
const requestBodyData = this.chartRequestBody();
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* If AssetType Amongst FUTIDX, FUTSTK,FUTCUR,FUTCOM then we take user input(includeContinuousFuture) otherwise set false
|
|
287
|
-
*/
|
|
288
|
-
if (!Object.values(futureAssetType).includes(assetType)) {
|
|
289
|
-
includeContinuousFuture = false;
|
|
290
|
-
} else {
|
|
291
|
-
requestBodyData.conti = includeContinuousFuture;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
requestBodyData.ltt = tillDate;
|
|
295
|
-
|
|
296
|
-
const url = this.__config.ChartURL(
|
|
297
|
-
interval,
|
|
298
|
-
exchangeType,
|
|
299
|
-
assetType,
|
|
300
|
-
symbol
|
|
301
|
-
);
|
|
302
|
-
log4js.debug("EOD URL -" + url);
|
|
303
|
-
|
|
304
|
-
const response = await this.__http.PostMethod(url, requestBodyData);
|
|
305
|
-
if (result.length !== 0) {
|
|
306
|
-
result = this.modifyResponse(response);
|
|
307
|
-
} else {
|
|
308
|
-
result = response;
|
|
309
|
-
}
|
|
310
|
-
log4js.debug("EOD Result :" + JSON.stringify(result));
|
|
311
|
-
return result;
|
|
312
|
-
} catch (error) {
|
|
313
|
-
log4js.debug("EOD error - " + error);
|
|
314
|
-
return Promise.reject(error);
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
*
|
|
320
|
-
* @param {"D1" | "W1" | "MN1"} interval
|
|
321
|
-
* @param {"FUTSTK" | "FUTIDX" | "FUTCUR" | "FUTCOM" | "OPTIDX" | "OPTSTK" | "OPTCUR" | "OPTFUT" | "EQUITY" | "INDEX"} assetType
|
|
322
|
-
* @param {string} symbol
|
|
323
|
-
* @param {"NSE" | "BSE" | "NFO" | "BFO" | "CDS" | "MCX" | "NCDEX" | "INDEX"} exchangeType
|
|
324
|
-
* @param {string} fromDate yyyy-MM-dd
|
|
325
|
-
* @param {string} toDate yyyy-MM-dd
|
|
326
|
-
* @param {boolean} includeContinuousFuture
|
|
327
|
-
* @returns
|
|
328
|
-
*/
|
|
329
|
-
getCustomPeriodChartAPI = async (
|
|
330
|
-
interval,
|
|
331
|
-
assetType,
|
|
332
|
-
symbol,
|
|
333
|
-
exchangeType,
|
|
334
|
-
fromDate,
|
|
335
|
-
toDate,
|
|
336
|
-
includeContinuousFuture
|
|
337
|
-
) => {
|
|
338
|
-
let result = {};
|
|
339
|
-
try {
|
|
340
|
-
//Convert into boolean
|
|
341
|
-
includeContinuousFuture = await this.convertToBoolean(
|
|
342
|
-
includeContinuousFuture
|
|
343
|
-
);
|
|
344
|
-
interval = "D1"
|
|
345
|
-
/**
|
|
346
|
-
* Validate eod chart params
|
|
347
|
-
*/
|
|
348
|
-
const validateResponse = validateChartCustomPeriod(
|
|
349
|
-
interval,
|
|
350
|
-
assetType,
|
|
351
|
-
symbol,
|
|
352
|
-
exchangeType,
|
|
353
|
-
fromDate,
|
|
354
|
-
toDate,
|
|
355
|
-
includeContinuousFuture
|
|
356
|
-
);
|
|
357
|
-
if (validateResponse.error) {
|
|
358
|
-
log4js.debug(
|
|
359
|
-
"CustomPeriod chart validation error - " + JSON.stringify(validateResponse.error.details)
|
|
360
|
-
);
|
|
361
|
-
return Promise.reject(validateResponse.error.details);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
//Request Body
|
|
365
|
-
const requestBodyData = this.chartRequestBody();
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* If AssetType Amongst FUTIDX, FUTSTK,FUTCUR,FUTCOM then we take user input(includeContinuousFuture) otherwise set false
|
|
369
|
-
*/
|
|
370
|
-
if (!Object.values(futureAssetType).includes(assetType)) {
|
|
371
|
-
includeContinuousFuture = false;
|
|
372
|
-
} else {
|
|
373
|
-
requestBodyData.conti = includeContinuousFuture;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
requestBodyData.frmDt = fromDate;
|
|
377
|
-
requestBodyData.toDt = toDate;
|
|
378
|
-
requestBodyData.prdTyp = "CUST"
|
|
379
|
-
delete requestBodyData.ltt;
|
|
380
|
-
|
|
381
|
-
const url = this.__config.ChartURL(
|
|
382
|
-
interval,
|
|
383
|
-
exchangeType,
|
|
384
|
-
assetType,
|
|
385
|
-
symbol
|
|
386
|
-
);
|
|
387
|
-
log4js.debug("EOD URL -" + url);
|
|
388
|
-
|
|
389
|
-
const response = await this.__http.PostMethod(url, requestBodyData);
|
|
390
|
-
if (result.length !== 0) {
|
|
391
|
-
result = this.modifyResponseForCustomPeriod(response, toDate);
|
|
392
|
-
} else {
|
|
393
|
-
result = response;
|
|
394
|
-
}
|
|
395
|
-
log4js.debug("EOD Result :" + JSON.stringify(result));
|
|
396
|
-
return result;
|
|
397
|
-
} catch (error) {
|
|
398
|
-
log4js.debug("EOD error - " + error);
|
|
399
|
-
return Promise.reject(error);
|
|
400
|
-
}
|
|
401
|
-
};
|
|
402
|
-
|
|
403
|
-
}
|
|
404
|
-
module.exports = Chart;
|
|
1
|
+
const log4js = require("./logger.js");
|
|
2
|
+
const { futureAssetType } = require("../enums/assetType");
|
|
3
|
+
const {
|
|
4
|
+
validateChartIntraday,
|
|
5
|
+
validateChartEOD,
|
|
6
|
+
} = require("../validations/chartValidator");
|
|
7
|
+
|
|
8
|
+
class Chart {
|
|
9
|
+
constructor(http, config, constants) {
|
|
10
|
+
this.__http = http;
|
|
11
|
+
this.__config = config;
|
|
12
|
+
this.__constants = constants;
|
|
13
|
+
}
|
|
14
|
+
checkResponseHaveArrayOrNot = (pltPnts) => {
|
|
15
|
+
if (
|
|
16
|
+
Array.isArray(pltPnts.ltt) &&
|
|
17
|
+
Array.isArray(pltPnts.open) &&
|
|
18
|
+
Array.isArray(pltPnts.high) &&
|
|
19
|
+
Array.isArray(pltPnts.low) &&
|
|
20
|
+
Array.isArray(pltPnts.close) &&
|
|
21
|
+
Array.isArray(pltPnts.vol)
|
|
22
|
+
) {
|
|
23
|
+
return true;
|
|
24
|
+
} else {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Modifying the response
|
|
30
|
+
*/
|
|
31
|
+
modifyResponse = async (response) => {
|
|
32
|
+
try {
|
|
33
|
+
const modifyResponse = {};
|
|
34
|
+
let msgID = "";
|
|
35
|
+
let srvTm = "";
|
|
36
|
+
let nextTillDate = "";
|
|
37
|
+
const charts = [];
|
|
38
|
+
if (Object.keys(response).length !== 0) {
|
|
39
|
+
msgID = response["msgID"];
|
|
40
|
+
srvTm = response["srvTm"];
|
|
41
|
+
const data = response.data;
|
|
42
|
+
const pltPnts = data.pltPnts;
|
|
43
|
+
if (
|
|
44
|
+
Object.keys(data).length !== 0 &&
|
|
45
|
+
Object.keys(pltPnts).length !== 0
|
|
46
|
+
) {
|
|
47
|
+
const isArray = await this.checkResponseHaveArrayOrNot(pltPnts);
|
|
48
|
+
if (isArray && pltPnts.ltt.length > 0) {
|
|
49
|
+
modifyResponse["nextTillDate"] = pltPnts.ltt[0];
|
|
50
|
+
for (let i = 0; i < pltPnts.ltt.length; i++) {
|
|
51
|
+
const dataArray = [];
|
|
52
|
+
dataArray[0] = pltPnts.ltt[i];
|
|
53
|
+
dataArray[1] = pltPnts.open[i];
|
|
54
|
+
dataArray[2] = pltPnts.high[i];
|
|
55
|
+
dataArray[3] = pltPnts.low[i];
|
|
56
|
+
dataArray[4] = pltPnts.close[i];
|
|
57
|
+
dataArray[5] = pltPnts.vol[i];
|
|
58
|
+
charts.push(dataArray);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
modifyResponse["data"] = charts;
|
|
65
|
+
modifyResponse["msgID"] = msgID;
|
|
66
|
+
modifyResponse["srvTm"] = srvTm;
|
|
67
|
+
log4js.debug("modifyResponse :" + JSON.stringify(modifyResponse));
|
|
68
|
+
return modifyResponse;
|
|
69
|
+
} catch (e) {
|
|
70
|
+
return Promise.reject(e);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Modifying the response
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
datewithoutTime = function (inputDate) {
|
|
79
|
+
var d = new Date(inputDate);
|
|
80
|
+
d.setHours(0, 0, 0, 0);
|
|
81
|
+
return d;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
modifyResponseForCustomPeriod = async (response, toDate) => {
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
const modifyResponse = {};
|
|
88
|
+
let msgID = "";
|
|
89
|
+
let srvTm = "";
|
|
90
|
+
var convertedToDate = new Date(toDate);
|
|
91
|
+
const charts = [];
|
|
92
|
+
if (Object.keys(response).length !== 0) {
|
|
93
|
+
msgID = response["msgID"];
|
|
94
|
+
srvTm = response["srvTm"];
|
|
95
|
+
const data = response.data;
|
|
96
|
+
const pltPnts = data.pltPnts;
|
|
97
|
+
if (
|
|
98
|
+
Object.keys(data).length !== 0 &&
|
|
99
|
+
Object.keys(pltPnts).length !== 0
|
|
100
|
+
) {
|
|
101
|
+
const isArray = await this.checkResponseHaveArrayOrNot(pltPnts);
|
|
102
|
+
if (isArray && pltPnts.ltt.length > 0) {
|
|
103
|
+
modifyResponse["nextTillDate"] = pltPnts.ltt[0];
|
|
104
|
+
for (let i = 0; i < pltPnts.ltt.length; i++) {
|
|
105
|
+
|
|
106
|
+
var convertedPlotPointDate = new Date(pltPnts.ltt[i]);
|
|
107
|
+
|
|
108
|
+
if(this.datewithoutTime(convertedPlotPointDate) > this.datewithoutTime(convertedToDate)) {
|
|
109
|
+
break
|
|
110
|
+
}
|
|
111
|
+
const dataArray = [];
|
|
112
|
+
dataArray[0] = pltPnts.ltt[i];
|
|
113
|
+
dataArray[1] = pltPnts.open[i];
|
|
114
|
+
dataArray[2] = pltPnts.high[i];
|
|
115
|
+
dataArray[3] = pltPnts.low[i];
|
|
116
|
+
dataArray[4] = pltPnts.close[i];
|
|
117
|
+
dataArray[5] = pltPnts.vol[i];
|
|
118
|
+
charts.push(dataArray);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
modifyResponse["data"] = charts;
|
|
125
|
+
modifyResponse["msgID"] = msgID;
|
|
126
|
+
modifyResponse["srvTm"] = srvTm;
|
|
127
|
+
log4js.debug("modifyResponse for Custom period:" + JSON.stringify(modifyResponse));
|
|
128
|
+
return modifyResponse;
|
|
129
|
+
} catch (e) {
|
|
130
|
+
return Promise.reject(e);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
convertToBoolean = async (value) => {
|
|
135
|
+
if (value === "TRUE" || value === "true") {
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
if (value === "FALSE" || value === "false") {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
//Chart RequestBody
|
|
144
|
+
chartRequestBody = () => {
|
|
145
|
+
return {
|
|
146
|
+
conti: false, // By default set as false
|
|
147
|
+
chTyp: "Interval", // By default set as Interval
|
|
148
|
+
ltt: null, // By default set as null
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
*
|
|
154
|
+
* @param {"M1" | "M3" | "M5" | "M15" | "M30" | "H1"} interval
|
|
155
|
+
* @param {"FUTSTK" | "FUTIDX" | "FUTCUR" | "FUTCOM" | "OPTIDX" | "OPTSTK" | "OPTCUR" | "OPTFUT" | "EQUITY" | "INDEX"} assetType
|
|
156
|
+
* @param {string} symbol
|
|
157
|
+
* @param {"NSE" | "BSE" | "NFO" | "BFO" | "CDS" | "MCX" | "NCDEX" | "INDEX"} exchangeType
|
|
158
|
+
* @param {string} tillDate
|
|
159
|
+
* @param {boolean} includeContinuousFuture
|
|
160
|
+
* @returns
|
|
161
|
+
*/
|
|
162
|
+
getIntradayChartAPI = async (
|
|
163
|
+
interval,
|
|
164
|
+
assetType,
|
|
165
|
+
symbol,
|
|
166
|
+
exchangeType,
|
|
167
|
+
tillDate,
|
|
168
|
+
includeContinuousFuture
|
|
169
|
+
) => {
|
|
170
|
+
let result = {};
|
|
171
|
+
try {
|
|
172
|
+
//Convert into boolean
|
|
173
|
+
includeContinuousFuture = await this.convertToBoolean(
|
|
174
|
+
includeContinuousFuture
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
//Convert null string into null object
|
|
178
|
+
if (tillDate.toLowerCase() === "null") {
|
|
179
|
+
tillDate = null;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Validate intraday chart params
|
|
184
|
+
*/
|
|
185
|
+
const validateResponse = validateChartIntraday(
|
|
186
|
+
interval,
|
|
187
|
+
assetType,
|
|
188
|
+
symbol,
|
|
189
|
+
exchangeType,
|
|
190
|
+
tillDate,
|
|
191
|
+
includeContinuousFuture
|
|
192
|
+
);
|
|
193
|
+
if (validateResponse.error) {
|
|
194
|
+
log4js.debug(
|
|
195
|
+
"intraday validation error - " + validateResponse.error.details
|
|
196
|
+
);
|
|
197
|
+
return Promise.reject(validateResponse.error.details);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
//Request Body
|
|
201
|
+
let requestBodyData = this.chartRequestBody();
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* If AssetType Amongst FUTIDX, FUTSTK,FUTCUR,FUTCOM then we take user input(includeContinuousFuture) otherwise set false
|
|
205
|
+
*/
|
|
206
|
+
if (!Object.values(futureAssetType).includes(assetType)) {
|
|
207
|
+
includeContinuousFuture = false;
|
|
208
|
+
} else {
|
|
209
|
+
requestBodyData.conti = includeContinuousFuture;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
requestBodyData.ltt = tillDate;
|
|
213
|
+
|
|
214
|
+
const url = this.__config.ChartURL(
|
|
215
|
+
interval,
|
|
216
|
+
exchangeType,
|
|
217
|
+
assetType,
|
|
218
|
+
symbol
|
|
219
|
+
);
|
|
220
|
+
log4js.debug("intraday URL -" + url);
|
|
221
|
+
|
|
222
|
+
const response = await this.__http.PostMethod(url, requestBodyData);
|
|
223
|
+
if (result.length !== 0) {
|
|
224
|
+
result = this.modifyResponse(response);
|
|
225
|
+
} else {
|
|
226
|
+
result = response;
|
|
227
|
+
}
|
|
228
|
+
return result;
|
|
229
|
+
} catch (error) {
|
|
230
|
+
log4js.debug("intraday error - " + error);
|
|
231
|
+
return Promise.reject(error);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
*
|
|
237
|
+
* @param {"D1" | "W1" | "MN1"} interval
|
|
238
|
+
* @param {"FUTSTK" | "FUTIDX" | "FUTCUR" | "FUTCOM" | "OPTIDX" | "OPTSTK" | "OPTCUR" | "OPTFUT" | "EQUITY" | "INDEX"} assetType
|
|
239
|
+
* @param {string} symbol
|
|
240
|
+
* @param {"NSE" | "BSE" | "NFO" | "BFO" | "CDS" | "MCX" | "NCDEX" | "INDEX"} exchangeType
|
|
241
|
+
* @param {string} tillDate yyyy-MM-dd
|
|
242
|
+
* @param {boolean} includeContinuousFuture
|
|
243
|
+
* @returns
|
|
244
|
+
*/
|
|
245
|
+
getEODChartAPI = async (
|
|
246
|
+
interval,
|
|
247
|
+
assetType,
|
|
248
|
+
symbol,
|
|
249
|
+
exchangeType,
|
|
250
|
+
tillDate,
|
|
251
|
+
includeContinuousFuture
|
|
252
|
+
) => {
|
|
253
|
+
let result = {};
|
|
254
|
+
try {
|
|
255
|
+
//Convert into boolean
|
|
256
|
+
includeContinuousFuture = await this.convertToBoolean(
|
|
257
|
+
includeContinuousFuture
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
//Convert null string into null object
|
|
261
|
+
if (tillDate.toLowerCase() === "null") {
|
|
262
|
+
tillDate = null;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Validate eod chart params
|
|
266
|
+
*/
|
|
267
|
+
const validateResponse = validateChartEOD(
|
|
268
|
+
interval,
|
|
269
|
+
assetType,
|
|
270
|
+
symbol,
|
|
271
|
+
exchangeType,
|
|
272
|
+
tillDate,
|
|
273
|
+
includeContinuousFuture
|
|
274
|
+
);
|
|
275
|
+
if (validateResponse.error) {
|
|
276
|
+
log4js.debug(
|
|
277
|
+
"EOD chart validation error - " + validateResponse.error.details
|
|
278
|
+
);
|
|
279
|
+
return Promise.reject(validateResponse.error.details);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
//Request Body
|
|
283
|
+
const requestBodyData = this.chartRequestBody();
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* If AssetType Amongst FUTIDX, FUTSTK,FUTCUR,FUTCOM then we take user input(includeContinuousFuture) otherwise set false
|
|
287
|
+
*/
|
|
288
|
+
if (!Object.values(futureAssetType).includes(assetType)) {
|
|
289
|
+
includeContinuousFuture = false;
|
|
290
|
+
} else {
|
|
291
|
+
requestBodyData.conti = includeContinuousFuture;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
requestBodyData.ltt = tillDate;
|
|
295
|
+
|
|
296
|
+
const url = this.__config.ChartURL(
|
|
297
|
+
interval,
|
|
298
|
+
exchangeType,
|
|
299
|
+
assetType,
|
|
300
|
+
symbol
|
|
301
|
+
);
|
|
302
|
+
log4js.debug("EOD URL -" + url);
|
|
303
|
+
|
|
304
|
+
const response = await this.__http.PostMethod(url, requestBodyData);
|
|
305
|
+
if (result.length !== 0) {
|
|
306
|
+
result = this.modifyResponse(response);
|
|
307
|
+
} else {
|
|
308
|
+
result = response;
|
|
309
|
+
}
|
|
310
|
+
log4js.debug("EOD Result :" + JSON.stringify(result));
|
|
311
|
+
return result;
|
|
312
|
+
} catch (error) {
|
|
313
|
+
log4js.debug("EOD error - " + error);
|
|
314
|
+
return Promise.reject(error);
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
*
|
|
320
|
+
* @param {"D1" | "W1" | "MN1"} interval
|
|
321
|
+
* @param {"FUTSTK" | "FUTIDX" | "FUTCUR" | "FUTCOM" | "OPTIDX" | "OPTSTK" | "OPTCUR" | "OPTFUT" | "EQUITY" | "INDEX"} assetType
|
|
322
|
+
* @param {string} symbol
|
|
323
|
+
* @param {"NSE" | "BSE" | "NFO" | "BFO" | "CDS" | "MCX" | "NCDEX" | "INDEX"} exchangeType
|
|
324
|
+
* @param {string} fromDate yyyy-MM-dd
|
|
325
|
+
* @param {string} toDate yyyy-MM-dd
|
|
326
|
+
* @param {boolean} includeContinuousFuture
|
|
327
|
+
* @returns
|
|
328
|
+
*/
|
|
329
|
+
getCustomPeriodChartAPI = async (
|
|
330
|
+
interval,
|
|
331
|
+
assetType,
|
|
332
|
+
symbol,
|
|
333
|
+
exchangeType,
|
|
334
|
+
fromDate,
|
|
335
|
+
toDate,
|
|
336
|
+
includeContinuousFuture
|
|
337
|
+
) => {
|
|
338
|
+
let result = {};
|
|
339
|
+
try {
|
|
340
|
+
//Convert into boolean
|
|
341
|
+
includeContinuousFuture = await this.convertToBoolean(
|
|
342
|
+
includeContinuousFuture
|
|
343
|
+
);
|
|
344
|
+
interval = "D1"
|
|
345
|
+
/**
|
|
346
|
+
* Validate eod chart params
|
|
347
|
+
*/
|
|
348
|
+
const validateResponse = validateChartCustomPeriod(
|
|
349
|
+
interval,
|
|
350
|
+
assetType,
|
|
351
|
+
symbol,
|
|
352
|
+
exchangeType,
|
|
353
|
+
fromDate,
|
|
354
|
+
toDate,
|
|
355
|
+
includeContinuousFuture
|
|
356
|
+
);
|
|
357
|
+
if (validateResponse.error) {
|
|
358
|
+
log4js.debug(
|
|
359
|
+
"CustomPeriod chart validation error - " + JSON.stringify(validateResponse.error.details)
|
|
360
|
+
);
|
|
361
|
+
return Promise.reject(validateResponse.error.details);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
//Request Body
|
|
365
|
+
const requestBodyData = this.chartRequestBody();
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* If AssetType Amongst FUTIDX, FUTSTK,FUTCUR,FUTCOM then we take user input(includeContinuousFuture) otherwise set false
|
|
369
|
+
*/
|
|
370
|
+
if (!Object.values(futureAssetType).includes(assetType)) {
|
|
371
|
+
includeContinuousFuture = false;
|
|
372
|
+
} else {
|
|
373
|
+
requestBodyData.conti = includeContinuousFuture;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
requestBodyData.frmDt = fromDate;
|
|
377
|
+
requestBodyData.toDt = toDate;
|
|
378
|
+
requestBodyData.prdTyp = "CUST"
|
|
379
|
+
delete requestBodyData.ltt;
|
|
380
|
+
|
|
381
|
+
const url = this.__config.ChartURL(
|
|
382
|
+
interval,
|
|
383
|
+
exchangeType,
|
|
384
|
+
assetType,
|
|
385
|
+
symbol
|
|
386
|
+
);
|
|
387
|
+
log4js.debug("EOD URL -" + url);
|
|
388
|
+
|
|
389
|
+
const response = await this.__http.PostMethod(url, requestBodyData);
|
|
390
|
+
if (result.length !== 0) {
|
|
391
|
+
result = this.modifyResponseForCustomPeriod(response, toDate);
|
|
392
|
+
} else {
|
|
393
|
+
result = response;
|
|
394
|
+
}
|
|
395
|
+
log4js.debug("EOD Result :" + JSON.stringify(result));
|
|
396
|
+
return result;
|
|
397
|
+
} catch (error) {
|
|
398
|
+
log4js.debug("EOD error - " + error);
|
|
399
|
+
return Promise.reject(error);
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
}
|
|
404
|
+
module.exports = Chart;
|