api_connect_nodejs 2.0.10 → 2.0.11

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.
Binary file
package/conf/settings.ini CHANGED
@@ -6,10 +6,11 @@ BasePathEq = https://nc.nuvamawealth.com/edelmw-eq/eq/
6
6
  BasePathComm = https://nc.nuvamawealth.com/edelmw-comm/comm/
7
7
  BasePathMf = https://nc.nuvamawealth.com/edelmw-mf/mf/
8
8
  BasePathContent = https://nc.nuvamawealth.com/edelmw-content/content/
9
+ BasePathReport = https://nc.nuvamawealth.com/app-report/equity/
9
10
  EquityContractURL = https://nc.nuvamawealth.com/app/toccontracts/instruments.zip
10
11
  MFContractURL = https://nc.nuvamawealth.com/app/toccontracts/mfInstruments.zip
11
12
 
12
- ApiIdKey = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHAiOjAsImZmIjoiVyIsImJkIjoid2ViLXBjIiwibmJmIjoxNjk4OTk0MTM1LCJzcmMiOiJlbXRtdyIsImF2IjoiMi4wLjYiLCJhcHBpZCI6IjhjZmE0MGJiYmUxMjQ5MGM2YzhjYzMwOWNlZmViZGQzIiwiaXNzIjoiZW10IiwiZXhwIjoxNjk5MDM2MjAwLCJpYXQiOjE2OTg5OTQ0MzV9.rwTusEQqt0VuYlW1-MSsixJm3RJGQTj2AFt8e_GsY3o
13
+ ApiIdKey = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHAiOjAsImZmIjoiVyIsImJkIjoid2ViLXBjIiwibmJmIjoxNzAzODUxOTQyLCJzcmMiOiJlbXRtdyIsImF2IjoiMi4wLjExIiwiYXBwaWQiOiI2NDE2ODVkOTExNjc0OTgyZDFjMGI5YzQzMmMxYWIyYiIsImlzcyI6ImVtdCIsImV4cCI6MTcwMzg3NDYwMCwiaWF0IjoxNzAzODUyMjQyfQ.m4RBAPmJc0RF1c1aR45kpVM7xPegx_F01F3nX-Bmiag
13
14
  TlsVersion = 1.2
14
15
  LogLevel = All
15
16
 
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Define segmentType as enum
3
+ */
4
+
5
+ const segmentType = Object.freeze({
6
+ EQUITY: "EQUITY",
7
+ COMMODITY: "COMMODITY",
8
+ });
9
+
10
+ module.exports = segmentType;
11
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api_connect_nodejs",
3
- "version": "2.0.10",
3
+ "version": "2.0.11",
4
4
  "description": "Command to run :",
5
5
  "main": "index.js",
6
6
  "directories": {
package/src/apiConnect.js CHANGED
@@ -4,6 +4,7 @@ const log4js = require("./logger.js");
4
4
  const Order = require("./order");
5
5
  const Chart = require("./chart");
6
6
  const Quote = require("./quote");
7
+ const Report = require("./report");
7
8
  const LiveNews = require("./liveNews");
8
9
  const Watchlist = require("./watchlist");
9
10
  const ResearchCalls = require("./researchCalls");
@@ -557,6 +558,41 @@ class APIConnect {
557
558
  return response;
558
559
  };
559
560
 
561
+ /**
562
+ *
563
+ * @param {"FUTSTK" | "FUTIDX" | "FUTCUR" | "FUTCOM" | "OPTIDX" | "OPTSTK" | "OPTCUR" | "OPTFUT" | "EQUITY" | "INDEX"} assetType
564
+ * @param {string} symbol
565
+ * @param {"NSE" | "BSE" | "NFO" | "NFO" | "MCX" | "NCDEX" | "INDEX"} exchangeType
566
+ * @param {string} fromDate yyyy-MM-dd
567
+ * @param {string} toDate yyyy-MM-dd
568
+ * @param {boolean} includeContinuousFuture
569
+ * @returns
570
+ */
571
+ getCustomPeriodChart = (
572
+ assetType,
573
+ symbol,
574
+ exchangeType,
575
+ fromDate,
576
+ toDate,
577
+ includeContinuousFuture = false
578
+ ) => {
579
+ let response = {};
580
+ log4js.info("getCustomPeriodChart method is called.");
581
+ let interval = "D1";
582
+ const chartObj = new Chart(this.__http, this.__config, this.__constants);
583
+ response = chartObj.getCustomPeriodChartAPI(
584
+ interval,
585
+ assetType,
586
+ symbol,
587
+ exchangeType,
588
+ fromDate,
589
+ toDate,
590
+ includeContinuousFuture
591
+ );
592
+
593
+ return response;
594
+ };
595
+
560
596
  //Get News Categories
561
597
  getNewsCategories = () => {
562
598
  log4js.info("Inside getNewsCategories method");
@@ -1268,6 +1304,7 @@ class APIConnect {
1268
1304
  exc: Exchange,
1269
1305
  prdCode: this.__constants.getValidProductCode(this.fileName, Exchange, ProductCode),
1270
1306
  ordTyp: Order_Type,
1307
+ curQty: CurrentQuantity,
1271
1308
  };
1272
1309
 
1273
1310
  if (Exchange == "MCX" || Exchange == "NCDEX") {
@@ -2476,6 +2513,27 @@ class APIConnect {
2476
2513
  return response;
2477
2514
  };
2478
2515
 
2516
+ //Get TRansaction History
2517
+ /**
2518
+ *
2519
+ * @param {string} segment
2520
+ * @param {string} fromDate
2521
+ * @param {string} toDate
2522
+ * @returns
2523
+ */
2524
+ getTransactionHistory = (
2525
+ segment, fromDate, toDate
2526
+ ) => {
2527
+ let response = {};
2528
+ log4js.info("getTransactionHistory method is called.");
2529
+ const reportObj = new Report(this.__http, this.__config, this.__constants);
2530
+ response = reportObj.getTransactionHistoryAPI(
2531
+ segment, fromDate, toDate
2532
+ );
2533
+
2534
+ return response;
2535
+ };
2536
+
2479
2537
  //CheckDependentAndUpdateData
2480
2538
  /**
2481
2539
  *
package/src/chart.js CHANGED
@@ -71,6 +71,66 @@ class Chart {
71
71
  }
72
72
  };
73
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
+
74
134
  convertToBoolean = async (value) => {
75
135
  if (value === "TRUE" || value === "true") {
76
136
  return true;
@@ -254,5 +314,91 @@ class Chart {
254
314
  return Promise.reject(error);
255
315
  }
256
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" | "NFO" | "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
+
257
403
  }
258
404
  module.exports = Chart;
package/src/config.js CHANGED
@@ -5,8 +5,10 @@ class __Config {
5
5
  baseurleq = "/edelmw-eq/eq/";
6
6
  baseurlcomm = "/edelmw-comm/comm/";
7
7
  baseurlcontent = "/edelmw-content/content/";
8
+ baseurlreport = "/app-report/equity/";
8
9
  baseurllogin = "/edelmw-login/login/";
9
10
  baseurlmf = "/edelmw-mf/mf/";
11
+
10
12
  EquityContractURL = "/app/toccontracts/instruments.zip";
11
13
  MFContractURL = "/app/toccontracts/mfInstruments.zip";
12
14
 
@@ -16,6 +18,7 @@ class __Config {
16
18
  this.baseurllogin = configData.BasePathLogin;
17
19
  this.baseurlmf = configData.BasePathMf;
18
20
  this.baseurlcontent = configData.BasePathContent;
21
+ this.baseurlreport = configData.BasePathReport;
19
22
  }
20
23
 
21
24
  ChartURL = function (interval, exc, aType, symbol) {
@@ -320,6 +323,20 @@ class __Config {
320
323
  MarketDepthURL = function (symbol) {
321
324
  return this.baseurlcontent + "quote/scrip/" + symbol;
322
325
  };
326
+
327
+ //TRANSACTION HISTORY
328
+ TransactionHistoryURL = function (accountCode, fromDate, toDate) {
329
+ return (
330
+ this.baseurlreport +
331
+ "pnl/transaction" +
332
+ "?accountId=" +
333
+ accountCode +
334
+ "&fromDate=" +
335
+ fromDate +
336
+ "&toDate=" +
337
+ toDate
338
+ );
339
+ };
323
340
  }
324
341
 
325
342
  module.exports = __Config;
package/src/http.js CHANGED
@@ -43,7 +43,6 @@ class __Http {
43
43
  res.on("end", () => {
44
44
  try {
45
45
  body = JSON.parse(Buffer.concat(body).toString());
46
-
47
46
  if (res.headers.appidkey) {
48
47
  this.__constants.AppIdKey = res.headers.appidkey;
49
48
  }
package/src/iniparser.js CHANGED
@@ -6,6 +6,7 @@ BasePathEq = "";
6
6
  BasePathComm = "";
7
7
  BasePathMf = "";
8
8
  BasePathContent = "";
9
+ BasePathReport = "";
9
10
  ApiIdKey = "";
10
11
  LogLevel = "";
11
12
  hostName = "";
@@ -19,6 +20,7 @@ const ConfigParser = function () {
19
20
  BasePathComm = config.GLOBAL.BasePathComm;
20
21
  BasePathMf = config.GLOBAL.BasePathMf;
21
22
  BasePathContent = config.GLOBAL.BasePathContent;
23
+ BasePathReport = config.GLOBAL.BasePathReport;
22
24
  ApiIdKey = config.GLOBAL.ApiIdKey;
23
25
  LogLevel = config.GLOBAL.LogLevel;
24
26
  hostName = config.STREAM.hostName;
@@ -39,4 +41,5 @@ module.exports = {
39
41
  port,
40
42
  formFactor,
41
43
  BasePathContent,
44
+ BasePathReport,
42
45
  };
package/src/report.js ADDED
@@ -0,0 +1,49 @@
1
+ const log4js = require("./logger.js");
2
+ const {
3
+ validateTransactionHistory,
4
+ } = require("../validations/reportValidator");
5
+ const segmentType = require("../enums/segmentType.js");
6
+
7
+ class Report {
8
+ constructor(http, config, constants) {
9
+ this.__http = http;
10
+ this.__config = config;
11
+ this.__constants = constants;
12
+ }
13
+
14
+ /**
15
+ *
16
+ * @param {string} symbol
17
+ * @returns
18
+ */
19
+ getTransactionHistoryAPI = async (segment, fromDate, toDate) => {
20
+ try {
21
+
22
+ /**
23
+ * Validate Transaction History params
24
+ */
25
+ const validateResponse = validateTransactionHistory(
26
+ segment,
27
+ fromDate,
28
+ toDate,
29
+ );
30
+ if (validateResponse.error) {
31
+ log4js.debug(
32
+ "Transaction History validation error - " + validateResponse.error.details
33
+ );
34
+ return Promise.reject(validateResponse.error.details);
35
+ }
36
+
37
+ const url = (segment == segmentType.EQUITY)
38
+ ? this.__config.TransactionHistoryURL(this.__constants.eqAccId, fromDate, toDate)
39
+ : this.__config.TransactionHistoryURL(this.__constants.coAccId, fromDate, toDate);
40
+ log4js.debug("Transaction History URL -" + url);
41
+ const response = await this.__http.GetMethod(url, false);
42
+ return response;
43
+ } catch (error) {
44
+ log4js.debug("Transaction History error - " + error);
45
+ return Promise.reject(error);
46
+ }
47
+ };
48
+ }
49
+ module.exports = Report;
@@ -0,0 +1,213 @@
1
+ const assert = require("chai").assert;
2
+ var { APIConnect } = require("../../../src/apiConnect");
3
+ var testConfig = require("../config");
4
+
5
+ const credentials = testConfig.equity;
6
+
7
+ edelconnectObj = async() => {
8
+ const edelObj = new APIConnect(
9
+ credentials.apiKey,
10
+ credentials.password,
11
+ credentials.reqId,
12
+ credentials.downloadContract
13
+ );
14
+ const res = await edelObj.Init();
15
+ return edelObj;
16
+ }
17
+
18
+ /**
19
+ * Command to run Test Cases "npm run testCustomPeriodChart"
20
+ */
21
+
22
+ describe("CustomPeriod chartTest", async function () {
23
+
24
+ describe("testCustomPeriodIfExchangeTypeIsNull", async function () {
25
+ let result;
26
+ before(async () => {
27
+ const edelObj = await edelconnectObj();
28
+
29
+ try {
30
+ result = await edelObj.getCustomPeriodChart(
31
+ "EQUITY", //assetType
32
+ "11423_NSE", //symbol
33
+ null, //exchangeType
34
+ "2023-10-06", //fromDate
35
+ "2023-11-06", //toDate
36
+ false //includeContinuousFuture
37
+ );
38
+ } catch(error) {
39
+ result = error;
40
+ }
41
+ });
42
+
43
+ it('"exc" must be one of [NSE, BSE, NFO, CDS, MCX, NCDEX, INDEX]', async function () {
44
+ assert.equal(
45
+ result[0].message,
46
+ '"exc" must be one of [NSE, BSE, NFO, CDS, MCX, NCDEX, INDEX]'
47
+ );
48
+ });
49
+
50
+ it('"exc" must be a string', async function () {
51
+ assert.equal(result[1].message, '"exc" must be a string');
52
+ });
53
+ });
54
+
55
+ describe("testCustomPeriodIfAssetTypeIsNull", async function () {
56
+ let result;
57
+ before(async () => {
58
+ const edelObj = await edelconnectObj();
59
+
60
+ try {
61
+ result = await edelObj.getCustomPeriodChart(
62
+ null, //assetType
63
+ "11423_NSE", //symbol
64
+ "NSE", //exchangeType
65
+ "2023-10-06", //fromDate
66
+ "2023-11-06", //toDate
67
+ false //includeContinuousFuture
68
+ );
69
+ } catch(error) {
70
+ result = error;
71
+ }
72
+ });
73
+
74
+ it('"assetType" must be one of [FUTSTK, FUTIDX, FUTCUR, FUTCOM, OPTIDX, OPTSTK, OPTCUR, OPTFUT, EQUITY, INDEX]', async function () {
75
+ assert.equal(
76
+ result[0].message,
77
+ '"aType" must be one of [FUTSTK, FUTIDX, FUTCUR, FUTCOM, OPTIDX, OPTSTK, OPTCUR, OPTFUT, EQUITY, INDEX]'
78
+ );
79
+ });
80
+
81
+ it('"assetType" must be a string', async function () {
82
+ assert.equal(result[1].message, '"aType" must be a string');
83
+ });
84
+ });
85
+
86
+ describe("testCustomPeriodIfFromDateIsNull", async function () {
87
+ let result;
88
+ before(async () => {
89
+ const edelObj = await edelconnectObj();
90
+ try {
91
+ result = await edelObj.getEODChart(
92
+ "EQUITY", //assetType
93
+ "11423_NSE", //symbol
94
+ "NSE", //exchangeType
95
+ null, //fromDate
96
+ "2023-11-06", //toDate
97
+ false //includeContinuousFuture
98
+ );
99
+ } catch (error) {
100
+ result = error;
101
+ }
102
+ });
103
+
104
+ it("testCustomPeriodIfFromDateIsNull", async function () {
105
+ assert.equal(
106
+ result[0].message,
107
+ '"From date" should not be null'
108
+ );
109
+ });
110
+
111
+ it('"From date" must be a string', async function () {
112
+ assert.equal(result[1].message, '"From date" must be a string');
113
+ });
114
+ });
115
+
116
+ describe("testCustomPeriodIfToDateIsNull", async function () {
117
+ let result;
118
+ before(async () => {
119
+ const edelObj = await edelconnectObj();
120
+ try {
121
+ result = await edelObj.getEODChart(
122
+ "EQUITY", //assetType
123
+ "11423_NSE", //symbol
124
+ "NSE", //exchangeType
125
+ "2023-11-06", //fromDate
126
+ null, //toDate
127
+ false //includeContinuousFuture
128
+ );
129
+ } catch (error) {
130
+ result = error;
131
+ }
132
+ });
133
+
134
+ it("testCustomPeriodIfToDateIsNull", async function () {
135
+ assert.equal(
136
+ result[0].message,
137
+ '"To date" should not be null'
138
+ );
139
+ });
140
+
141
+ it('"To date" must be a string', async function () {
142
+ assert.equal(result[1].message, '"To date" must be a string');
143
+ });
144
+ });
145
+
146
+ describe("testCustomPeriodIfSymbolIsNull", async function () {
147
+ let result;
148
+ before(async () => {
149
+ const edelObj = await edelconnectObj();
150
+ try {
151
+ result = await edelObj.getEODChart(
152
+ "EQUITY", //assetType
153
+ null, //symbol
154
+ "NSE", //exchangeType
155
+ "2023-10-06", //fromDate
156
+ "2023-11-06", //toDate
157
+ false //includeContinuousFuture
158
+ );
159
+ } catch (error) {
160
+ result = error;
161
+ }
162
+ });
163
+
164
+ it('"symbol" must be a string', async function () {
165
+ assert.equal(result[0].message, '"symbol" must be a string');
166
+ });
167
+ });
168
+
169
+ describe("IfallInputParamsHaveCorrectParams", async function () {
170
+ try {
171
+ const requestBodyObj = {
172
+ assetType: "EQUITY",
173
+ symbol: "11423_NSE",
174
+ exchangeType: "NSE",
175
+ fromDate:"2023-10-06", //fromDate
176
+ toDate:"2023-11-06", //toDate
177
+ includeContinuousFuture: false,
178
+ };
179
+ let response = {};
180
+
181
+ before(async () => {
182
+ const edelObj = await edelconnectObj();
183
+ try {
184
+ const result = await edelObj.getEODChart(
185
+ requestBodyObj.assetType,
186
+ requestBodyObj.symbol,
187
+ requestBodyObj.exchangeType,
188
+ requestBodyObj.fromDate,
189
+ requestBodyObj.toDate,
190
+ requestBodyObj.includeContinuousFuture
191
+ );
192
+ response = result;
193
+ } catch (error) {
194
+ console.log("error is ", error);
195
+ }
196
+ });
197
+
198
+ it("Response is not empty", async function () {
199
+ assert.isNotEmpty(response);
200
+ });
201
+
202
+ it("Response have msgID", async function () {
203
+ assert.isNotEmpty(response.msgID);
204
+ });
205
+
206
+ it("Response have srvTm", async function () {
207
+ assert.isNotNull(response.srvTm);
208
+ });
209
+ } catch (error) {
210
+ console.log("error is ", error);
211
+ }
212
+ });
213
+ });
@@ -30,11 +30,20 @@ validatePlaceTrade = (object, prds) => {
30
30
  ordTyp: Joi.string()
31
31
  .valid(...orderTypeArray)
32
32
  .required(),
33
- qty: Joi.number().required(),
33
+ qty: Joi.number()
34
+ .positive()
35
+ .required(),
34
36
  sym: Joi.string().required(),
35
- lmPrc: Joi.string().required(),
36
- dscQty: Joi.string(),
37
- trgPrc: Joi.string(),
37
+ lmPrc: Joi.string()
38
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
39
+ .required()
40
+ .error(new Error('Parameter Limit Price cannot be Negative or non-numeric')),
41
+ dscQty: Joi.string()
42
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
43
+ .error(new Error('Parameter Disclosed Quantity cannot be Negative or non-numeric')),
44
+ trgPrc: Joi.string()
45
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
46
+ .error(new Error('Parameter Trigger price cannot be Negative or non-numeric')),
38
47
  prdCode: Joi.string()
39
48
  // .valid(...prdName)
40
49
  .required(),
@@ -63,18 +72,29 @@ validateModifyTrade = (object, prds) => {
63
72
  ordTyp: Joi.string()
64
73
  .valid(...orderTypeArray)
65
74
  .required(),
66
- qty: Joi.number().required(),
75
+ qty: Joi.number()
76
+ .positive()
77
+ .required(),
67
78
  dscQty: Joi.string(),
68
79
  sym: Joi.string().required(),
69
- lmPrc: Joi.number().required(),
70
- trgPrc: Joi.string(),
80
+ lmPrc: Joi.number()
81
+ .min(0)
82
+ .required(),
83
+ trgPrc: Joi.string()
84
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
85
+ .error(new Error('Parameter trigger price cannot be Negative or non-numeric')),
71
86
  prdCode: Joi.string()
72
87
  // .valid(...prdName)
73
88
  .required(),
74
89
  nstOID: Joi.string().required(),
75
- curQty: Joi.string().required(),
90
+ curQty: Joi.string()
91
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
92
+ .required()
93
+ .error(new Error('Parameter Current Quantity cannot be Negative or non-numeric')),
76
94
  }).options({ abortEarly: false });
77
95
 
96
+ const re = modifyTradeSchema.validate(object);
97
+ console.log(re);
78
98
  return modifyTradeSchema.validate(object);
79
99
  };
80
100
 
@@ -94,8 +114,13 @@ validateCancelPlaceTrade = (object, prds) => {
94
114
  prdCode: Joi.string()
95
115
  // .valid(...prdName)
96
116
  .required(),
117
+ curQty: Joi.string()
118
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
119
+ .error(new Error('Parameter Current Quantity cannot be Negative or non-numeric'))
97
120
  }).options({ abortEarly: false });
98
121
 
122
+ const re = cancelPlaceTradeSchema.validate(object);
123
+ console.log(re);
99
124
  return cancelPlaceTradeSchema.validate(object);
100
125
  };
101
126
 
@@ -104,6 +129,7 @@ validateCancelPlaceTradeV1 = (object, prds) => {
104
129
  // if (prds.exc.includes(object.exc)) {
105
130
  // prdName = prds.prd[object.exc];
106
131
  // }
132
+
107
133
  const cancelPlaceTradeSchema = Joi.object({
108
134
  nstOID: Joi.string().required(),
109
135
  exc: Joi.string()
@@ -115,8 +141,12 @@ validateCancelPlaceTradeV1 = (object, prds) => {
115
141
  prdCode: Joi.string()
116
142
  // .valid(...prdName)
117
143
  .required(),
118
- curQty: Joi.string().required(),
119
- flQty: Joi.string().required(),
144
+ curQty: Joi.string().required()
145
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
146
+ .error(new Error('Parameter Current Quantity cannot be Negative or non-numeric')),
147
+ flQty: Joi.string().required()
148
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
149
+ .error(new Error('Parameter Fill Quantity cannot be Negative or non-numeric')),
120
150
  trdSym: Joi.string().required(),
121
151
  action: Joi.string()
122
152
  .valid(...actionTypeArray)
@@ -124,6 +154,8 @@ validateCancelPlaceTradeV1 = (object, prds) => {
124
154
  sym: Joi.string().required(),
125
155
  }).options({ abortEarly: false });
126
156
 
157
+ const re = cancelPlaceTradeSchema.validate(object);
158
+ console.log(re);
127
159
  return cancelPlaceTradeSchema.validate(object);
128
160
  };
129
161
 
@@ -146,8 +178,12 @@ validatePlaceGtcGtdTrade = (object, prds) => {
146
178
  ordTyp: Joi.string()
147
179
  .valid(...orderTypeArray)
148
180
  .required(),
149
- qty: Joi.number().required(),
150
- lmPrc: Joi.number().required(),
181
+ qty: Joi.number()
182
+ .positive()
183
+ .required(),
184
+ lmPrc: Joi.number()
185
+ .min(0)
186
+ .required(),
151
187
  prdCode: Joi.string()
152
188
  // .valid(...prdName)
153
189
  .required(),
@@ -155,6 +191,8 @@ validatePlaceGtcGtdTrade = (object, prds) => {
155
191
  sym: Joi.string().required(),
156
192
  }).options({ abortEarly: false });
157
193
 
194
+ const re = PlaceGtcGtdTradeSchema.validate(object);
195
+ console.log(re);
158
196
  return PlaceGtcGtdTradeSchema.validate(object);
159
197
  };
160
198
  validatePlaceAMOTrade = (object, prds) => {
@@ -176,16 +214,24 @@ validatePlaceAMOTrade = (object, prds) => {
176
214
  ordTyp: Joi.string()
177
215
  .valid(...orderTypeArray)
178
216
  .required(),
179
- qty: Joi.number().required(),
217
+ qty: Joi.number()
218
+ .positive()
219
+ .required(),
180
220
  dscQty: Joi.string(),
181
221
  sym: Joi.string().required(),
182
- lmPrc: Joi.number().required(),
183
- trgPrc: Joi.string(),
222
+ lmPrc: Joi.number()
223
+ .min(0)
224
+ .required(),
225
+ trgPrc: Joi.string()
226
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
227
+ .error(new Error('Parameter trigger price cannot be Negative or non-numeric')),
184
228
  prdCode: Joi.string()
185
229
  // .valid(...prdName)
186
230
  .required(),
187
231
  }).options({ abortEarly: false });
188
232
 
233
+ const re = placeAMOTradeSchema.validate(object);
234
+ console.log(re);
189
235
  return placeAMOTradeSchema.validate(object);
190
236
  };
191
237
 
@@ -208,18 +254,32 @@ validateModifyAMOTrade = (object, prds) => {
208
254
  ordTyp: Joi.string()
209
255
  .valid(...orderTypeArray)
210
256
  .required(),
211
- qty: Joi.number().required(),
212
- dscQty: Joi.string(),
213
- lmPrc: Joi.number().required(),
214
- trgPrc: Joi.string(),
257
+ qty: Joi.number()
258
+ .positive()
259
+ .required(),
260
+ dscQty: Joi.string()
261
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
262
+ .error(new Error('Parameter Disclosed Quantity cannot be Negative or non-numeric')),
263
+ lmPrc: Joi.number()
264
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
265
+ .required()
266
+ .error(new Error('Parameter limit price cannot be Negative or non-numeric')),
267
+ trgPrc: Joi.string()
268
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
269
+ .error(new Error('Parameter trigger price cannot be Negative or non-numeric')),
215
270
  prdCode: Joi.string()
216
271
  // .valid(...prdName)
217
272
  .required(),
218
273
  nstOID: Joi.string().required(),
219
274
  sym: Joi.string().required(),
220
- curQty: Joi.string().required(),
275
+ curQty: Joi.string()
276
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
277
+ .required()
278
+ .error(new Error('Parameter Current Quantity cannot be Negative or non-numeric')),
221
279
  }).options({ abortEarly: false });
222
280
 
281
+ const re = modifyAMOTradeSchema.validate(object);
282
+ console.log(re);
223
283
  return modifyAMOTradeSchema.validate(object);
224
284
  };
225
285
 
@@ -239,8 +299,13 @@ validateCancelAMOTrade = (object, prds) => {
239
299
  prdCode: Joi.string()
240
300
  // .valid(...prdName)
241
301
  .required(),
302
+ curQty: Joi.string()
303
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
304
+ .error(new Error('Parameter Current Quantity cannot be Negative or non-numeric')),
242
305
  }).options({ abortEarly: false });
243
306
 
307
+ const re = cancelAMOTradeSchema.validate(object);
308
+ console.log(re);
244
309
  return cancelAMOTradeSchema.validate(object);
245
310
  };
246
311
 
@@ -269,6 +334,8 @@ validateCancelAMOTradeV1 = (object, prds) => {
269
334
  sym: Joi.string().required(),
270
335
  }).options({ abortEarly: false });
271
336
 
337
+ const re = cancelAMOTradeSchema.validate(object);
338
+ console.log(re);
272
339
  return cancelAMOTradeSchema.validate(object);
273
340
  };
274
341
 
@@ -280,7 +347,10 @@ validateConvertPositionCOMM = (object, prds) => {
280
347
  const ConvertPositionCOMMSchema = Joi.object({
281
348
  sym: Joi.string().required(),
282
349
  cnvTyp: Joi.string().valid("D", "C").required(),
283
- qty: Joi.string().required(),
350
+ qty: Joi.string()
351
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
352
+ .required()
353
+ .error(new Error('Parameter Quantity cannot be Negative or non-numeric')),
284
354
  action: Joi.string().valid("B", "S").required(),
285
355
  prdCode: Joi.string()
286
356
  // .valid(...prdName)
@@ -295,6 +365,8 @@ validateConvertPositionCOMM = (object, prds) => {
295
365
  trdSym: Joi.string().required(),
296
366
  }).options({ abortEarly: false });
297
367
 
368
+ const re = ConvertPositionCOMMSchema.validate(object);
369
+ console.log(re);
298
370
  return ConvertPositionCOMMSchema.validate(object);
299
371
  };
300
372
 
@@ -321,7 +393,9 @@ validatePlaceMF = (object) => {
321
393
  isin: Joi.string().required(),
322
394
  txnTyp: Joi.string().required(),
323
395
  clientCode: Joi.string().required(),
324
- qty: Joi.number().required(),
396
+ qty: Joi.number()
397
+ .positive()
398
+ .required(),
325
399
  amt: Joi.number().positive().required(),
326
400
  reInvFlg: Joi.string().required(),
327
401
  folioNo: Joi.any().when("txnTyp", {
@@ -349,7 +423,9 @@ validateModifyMF = (object) => {
349
423
  isin: Joi.string().required(),
350
424
  txnTyp: Joi.string().required(),
351
425
  clientCode: Joi.string().required(),
352
- qty: Joi.number().required(),
426
+ qty: Joi.number()
427
+ .positive()
428
+ .required(),
353
429
  amt: Joi.number().positive().required(),
354
430
  reInvFlg: Joi.string().required(),
355
431
  folioNo: Joi.any().when("txnTyp", {
@@ -408,16 +484,33 @@ validatePlaceBracketTrade = (object, prds) => {
408
484
  .required(),
409
485
  sym: Joi.string().required(),
410
486
  trnsTyp: Joi.string().required(),
411
- qty: Joi.number().required(),
487
+ qty: Joi.number()
488
+ .positive()
489
+ .required(),
412
490
  dur: Joi.string().required(),
413
- dsQty: Joi.string().required(),
414
- prc: Joi.number().required(),
415
- slVal: Joi.string().required(),
416
- trlSl: Joi.string(),
417
- trlSlVal: Joi.string(),
418
- sqOffVal: Joi.string().required(),
491
+ dsQty: Joi.string()
492
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
493
+ .required()
494
+ .error(new Error('Parameter Disclosed Quantity cannot be Negative or non-numeric')),
495
+ prc: Joi.number()
496
+ .min(0)
497
+ .required(),
498
+ slVal: Joi.string()
499
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
500
+ .required()
501
+ .error(new Error('Parameter Stop Loss cannot be Negative or non-numeric')),
502
+ trlSl: Joi.string().valid("Y", "N").required(),
503
+ trlSlVal: Joi.string()
504
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
505
+ .error(new Error('Parameter Trailing stop loss value cannot be Negative or non-numeric')),
506
+ sqOffVal: Joi.string()
507
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
508
+ .required()
509
+ .error(new Error('Parameter Square off cannot be Negative or non-numeric')),
419
510
  }).options({ abortEarly: false });
420
511
 
512
+ const re = PlaceBracketTradeSchema.validate(object);
513
+ console.log(re);
421
514
  return PlaceBracketTradeSchema.validate(object);
422
515
  };
423
516
 
@@ -483,15 +576,26 @@ validatePlaceBasketTrade = (orderList, prds) => {
483
576
  dur: Joi.string()
484
577
  .valid(...validityArray)
485
578
  .required(),
486
- price: Joi.string().required(),
579
+ price: Joi.string()
580
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
581
+ .required()
582
+ .error(new Error('Parameter Price cannot be Negative or non-numeric')),
487
583
  trgPrc: Joi.string().required(),
488
- qty: Joi.number().required(),
489
- dscQty: Joi.string().required(),
584
+ qty: Joi.number()
585
+ .positive()
586
+ .required(),
587
+ dscQty: Joi.string()
588
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
589
+ .required()
590
+ .error(new Error('Parameter Disclosed Quantity cannot be Negative or non-numeric')),
490
591
  GTDDate: Joi.string().required(),
491
592
  rmk: Joi.string().allow("").required(),
492
593
  sym: Joi.string().required(),
493
594
  })
494
595
  .options({ abortEarly: false });
596
+
597
+ const re = orderListSchema.validate(item);
598
+ console.log(re);
495
599
  return orderListSchema.validate(item);
496
600
  });
497
601
  };
@@ -517,11 +621,23 @@ validatePositionSquareOff = (orderList, prds) => {
517
621
  ordTyp: Joi.string()
518
622
  .valid(...orderTypeArray)
519
623
  .required(),
520
- qty: Joi.string().required(),
521
- dscQty: Joi.string().required(),
624
+ qty: Joi.string()
625
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
626
+ .required()
627
+ .error(new Error('Parameter Quantity cannot be Negative or non-numeric')),
628
+ dscQty: Joi.string()
629
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
630
+ .required()
631
+ .error(new Error('Parameter Disclosed Quantity cannot be Negative or non-numeric')),
522
632
  sym: Joi.string().required(),
523
- trgPrc: Joi.string().required(),
524
- price: Joi.string().required(),
633
+ trgPrc: Joi.string()
634
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
635
+ .required()
636
+ .error(new Error('Parameter Trigger price cannot be Negative or non-numeric')),
637
+ price: Joi.string()
638
+ .pattern(new RegExp("^\\d+(\\.\\d+)?"))
639
+ .required()
640
+ .error(new Error('Parameter Price cannot be Negative or non-numeric')),
525
641
  prdCode: Joi.string()
526
642
  // .valid(...prdName)
527
643
  .required(),
@@ -529,6 +645,9 @@ validatePositionSquareOff = (orderList, prds) => {
529
645
  GTDDate: Joi.string().required(),
530
646
  })
531
647
  .options({ abortEarly: false });
648
+
649
+ const re = orderListSchema.validate(item);
650
+ console.log(re);
532
651
  return orderListSchema.validate(item);
533
652
  });
534
653
  };
@@ -79,7 +79,47 @@ validateChartEOD = (interval, aType, symbol, exc, tillDate, conti) => {
79
79
  return chartSchema.validate(paramsObject);
80
80
  };
81
81
 
82
+ /**
83
+ * Validate Chart CustomPeriod input params
84
+ */
85
+ validateChartCustomPeriod = (interval, aType, symbol, exc, fromDate, toDate, conti) => {
86
+ const paramsObject = {
87
+ interval: interval,
88
+ aType: aType,
89
+ symbol: symbol,
90
+ exc: exc,
91
+ fromDate: fromDate,
92
+ toDate: toDate,
93
+ conti: conti,
94
+ };
95
+
96
+ const chartSchema = Joi.object({
97
+ interval: Joi.string()
98
+ .valid(...eodIntervalTypeArray)
99
+ .required(),
100
+ aType: Joi.string()
101
+ .valid(...assetTypeArray)
102
+ .required(),
103
+ symbol: Joi.string().required(),
104
+ exc: Joi.string()
105
+ .valid(...chartExchangeTypeArray)
106
+ .required(),
107
+ fromDate: Joi.alternatives().try(
108
+ JoiDate.date().format("YYYY-MM-DD").utc(),
109
+ Joi.string().required()
110
+ ),
111
+ toDate: Joi.alternatives().try(
112
+ JoiDate.date().format("YYYY-MM-DD").utc(),
113
+ Joi.string().required()
114
+ ),
115
+ conti: Joi.boolean().strict(),
116
+ }).options({ abortEarly: false });
117
+
118
+ return chartSchema.validate(paramsObject);
119
+ };
120
+
82
121
  module.exports = {
83
122
  validateChartIntraday,
84
123
  validateChartEOD,
124
+ validateChartCustomPeriod,
85
125
  };
@@ -0,0 +1,35 @@
1
+ const Joi = require("Joi");
2
+
3
+ const enumSegmentType = require("../enums/segmentType");
4
+ const JoiDate = require("Joi").extend(require("@joi/date"));
5
+ const segmentTypeArray = Object.values(enumSegmentType);
6
+
7
+ /**
8
+ * Validate Transaction History input params
9
+ */
10
+ validateTransactionHistory = (segment,fromDate,toDate) => {
11
+ const paramsObject = {
12
+ segment,
13
+ fromDate,
14
+ toDate
15
+ };
16
+ const transactionHistoryParamsSchema = Joi.object({
17
+ segment: Joi.string()
18
+ .valid(...segmentTypeArray)
19
+ .required(),
20
+ fromDate: Joi.alternatives().try(
21
+ JoiDate.date().format("YYYY-MM-DD").utc(),
22
+ Joi.string().required()
23
+ ),
24
+ toDate: Joi.alternatives().try(
25
+ JoiDate.date().format("YYYY-MM-DD").utc(),
26
+ Joi.string().required()
27
+ ),
28
+ }).options({ abortEarly: false });
29
+
30
+ return transactionHistoryParamsSchema.validate(paramsObject);
31
+ };
32
+
33
+ module.exports = {
34
+ validateTransactionHistory
35
+ };
Binary file