api_connect_nodejs 2.0.1 → 2.0.4

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/src/apiUtils.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const fs = require("fs");
2
2
  const configData = require("./iniparser.js");
3
3
  const log4js = require("./logger.js");
4
+ const path = require("path");
4
5
  class __Constants {
5
6
  __VendorSession = "";
6
7
  __ApiKey = "";
@@ -10,6 +11,7 @@ class __Constants {
10
11
  __JSessionId = "";
11
12
  __AppIdKey = "";
12
13
  __Data = "";
14
+ __Prds = "";
13
15
 
14
16
  constructor() {
15
17
  this.__AppIdKey = configData.ApiIdKey;
@@ -79,6 +81,14 @@ class __Constants {
79
81
  this.__Data = val;
80
82
  }
81
83
 
84
+ get Prds() {
85
+ return this.__Prds;
86
+ }
87
+
88
+ set Prds(val) {
89
+ this.__Prds = val;
90
+ }
91
+
82
92
  //Check file exist or not
83
93
  fileExistOrNot = (path) => {
84
94
  let flag = false;
@@ -118,12 +128,94 @@ class __Constants {
118
128
  if (val === null) {
119
129
  return true;
120
130
  }
121
- if ((typeof val === "string") && (val.length === 0)) {
131
+ if (typeof val === "string" && val.length === 0) {
122
132
  return true;
123
133
  }
124
134
 
125
135
  return false;
126
136
  };
127
- }
128
137
 
138
+ getProductsAndExchange = (prds) => {
139
+ let res = {
140
+ exc: [],
141
+ prd: {},
142
+ };
143
+ prds.map((item) => {
144
+ const exc = item.exc;
145
+ res.exc.push(exc);
146
+ res.prd[exc] = [];
147
+ item.prd.map((item2) => {
148
+ res.prd[exc].push(item2.prdVal);
149
+ });
150
+ });
151
+ return Object.freeze(res);
152
+ };
153
+
154
+ readSessionFile = (sessionFile) => {
155
+ let absolutePath = path.resolve(`../../${sessionFile}`);
156
+ let data = fs.readFileSync(absolutePath, 'utf-8')
157
+ return JSON.parse(data);
158
+ }
159
+
160
+ getExchangesFromSession = (sessionFile) => {
161
+ let exchanges = []
162
+ let loginData = this.readSessionFile(sessionFile)
163
+ loginData.data.data.lgnData.prds.forEach(item => {
164
+ exchanges.push(item.exc)
165
+ });
166
+ return exchanges;
167
+ }
168
+
169
+ getValidProductCode = (sessionFile, userExchange, userProductCode) => {
170
+ let prdVal
171
+ //check if user exchange exist in session file
172
+ if (!this.getExchangesFromSession(sessionFile).includes(userExchange))
173
+ throw new Error('Invalid Exchange Passed')
174
+
175
+ let loginData = this.readSessionFile(sessionFile)
176
+
177
+ loginData.data.data.lgnData.prds.forEach(item => {
178
+ if (item.exc == userExchange) {
179
+ item.prd.forEach(x => {
180
+ if (x.prdVal == userProductCode) {
181
+ console.log(x.prdVal)
182
+ prdVal = x.prdVal
183
+ }
184
+
185
+ if (this.productCodeMap[userProductCode] === undefined) {
186
+ throw new Error('Product Code Does not exists')
187
+ }
188
+ if(prdVal === undefined)
189
+ prdVal = this.productCodeMap[userProductCode]
190
+ })
191
+ }
192
+ });
193
+ return prdVal;
194
+ }
195
+
196
+ productCodeMap = {
197
+ 'B': 'BO',
198
+ 'C': 'CNC',
199
+ 'F': 'MTF',
200
+ 'H': 'CO',
201
+ 'I': 'MIS',
202
+ 'M': 'NRML',
203
+ 'BO': 'B',
204
+ 'CNC': 'C',
205
+ 'MTF': 'F',
206
+ 'CO': 'H',
207
+ 'MIS': 'I',
208
+ 'NRML': 'M'
209
+ }
210
+
211
+ getAlternateActionName = (actionString) => {
212
+ let alternateExchange = ""
213
+ if (actionString.toUpperCase() == "BUY") {
214
+ alternateExchange = "B"
215
+ }else if (actionString.toUpperCase() == "SELL") {
216
+ alternateExchange = "S"
217
+ }
218
+ return alternateExchange;
219
+ }
220
+ }
129
221
  module.exports = __Constants;
package/src/config.js CHANGED
@@ -144,18 +144,6 @@ class __Config {
144
144
  return this.baseurleq + "trade/placebrackettrade/" + userid;
145
145
  };
146
146
 
147
- PlaceCoverTradeURL = function (userid) {
148
- return this.baseurleq + "trade/covertrade/" + userid;
149
- };
150
-
151
- ModifyCoverTradeURL = function (userid) {
152
- return this.baseurleq + "trade/modifycovertrade/" + userid;
153
- };
154
-
155
- ExitCoverTradeURL = function (userid) {
156
- return this.baseurleq + "trade/exitcovertrade/" + userid;
157
- };
158
-
159
147
  PlaceBasketTradeURL = function (userid) {
160
148
  return this.baseurleq + "trade/basketorder/" + userid;
161
149
  };
@@ -209,7 +197,7 @@ class __Config {
209
197
  };
210
198
 
211
199
  ModifyTradeURL_comm = function (userid) {
212
- return self.baseurlcomm + "trade/modifytrade/" + userid;
200
+ return this.baseurlcomm + "trade/modifytrade/" + userid;
213
201
  };
214
202
 
215
203
  CancelTradeURL = function (userid) {
@@ -240,8 +228,9 @@ class __Config {
240
228
  return this.baseurleq + "trade/amoflag";
241
229
  };
242
230
 
243
- GetAMOFlag_comm = function () {
244
- return this.baseurlcomm + "trade/amoflag";
231
+ GetAMOFlag_comm = function (exc) {
232
+ //return this.baseurlcomm + "trade/amoflag";
233
+ return this.baseurlcomm + `trade/amostatus/${exc}`;
245
234
  };
246
235
 
247
236
  PositionSqOffURL = function (userid) {
@@ -253,7 +242,7 @@ class __Config {
253
242
  };
254
243
 
255
244
  ConvertPositionURL_comm = function (userid) {
256
- return this.baseurlcomm + "trade/convertposition/v1/" + userid;
245
+ return this.baseurlcomm + "trade/positionconversion/" + userid;
257
246
  };
258
247
 
259
248
  PlaceAMOTrade = function (userid) {
@@ -261,7 +250,7 @@ class __Config {
261
250
  };
262
251
 
263
252
  PlaceAMOTrade_comm = function (userid) {
264
- return self.baseurlcomm + "trade/amo/placetrade/" + userid;
253
+ return this.baseurlcomm + "trade/amo/placetrade/" + userid;
265
254
  };
266
255
 
267
256
  ModifyAMOTrade = function (userid) {
@@ -319,7 +308,8 @@ class __Config {
319
308
  };
320
309
 
321
310
  LogoutURL = function (userid) {
322
- return this.baseurllogin + "accounts/" + userid + "/logout";
311
+ // return this.baseurllogin + "accounts/" + userid + "/logout";
312
+ return this.baseurllogin + "account/logoff/" + userid;
323
313
  };
324
314
  }
325
315