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/README.md +1 -1
- package/conf/settings.ini +1 -1
- package/package.json +1 -1
- package/src/apiConnect.js +275 -357
- package/src/apiUtils.js +94 -2
- package/src/config.js +8 -18
- package/validations/apiConnectValidator.js +180 -167
package/src/apiConnect.js
CHANGED
|
@@ -20,9 +20,6 @@ const {
|
|
|
20
20
|
validateModifyTrade,
|
|
21
21
|
validateCancelPlaceTrade,
|
|
22
22
|
validatePlaceGtcGtdTrade,
|
|
23
|
-
validatePlaceCoverTrade,
|
|
24
|
-
validateModifyCoverTrade,
|
|
25
|
-
validateExitCoverTrade,
|
|
26
23
|
validatePlaceAMOTrade,
|
|
27
24
|
validateModifyAMOTrade,
|
|
28
25
|
validateCancelAMOTrade,
|
|
@@ -36,6 +33,8 @@ const {
|
|
|
36
33
|
validateOrderHistory,
|
|
37
34
|
validatePositionSquareOff,
|
|
38
35
|
validateMFOrderBook,
|
|
36
|
+
validateGetAMOStxatus,
|
|
37
|
+
validateConvertPositionEQ,
|
|
39
38
|
} = require("../validations/apiConnectValidator");
|
|
40
39
|
|
|
41
40
|
const {
|
|
@@ -62,7 +61,8 @@ class APIConnect {
|
|
|
62
61
|
this.reqId = reqId;
|
|
63
62
|
this.fileName = "data_" + apiKey + ".txt";
|
|
64
63
|
this.__http.fileName = this.fileName;
|
|
65
|
-
this.feedObject =
|
|
64
|
+
this.feedObject = new Feed();
|
|
65
|
+
this.excsAndprdDpNm = [];
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
/**
|
|
@@ -79,49 +79,64 @@ class APIConnect {
|
|
|
79
79
|
resolve(res);
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
|
+
const readFilePromise = new Promise((resolve, reject) => {
|
|
83
|
+
fs.readFile(this.fileName, "utf8", (err, data) => {
|
|
84
|
+
if (err) {
|
|
85
|
+
//var promises=[]
|
|
86
|
+
// if file doesn't exist, then generate it
|
|
87
|
+
// these two functions will fill the __constants and generate ${fileName}
|
|
88
|
+
// promises.push(this.__GenerateVendorSession(this.apiKey, this.password, this.reqId));
|
|
89
|
+
// promises.push(this.__GetAuthorization(this.reqId));
|
|
90
|
+
count++;
|
|
91
|
+
// Promise.all(promises).then(checkDone()).catch(reject());
|
|
92
|
+
this.__GenerateVendorSession(this.apiKey, this.password, this.reqId)
|
|
93
|
+
.then((res) => {
|
|
94
|
+
this.__GetAuthorization(this.reqId)
|
|
95
|
+
.then((res) => {
|
|
96
|
+
checkDone(res);
|
|
97
|
+
resolve(true);
|
|
98
|
+
})
|
|
99
|
+
.catch((err) => reject(err));
|
|
100
|
+
})
|
|
101
|
+
.catch((err) => reject(err));
|
|
102
|
+
} else {
|
|
103
|
+
const j = JSON.parse(data);
|
|
104
|
+
this.__constants.VendorSession = j.vt;
|
|
105
|
+
this.__constants.JSession = j.auth;
|
|
106
|
+
this.__constants.eqAccId = j.eqaccid;
|
|
107
|
+
this.__constants.coAccId = j.coaccid;
|
|
108
|
+
this.__constants.Data = j.data;
|
|
109
|
+
this.__constants.AppIdKey = j.appidkey;
|
|
110
|
+
this.__constants.profileId = j.data.data.lgnData.accs.prfId;
|
|
111
|
+
this.__constants.prds = j.data.data.lgnData.prds;
|
|
112
|
+
this.excsAndprdDpNm = this.__constants.getProductsAndExchange(
|
|
113
|
+
this.__constants.prds
|
|
114
|
+
);
|
|
115
|
+
count++;
|
|
116
|
+
checkDone();
|
|
117
|
+
resolve(true);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
82
121
|
|
|
83
122
|
// Check if ${fileName} exists
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
//var promises=[]
|
|
87
|
-
// if file doesn't exist, then generate it
|
|
88
|
-
// these two functions will fill the __constants and generate ${fileName}
|
|
89
|
-
// promises.push(this.__GenerateVendorSession(this.apiKey, this.password, this.reqId));
|
|
90
|
-
// promises.push(this.__GetAuthorization(this.reqId));
|
|
123
|
+
readFilePromise
|
|
124
|
+
.then((res) => {
|
|
91
125
|
count++;
|
|
92
|
-
|
|
93
|
-
this.
|
|
94
|
-
.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
126
|
+
this.__CheckUpdate().then(checkDone).catch(reject);
|
|
127
|
+
this.excsAndprdDpNm = this.__constants.getProductsAndExchange(
|
|
128
|
+
this.__constants.prds
|
|
129
|
+
);
|
|
130
|
+
this.__Instruments()
|
|
131
|
+
.then(async (res) => {
|
|
132
|
+
//console.log("instrument then");
|
|
133
|
+
checkDone(res);
|
|
100
134
|
})
|
|
101
135
|
.catch((err) => reject(err));
|
|
102
|
-
} else {
|
|
103
|
-
const j = JSON.parse(data);
|
|
104
|
-
this.__constants.VendorSession = j.vt;
|
|
105
|
-
this.__constants.JSession = j.auth;
|
|
106
|
-
this.__constants.eqAccId = j.eqaccid;
|
|
107
|
-
this.__constants.coAccId = j.coaccid;
|
|
108
|
-
this.__constants.Data = j.data;
|
|
109
|
-
this.__constants.AppIdKey = j.appidkey;
|
|
110
|
-
this.__constants.profileId = j.data.data.lgnData.accs.prfId;
|
|
111
|
-
count++;
|
|
112
|
-
checkDone();
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
count++;
|
|
116
|
-
this.feedObject = new Feed();
|
|
117
|
-
// this.__CheckUpdate().then(checkDone).catch(reject);
|
|
118
|
-
this.__Instruments()
|
|
119
|
-
.then((res) => {
|
|
120
|
-
//console.log("instrument then");
|
|
121
|
-
checkDone(res);
|
|
122
136
|
})
|
|
123
137
|
.catch((err) => {
|
|
124
|
-
|
|
138
|
+
delete this.feedObject;
|
|
139
|
+
reject(err)
|
|
125
140
|
});
|
|
126
141
|
});
|
|
127
142
|
};
|
|
@@ -185,14 +200,14 @@ class APIConnect {
|
|
|
185
200
|
if (res.data.msg === "MANDATORY") {
|
|
186
201
|
console.log(
|
|
187
202
|
"Mandatory Update. New version " +
|
|
188
|
-
|
|
203
|
+
res.data.vsn +
|
|
189
204
|
". Update to new version to continue."
|
|
190
205
|
);
|
|
191
206
|
process.exit();
|
|
192
207
|
} else if (res.data.msg === "OPTIONAL") {
|
|
193
208
|
console.log(
|
|
194
209
|
"New version " +
|
|
195
|
-
|
|
210
|
+
res.data.vsn +
|
|
196
211
|
" is available. Stay up to date for better experience"
|
|
197
212
|
);
|
|
198
213
|
}
|
|
@@ -200,7 +215,7 @@ class APIConnect {
|
|
|
200
215
|
} else {
|
|
201
216
|
throw res;
|
|
202
217
|
}
|
|
203
|
-
})
|
|
218
|
+
})
|
|
204
219
|
};
|
|
205
220
|
|
|
206
221
|
/**
|
|
@@ -360,12 +375,12 @@ class APIConnect {
|
|
|
360
375
|
addSymbolWatchlist = (groupName, symLst) => {
|
|
361
376
|
let res = {};
|
|
362
377
|
log4js.info("Inside addSymbolWatchlist method");
|
|
363
|
-
const
|
|
378
|
+
const watchlistObj = new Watchlist(
|
|
364
379
|
this.__http,
|
|
365
380
|
this.__config,
|
|
366
381
|
this.__constants
|
|
367
382
|
);
|
|
368
|
-
res =
|
|
383
|
+
res = watchlistObj.addSymbolWatchlist(groupName, symLst);
|
|
369
384
|
return res;
|
|
370
385
|
};
|
|
371
386
|
|
|
@@ -384,12 +399,12 @@ class APIConnect {
|
|
|
384
399
|
deleteSymbolWatchlist = (groupName, symLst) => {
|
|
385
400
|
let res = {};
|
|
386
401
|
log4js.info("Inside deleteSymbolWatchlist method");
|
|
387
|
-
const
|
|
402
|
+
const watchlistObj = new Watchlist(
|
|
388
403
|
this.__http,
|
|
389
404
|
this.__config,
|
|
390
405
|
this.__constants
|
|
391
406
|
);
|
|
392
|
-
res =
|
|
407
|
+
res = watchlistObj.deleteSymbolWatchlist(groupName, symLst);
|
|
393
408
|
return res;
|
|
394
409
|
};
|
|
395
410
|
|
|
@@ -407,12 +422,12 @@ class APIConnect {
|
|
|
407
422
|
deleteWatchlistGroups = (groups) => {
|
|
408
423
|
let res = {};
|
|
409
424
|
log4js.info("Inside deleteWatchlistGroups method");
|
|
410
|
-
const
|
|
425
|
+
const watchlistObj = new Watchlist(
|
|
411
426
|
this.__http,
|
|
412
427
|
this.__config,
|
|
413
428
|
this.__constants
|
|
414
429
|
);
|
|
415
|
-
res =
|
|
430
|
+
res = watchlistObj.deleteWatchlistGroups(groups);
|
|
416
431
|
return res;
|
|
417
432
|
};
|
|
418
433
|
|
|
@@ -431,12 +446,12 @@ class APIConnect {
|
|
|
431
446
|
renameWatchlistGroup = (groupName, newGroupName) => {
|
|
432
447
|
let res = {};
|
|
433
448
|
log4js.info("renameWatchlistGroup method is called.");
|
|
434
|
-
const
|
|
449
|
+
const watchlistObj = new Watchlist(
|
|
435
450
|
this.__http,
|
|
436
451
|
this.__config,
|
|
437
452
|
this.__constants
|
|
438
453
|
);
|
|
439
|
-
res =
|
|
454
|
+
res = watchlistObj.renameWatchlistGroup(groupName, newGroupName);
|
|
440
455
|
return res;
|
|
441
456
|
};
|
|
442
457
|
/**
|
|
@@ -821,7 +836,11 @@ class APIConnect {
|
|
|
821
836
|
* @returns Promise that resolves to the details of single order
|
|
822
837
|
*/
|
|
823
838
|
OrderDetails = (orderId, Exchange) => {
|
|
824
|
-
const validateResponse = validateOrderDetails(
|
|
839
|
+
const validateResponse = validateOrderDetails(
|
|
840
|
+
orderId,
|
|
841
|
+
Exchange,
|
|
842
|
+
this.excsAndprdDpNm
|
|
843
|
+
);
|
|
825
844
|
if (validateResponse.error) {
|
|
826
845
|
log4js.debug(
|
|
827
846
|
"OrderDetails validation error -" + validateResponse.error.details
|
|
@@ -915,15 +934,15 @@ class APIConnect {
|
|
|
915
934
|
* Order placement refers to the function by which you as a user can place an order to respective exchanges. Order placement allows you to set various parameters like the symbol, action (buy, sell, stop loss buy, stop loss sell), product type, validity period and few other custom parameters and then finally place the order. Any order placed will first go through a risk validation in our internal systems and will then be sent to exchange. Usually any order successfully placed will have OrderID and ExchangeOrderID fields populated. If ExchangeOrderID is blank it usually means that the order has not been sent and accepted at respective exchange.
|
|
916
935
|
* @param {string} Trading_Symbol Trading Symbol of the Scrip
|
|
917
936
|
* @param {string} Exchange Exchange
|
|
918
|
-
* @param {
|
|
919
|
-
* @param {
|
|
920
|
-
* @param {
|
|
937
|
+
* @param {string} Action BUY | SELL
|
|
938
|
+
* @param {string} Duration DAY | IOC | EOS(for BSE)
|
|
939
|
+
* @param {string} Order_Type LIMIT | MARKET | STOP_LIMIT | STOP_MARKET
|
|
921
940
|
* @param {number} Quantity Quantity of the Scrip
|
|
922
941
|
* @param {string} Streaming_Symbol companycode_exchange to be obtained from Contract file downloaded
|
|
923
942
|
* @param {number} Limit_Price Limit price of the Scrip
|
|
924
943
|
* @param {string} Disclosed_Quantity Quantity to be disclosed while order placement
|
|
925
944
|
* @param {string} TriggerPrice Trigger Price applicable for SL/SL-M Orders
|
|
926
|
-
* @param {
|
|
945
|
+
* @param {string} ProductCode CNC | MIS | NRML | MTF
|
|
927
946
|
* @returns Promise that resolves/rejects to Place trade api response
|
|
928
947
|
*/
|
|
929
948
|
PlaceTrade = (
|
|
@@ -937,10 +956,11 @@ class APIConnect {
|
|
|
937
956
|
Limit_Price,
|
|
938
957
|
Disclosed_Quantity = "0",
|
|
939
958
|
TriggerPrice = "0",
|
|
940
|
-
ProductCode
|
|
959
|
+
ProductCode
|
|
941
960
|
) => {
|
|
942
961
|
log4js.info("Inside PlaceTrade method");
|
|
943
|
-
|
|
962
|
+
|
|
963
|
+
let paramsObj = {
|
|
944
964
|
trdSym: Trading_Symbol,
|
|
945
965
|
exc: Exchange,
|
|
946
966
|
action: Action,
|
|
@@ -953,7 +973,7 @@ class APIConnect {
|
|
|
953
973
|
trgPrc: TriggerPrice,
|
|
954
974
|
prdCode: ProductCode,
|
|
955
975
|
};
|
|
956
|
-
const validateResponse = validatePlaceTrade(paramsObj);
|
|
976
|
+
const validateResponse = validatePlaceTrade(paramsObj, this.excsAndprdDpNm);
|
|
957
977
|
if (validateResponse.error) {
|
|
958
978
|
log4js.debug(
|
|
959
979
|
"PlaceTrade validation error -" + validateResponse.error.details
|
|
@@ -973,7 +993,7 @@ class APIConnect {
|
|
|
973
993
|
mktPro: "",
|
|
974
994
|
lmPrc: Limit_Price,
|
|
975
995
|
trgPrc: TriggerPrice,
|
|
976
|
-
prdCode: ProductCode,
|
|
996
|
+
prdCode: this.__constants.getValidProductCode(this.fileName, Exchange, ProductCode),
|
|
977
997
|
posSqr: "N",
|
|
978
998
|
minQty: "0",
|
|
979
999
|
ordSrc: "API",
|
|
@@ -997,90 +1017,6 @@ class APIConnect {
|
|
|
997
1017
|
}
|
|
998
1018
|
};
|
|
999
1019
|
|
|
1000
|
-
/**
|
|
1001
|
-
* A Cover Order is an order type for intraday trades. A Cover Order lets you to place trades with very high leverage of up to 20 times the available limits (Cash/Stocks collateral limits)
|
|
1002
|
-
*
|
|
1003
|
-
* Pay a fraction of total order amount (10% or Rs. 20) to own the shares. In case it falls below the following price, sell it off to prevent me losing money from sharp price drops.
|
|
1004
|
-
* @param {string} Trading_Symbol Trading Symbol of the Scrip
|
|
1005
|
-
* @param {string} Exchange Exchange
|
|
1006
|
-
* @param {'BUY' | 'SELL'} Action BUY | SELL
|
|
1007
|
-
* @param {'DAY' | 'IOC' | 'EOS'} Duration DAY | IOC | EOS(for BSE)
|
|
1008
|
-
* @param {'LIMIT' | 'MARKET' | 'STOP_LIMIT' | 'STOP_MARKET'} Order_Type LIMIT | MARKET | STOP_LIMIT | STOP_MARKET
|
|
1009
|
-
* @param {number} Quantity Quantity of the Scrip
|
|
1010
|
-
* @param {string} Streaming_Symbol companycode_exchange to be obtained from Contract file downloaded
|
|
1011
|
-
* @param {number} Limit_Price Limit price of the Scrip
|
|
1012
|
-
* @param {string} Disclosed_Quantity Quantity to be disclosed while order placement
|
|
1013
|
-
* @param {string} TriggerPrice Trigger Price applicable for SL/SL-M Orders
|
|
1014
|
-
* @param {'CNC' | 'MIS' | 'NRML' | 'MTF'} ProductCode CNC | MIS | NRML | MTF
|
|
1015
|
-
* @returns Promise that resolves/rejects to Place Cover Order api response
|
|
1016
|
-
*/
|
|
1017
|
-
PlaceCoverTrade = (
|
|
1018
|
-
Trading_Symbol,
|
|
1019
|
-
Exchange,
|
|
1020
|
-
Action,
|
|
1021
|
-
Duration,
|
|
1022
|
-
Order_Type,
|
|
1023
|
-
Quantity,
|
|
1024
|
-
Streaming_Symbol,
|
|
1025
|
-
Limit_Price,
|
|
1026
|
-
Disclosed_Quantity = "0",
|
|
1027
|
-
TriggerPrice = "0",
|
|
1028
|
-
ProductCode = "CNC"
|
|
1029
|
-
) => {
|
|
1030
|
-
log4js.info("Inside PlaceCoverTrade method");
|
|
1031
|
-
if (Exchange == "MCX" || Exchange == "NCDEX") {
|
|
1032
|
-
console.log("Operation invalid for commodities");
|
|
1033
|
-
return Promise.reject(new Error("Operation invalid for commodities"));
|
|
1034
|
-
}
|
|
1035
|
-
const paramsObj = {
|
|
1036
|
-
trdSym: Trading_Symbol,
|
|
1037
|
-
exc: Exchange,
|
|
1038
|
-
action: Action,
|
|
1039
|
-
dur: Duration,
|
|
1040
|
-
ordTyp: Order_Type,
|
|
1041
|
-
qty: Quantity,
|
|
1042
|
-
sym: Streaming_Symbol,
|
|
1043
|
-
lmPrc: Limit_Price,
|
|
1044
|
-
dscQty: Disclosed_Quantity,
|
|
1045
|
-
trgPrc: TriggerPrice,
|
|
1046
|
-
prdCode: ProductCode,
|
|
1047
|
-
};
|
|
1048
|
-
const validateResponse = validatePlaceCoverTrade(paramsObj);
|
|
1049
|
-
if (validateResponse.error) {
|
|
1050
|
-
log4js.debug(
|
|
1051
|
-
"PlaceCoverTrade validation error -" + validateResponse.error.details
|
|
1052
|
-
);
|
|
1053
|
-
return Promise.reject(validateResponse.error.details);
|
|
1054
|
-
}
|
|
1055
|
-
|
|
1056
|
-
const data = {
|
|
1057
|
-
trdSym: Trading_Symbol,
|
|
1058
|
-
exc: Exchange,
|
|
1059
|
-
action: Action,
|
|
1060
|
-
dur: Duration,
|
|
1061
|
-
ordTyp: Order_Type,
|
|
1062
|
-
qty: Quantity,
|
|
1063
|
-
dscQty: Disclosed_Quantity,
|
|
1064
|
-
sym: Streaming_Symbol,
|
|
1065
|
-
mktPro: "",
|
|
1066
|
-
lmPrc: Limit_Price,
|
|
1067
|
-
trgPrc: TriggerPrice,
|
|
1068
|
-
prdCode: ProductCode,
|
|
1069
|
-
posSqr: "false",
|
|
1070
|
-
minQty: "0",
|
|
1071
|
-
ordSrc: "API",
|
|
1072
|
-
vnCode: "",
|
|
1073
|
-
rmk: "",
|
|
1074
|
-
flQty: "0",
|
|
1075
|
-
};
|
|
1076
|
-
|
|
1077
|
-
log4js.debug("PlaceCoverTrade Data :" + JSON.stringify(data));
|
|
1078
|
-
const url = this.__config.PlaceCoverTradeURL(this.__constants.eqAccId);
|
|
1079
|
-
log4js.debug("PlaceCoverTrade URLS -" + url);
|
|
1080
|
-
var result = this.__http.PostMethod(url, data);
|
|
1081
|
-
log4js.debug("PlaceCoverTrade Result :" + JSON.stringify(result));
|
|
1082
|
-
return result;
|
|
1083
|
-
};
|
|
1084
1020
|
|
|
1085
1021
|
/**
|
|
1086
1022
|
* Good Till Cancel (GTC) orders refers to orders where the validity period of the order is upto execution, cancellation by user or 90 days whichever comes first. This is a validity period used when you want to fire and forget an order and is usually an order placed with a limit price.
|
|
@@ -1090,13 +1026,13 @@ class APIConnect {
|
|
|
1090
1026
|
* GTC order is active until the trade is executed or trader cancels the order. GTD orders remains active until a user specified date/7 days whichever is earlier or it has been filled or cancelled.
|
|
1091
1027
|
* @param {string} Trading_Symbol Trading Symbol of the Scrip
|
|
1092
1028
|
* @param {string} Exchange Exchange
|
|
1093
|
-
* @param {
|
|
1094
|
-
* @param {
|
|
1095
|
-
* @param {
|
|
1029
|
+
* @param {string} Action BUY | SELL
|
|
1030
|
+
* @param {string} Duration GTC | GTD
|
|
1031
|
+
* @param {string} Order_Type LIMIT | MARKET | STOP_LIMIT | STOP_MARKET
|
|
1096
1032
|
* @param {number} Quantity Quantity of the Scrip
|
|
1097
1033
|
* @param {number} Limit_Price Limit price of the Scrip
|
|
1098
1034
|
* @param {string} streaming_symbol companycode_exchange to be obtained from Contract file downloaded
|
|
1099
|
-
* @param {
|
|
1035
|
+
* @param {string} Product_Code CNC | MIS | NRML | MTF
|
|
1100
1036
|
* @param {string} DTDays Date for GTD Orders in dd/MM/yyyy formaat
|
|
1101
1037
|
* @returns Promise that resolves/rejects to Place GTC/GTD trade api response
|
|
1102
1038
|
*/
|
|
@@ -1125,7 +1061,10 @@ class APIConnect {
|
|
|
1125
1061
|
prdCode: Product_Code,
|
|
1126
1062
|
dtDays: DTDays,
|
|
1127
1063
|
};
|
|
1128
|
-
const validateResponse = validatePlaceGtcGtdTrade(
|
|
1064
|
+
const validateResponse = validatePlaceGtcGtdTrade(
|
|
1065
|
+
paramsObj,
|
|
1066
|
+
this.excsAndprdDpNm
|
|
1067
|
+
);
|
|
1129
1068
|
if (validateResponse.error) {
|
|
1130
1069
|
log4js.debug(
|
|
1131
1070
|
"PlaceGtcGtdTrade validation error -" + validateResponse.error.details
|
|
@@ -1141,7 +1080,7 @@ class APIConnect {
|
|
|
1141
1080
|
ordTyp: Order_Type,
|
|
1142
1081
|
qty: Quantity,
|
|
1143
1082
|
lmPrc: Limit_Price,
|
|
1144
|
-
prdCode: Product_Code,
|
|
1083
|
+
prdCode: this.__constants.getValidProductCode(this.fileName, Exchange, Product_Code),
|
|
1145
1084
|
dtDays: DTDays,
|
|
1146
1085
|
ordSrc: "API",
|
|
1147
1086
|
vnCode: "",
|
|
@@ -1173,15 +1112,15 @@ class APIConnect {
|
|
|
1173
1112
|
* Modify orders allows a user to change certain aspects of the order once it is placed. Depending on the execution state of the order (i.e. either completely open, partially open) there are various levels of modification allowed. As a user you can edit the product type, order quantity, order validity and certain other parameters. Please note that any modifications made to an order will be sent back to the risk system for validation before being submitted and there are chances that an already placed order may get rejected in case of a modification.
|
|
1174
1113
|
* @param {string} Trading_Symbol Trading Symbol of the Scrip
|
|
1175
1114
|
* @param {string} Exchange Exchange
|
|
1176
|
-
* @param {
|
|
1177
|
-
* @param {
|
|
1178
|
-
* @param {
|
|
1115
|
+
* @param {string} Action BUY | SELL
|
|
1116
|
+
* @param {string} Duration DAY | IOC | EOS(for BSE)
|
|
1117
|
+
* @param {string} Order_Type LIMIT | MARKET | STOP_LIMIT | STOP_MARKET
|
|
1179
1118
|
* @param {number} Quantity Quantity of the Scrip
|
|
1180
1119
|
* @param {string} Streaming_Symbol companycode_exchange to be obtained from Contract file downloaded
|
|
1181
1120
|
* @param {number} Limit_Price Limit price of the Scrip
|
|
1182
1121
|
* @param {string} Disclosed_Quantity Quantity to be disclosed while order placement
|
|
1183
1122
|
* @param {string} TriggerPrice Trigger Price applicable for SL/SL-M Orders
|
|
1184
|
-
* @param {
|
|
1123
|
+
* @param {string} ProductCode CNC | MIS | NRML | MTF
|
|
1185
1124
|
* @returns Promise that resolves/rejects to Modify Order api response
|
|
1186
1125
|
*/
|
|
1187
1126
|
ModifyTrade = (
|
|
@@ -1196,7 +1135,7 @@ class APIConnect {
|
|
|
1196
1135
|
Order_ID,
|
|
1197
1136
|
Disclosed_Quantity = "0",
|
|
1198
1137
|
TriggerPrice = "0",
|
|
1199
|
-
ProductCode
|
|
1138
|
+
ProductCode
|
|
1200
1139
|
) => {
|
|
1201
1140
|
log4js.info("Inside ModifyTrade method");
|
|
1202
1141
|
const paramsObj = {
|
|
@@ -1213,7 +1152,10 @@ class APIConnect {
|
|
|
1213
1152
|
trgPrc: TriggerPrice,
|
|
1214
1153
|
prdCode: ProductCode,
|
|
1215
1154
|
};
|
|
1216
|
-
const validateResponse = validateModifyTrade(
|
|
1155
|
+
const validateResponse = validateModifyTrade(
|
|
1156
|
+
paramsObj,
|
|
1157
|
+
this.excsAndprdDpNm
|
|
1158
|
+
);
|
|
1217
1159
|
if (validateResponse.error) {
|
|
1218
1160
|
log4js.debug(
|
|
1219
1161
|
"ModifyTrade validation error -" + validateResponse.error.details
|
|
@@ -1233,7 +1175,7 @@ class APIConnect {
|
|
|
1233
1175
|
mktPro: "",
|
|
1234
1176
|
lmPrc: Limit_Price,
|
|
1235
1177
|
trgPrc: TriggerPrice,
|
|
1236
|
-
prdCode: ProductCode,
|
|
1178
|
+
prdCode: this.__constants.getValidProductCode(this.fileName, Exchange, ProductCode),
|
|
1237
1179
|
dtDays: "",
|
|
1238
1180
|
nstOID: Order_ID,
|
|
1239
1181
|
valid: false,
|
|
@@ -1254,94 +1196,12 @@ class APIConnect {
|
|
|
1254
1196
|
return result;
|
|
1255
1197
|
}
|
|
1256
1198
|
};
|
|
1257
|
-
|
|
1258
|
-
/**
|
|
1259
|
-
* Modify Cover Order
|
|
1260
|
-
* @param {string} Trading_Symbol Trading Symbol of the Scrip
|
|
1261
|
-
* @param {string} Exchange Exchange
|
|
1262
|
-
* @param {'BUY' | 'SELL'} Action BUY | SELL
|
|
1263
|
-
* @param {'DAY' | 'IOC' | 'EOS'} Duration DAY | IOC | EOS(for BSE)
|
|
1264
|
-
* @param {'LIMIT' | 'MARKET' | 'STOP_LIMIT' | 'STOP_MARKET'} Order_Type LIMIT | MARKET | STOP_LIMIT | STOP_MARKET
|
|
1265
|
-
* @param {number} Quantity Quantity of the Scrip
|
|
1266
|
-
* @param {string} Streaming_Symbol companycode_exchange to be obtained from Contract file downloaded
|
|
1267
|
-
* @param {number} Limit_Price Limit price of the Scrip
|
|
1268
|
-
* @param {string} Disclosed_Quantity Quantity to be disclosed while order placement
|
|
1269
|
-
* @param {string} TriggerPrice Trigger Price applicable for SL/SL-M Orders
|
|
1270
|
-
* @param {'CNC' | 'MIS' | 'NRML' | 'MTF'} ProductCode CNC | MIS | NRML | MTF
|
|
1271
|
-
* @returns Promise that resolves/rejects to Modify Cover Order api response
|
|
1272
|
-
*/
|
|
1273
|
-
ModifyCoverTrade = (
|
|
1274
|
-
Trading_Symbol,
|
|
1275
|
-
Exchange,
|
|
1276
|
-
Action,
|
|
1277
|
-
Duration,
|
|
1278
|
-
Order_Type,
|
|
1279
|
-
Quantity,
|
|
1280
|
-
Streaming_Symbol,
|
|
1281
|
-
Limit_Price,
|
|
1282
|
-
Order_ID,
|
|
1283
|
-
Disclosed_Quantity = "0",
|
|
1284
|
-
TriggerPrice = "0",
|
|
1285
|
-
ProductCode = "CNC"
|
|
1286
|
-
) => {
|
|
1287
|
-
log4js.info("Inside ModifyCoverTrade method");
|
|
1288
|
-
if (Exchange == "MCX" || Exchange == "NCDEX") {
|
|
1289
|
-
console.log("Operation invalid for commodities");
|
|
1290
|
-
return Promise.reject(new Error("Operation invalid for commodities"));
|
|
1291
|
-
}
|
|
1292
|
-
const paramsObj = {
|
|
1293
|
-
trdSym: Trading_Symbol,
|
|
1294
|
-
exc: Exchange,
|
|
1295
|
-
action: Action,
|
|
1296
|
-
dur: Duration,
|
|
1297
|
-
ordTyp: Order_Type,
|
|
1298
|
-
qty: Quantity,
|
|
1299
|
-
sym: Streaming_Symbol,
|
|
1300
|
-
lmPrc: Limit_Price,
|
|
1301
|
-
nstOID: Order_ID,
|
|
1302
|
-
dscQty: Disclosed_Quantity,
|
|
1303
|
-
trgPrc: TriggerPrice,
|
|
1304
|
-
prdCode: ProductCode,
|
|
1305
|
-
};
|
|
1306
|
-
const validateResponse = validateModifyCoverTrade(paramsObj);
|
|
1307
|
-
if (validateResponse.error) {
|
|
1308
|
-
log4js.debug(
|
|
1309
|
-
"ModifyCoverTrade validation error -" + validateResponse.error.details
|
|
1310
|
-
);
|
|
1311
|
-
return Promise.reject(validateResponse.error.details);
|
|
1312
|
-
}
|
|
1313
|
-
const data = {
|
|
1314
|
-
trdSym: Trading_Symbol,
|
|
1315
|
-
exc: Exchange,
|
|
1316
|
-
action: Action,
|
|
1317
|
-
dur: Duration,
|
|
1318
|
-
flQty: "0",
|
|
1319
|
-
ordTyp: Order_Type,
|
|
1320
|
-
qty: Quantity,
|
|
1321
|
-
dscQty: Disclosed_Quantity,
|
|
1322
|
-
sym: Streaming_Symbol,
|
|
1323
|
-
mktPro: "",
|
|
1324
|
-
lmPrc: Limit_Price,
|
|
1325
|
-
trgPrc: TriggerPrice,
|
|
1326
|
-
prdCode: ProductCode,
|
|
1327
|
-
dtDays: "",
|
|
1328
|
-
nstOID: Order_ID,
|
|
1329
|
-
};
|
|
1330
|
-
|
|
1331
|
-
log4js.debug("ModifyCoverTrade Data :" + JSON.stringify(data));
|
|
1332
|
-
const url = this.__config.ModifyCoverTradeURL(this.__constants.eqAccId);
|
|
1333
|
-
log4js.debug("ModifyCoverTrade URLS -" + url);
|
|
1334
|
-
var result = this.__http.PutMethod(url, data);
|
|
1335
|
-
log4js.debug("ModifyCoverTrade Result :" + JSON.stringify(result));
|
|
1336
|
-
return result;
|
|
1337
|
-
};
|
|
1338
|
-
|
|
1339
1199
|
/**
|
|
1340
1200
|
* An order can be cancelled, as long as on order is open or pending in the system.
|
|
1341
1201
|
* @param {string} OrderId Nest OrderId
|
|
1342
1202
|
* @param {string} Exchange Exchange
|
|
1343
|
-
* @param {'
|
|
1344
|
-
* @param {
|
|
1203
|
+
* @param {string'} Order_Type LIMIT | MARKET | STOP_LIMIT | STOP_MARKET
|
|
1204
|
+
* @param {string} ProductCode CNC | MIS | NRML | MTF
|
|
1345
1205
|
* @returns Promise that resolves/rejects to Cancel Trade api response
|
|
1346
1206
|
*/
|
|
1347
1207
|
CancelTrade = (OrderId, Exchange, Order_Type, ProductCode) => {
|
|
@@ -1349,10 +1209,13 @@ class APIConnect {
|
|
|
1349
1209
|
const data = {
|
|
1350
1210
|
nstOID: OrderId,
|
|
1351
1211
|
exc: Exchange,
|
|
1352
|
-
prdCode: ProductCode,
|
|
1212
|
+
prdCode: this.__constants.getValidProductCode(this.fileName, Exchange, ProductCode),
|
|
1353
1213
|
ordTyp: Order_Type,
|
|
1354
1214
|
};
|
|
1355
|
-
const validateResponse = validateCancelPlaceTrade(
|
|
1215
|
+
const validateResponse = validateCancelPlaceTrade(
|
|
1216
|
+
data,
|
|
1217
|
+
this.excsAndprdDpNm
|
|
1218
|
+
);
|
|
1356
1219
|
if (validateResponse.error) {
|
|
1357
1220
|
log4js.debug(
|
|
1358
1221
|
"CancelTrade validation error -" + validateResponse.error.details
|
|
@@ -1410,27 +1273,6 @@ class APIConnect {
|
|
|
1410
1273
|
return result;
|
|
1411
1274
|
};
|
|
1412
1275
|
|
|
1413
|
-
/**
|
|
1414
|
-
* This functionality allows you to completely exit a cover order which includes cancelling any unplaced orders and also completely squaring off any executed orders. For the orders which were executed it will usually modify the stop loss order leg and place it as a market order to ensure execution, while any non executed quantity order will get cancelled.
|
|
1415
|
-
* @param {string} OrderId Nest OrderId
|
|
1416
|
-
* @returns Promise that resolves/rejects to Exit Cover Trade api response
|
|
1417
|
-
*/
|
|
1418
|
-
ExitCoverTrade = (OrderId) => {
|
|
1419
|
-
log4js.info("Inside ExitCoverTrade method");
|
|
1420
|
-
const validateResponse = validateExitCoverTrade(OrderId);
|
|
1421
|
-
if (validateResponse.error) {
|
|
1422
|
-
log4js.debug(
|
|
1423
|
-
"ExitCoverTrade validation error -" + validateResponse.error.details
|
|
1424
|
-
);
|
|
1425
|
-
return Promise.reject(validateResponse.error.details);
|
|
1426
|
-
}
|
|
1427
|
-
const url = this.__config.ExitCoverTradeURL(this.__constants.eqAccId);
|
|
1428
|
-
log4js.debug("ExitCoverTrade URLS -" + url);
|
|
1429
|
-
var result = this.__http.PutMethod(url, { nstOID: OrderId });
|
|
1430
|
-
log4js.debug("ExitCoverTrade Result :" + JSON.stringify(result));
|
|
1431
|
-
return result;
|
|
1432
|
-
};
|
|
1433
|
-
|
|
1434
1276
|
/**
|
|
1435
1277
|
* Similar to Exit Cover order the functionality will ensure that any non executed open order will be cancelled. However for any orders which are executed it will automatically cancel one of the target or stop loss legs and modify the other leg to be placed as a market order. This will ensure that any executed orders will be squared off in position terms.
|
|
1436
1278
|
* @param {string} Order_Id Mest OrderId
|
|
@@ -1502,7 +1344,10 @@ class APIConnect {
|
|
|
1502
1344
|
trlSl: Trailing_Stop_Loss,
|
|
1503
1345
|
trlSlVal: Trailing_Stop_Loss_Value,
|
|
1504
1346
|
};
|
|
1505
|
-
const validateResponse = validatePlaceBracketTrade(
|
|
1347
|
+
const validateResponse = validatePlaceBracketTrade(
|
|
1348
|
+
paramsObj,
|
|
1349
|
+
this.excsAndprdDpNm
|
|
1350
|
+
);
|
|
1506
1351
|
if (validateResponse.error) {
|
|
1507
1352
|
log4js.debug(
|
|
1508
1353
|
"PlaceBracketTrade validation error -" + validateResponse.error.details
|
|
@@ -1539,15 +1384,8 @@ class APIConnect {
|
|
|
1539
1384
|
* @param {Array<Order>} orderlist Array of Orders to be placed
|
|
1540
1385
|
* @returns Promise that resolves/rejects to Place Basket Trade api response
|
|
1541
1386
|
*/
|
|
1542
|
-
PlaceBasketTrade = (orderlist) => {
|
|
1387
|
+
PlaceBasketTrade = async (orderlist) => {
|
|
1543
1388
|
log4js.info("Inside PlaceBasketTrade method");
|
|
1544
|
-
const validateResponse = validatePlaceBasketTrade(orderlist);
|
|
1545
|
-
if (validateResponse.error) {
|
|
1546
|
-
log4js.debug(
|
|
1547
|
-
"PlaceBasketTrade validation error -" + validateResponse.error.details
|
|
1548
|
-
);
|
|
1549
|
-
return Promise.reject(validateResponse.error.details);
|
|
1550
|
-
}
|
|
1551
1389
|
let isComm = false;
|
|
1552
1390
|
const lst = [];
|
|
1553
1391
|
orderlist.forEach(({ sym, GTDDate, rmk, ...order }) => {
|
|
@@ -1564,6 +1402,17 @@ class APIConnect {
|
|
|
1564
1402
|
if (isComm) {
|
|
1565
1403
|
console.log("Basket Order not available for Commodity");
|
|
1566
1404
|
}
|
|
1405
|
+
const validateResponse = validatePlaceBasketTrade(lst, this.excsAndprdDpNm);
|
|
1406
|
+
await Promise.all(
|
|
1407
|
+
validateResponse.map((item) => {
|
|
1408
|
+
if (item.error) {
|
|
1409
|
+
log4js.debug(
|
|
1410
|
+
"PlaceBasketTrade validation error -" + item.error.details
|
|
1411
|
+
);
|
|
1412
|
+
return Promise.reject(item.error.details);
|
|
1413
|
+
}
|
|
1414
|
+
})
|
|
1415
|
+
);
|
|
1567
1416
|
const url = this.__config.PlaceBasketTradeURL(this.__constants.eqAccId);
|
|
1568
1417
|
log4js.debug("PlaceBasketTrade URLS -" + url);
|
|
1569
1418
|
var result = this.__http.PostMethod(url, fd);
|
|
@@ -1592,19 +1441,33 @@ class APIConnect {
|
|
|
1592
1441
|
};
|
|
1593
1442
|
|
|
1594
1443
|
/**
|
|
1595
|
-
* Get AMO
|
|
1444
|
+
* Get AMO Status
|
|
1445
|
+
* @param {string} exchange Exchange value from Position book response.
|
|
1596
1446
|
* @returns Promise that resolves/rejects to the Get AMO Status api response
|
|
1597
1447
|
*/
|
|
1598
|
-
GetAMOStxatus = () => {
|
|
1448
|
+
GetAMOStxatus = (exchange) => {
|
|
1599
1449
|
log4js.info("Inside GetAMOStxatus method");
|
|
1600
1450
|
const accTyp = this.__constants.Data.data.lgnData.accTyp;
|
|
1451
|
+
if (accTyp == "CO" || accTyp == "COMEQ") {
|
|
1452
|
+
const validateResponse = validateGetAMOStxatus(
|
|
1453
|
+
exchange,
|
|
1454
|
+
this.excsAndprdDpNm
|
|
1455
|
+
);
|
|
1456
|
+
if (validateResponse.error) {
|
|
1457
|
+
log4js.debug(
|
|
1458
|
+
" GetAMOStxatus validation error - " + validateResponse.error.details
|
|
1459
|
+
);
|
|
1460
|
+
return Promise.reject(validateResponse.error.details);
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1601
1464
|
const eqUrl =
|
|
1602
1465
|
accTyp == "EQ" || accTyp == "COMEQ"
|
|
1603
1466
|
? this.__config.GetAMOFlag(this.__constants.eqAccId)
|
|
1604
1467
|
: undefined;
|
|
1605
1468
|
const commUrl =
|
|
1606
1469
|
accTyp == "CO" || accTyp == "COMEQ"
|
|
1607
|
-
? this.__config.GetAMOFlag_comm(
|
|
1470
|
+
? this.__config.GetAMOFlag_comm(exchange)
|
|
1608
1471
|
: undefined;
|
|
1609
1472
|
log4js.debug("GetAMOStxatus URLS - eq :" + eqUrl + " comm:" + commUrl);
|
|
1610
1473
|
var result = this.__getEqCommData(eqUrl, commUrl);
|
|
@@ -1615,16 +1478,16 @@ class APIConnect {
|
|
|
1615
1478
|
/**
|
|
1616
1479
|
* After market order or AMO in short refers to orders which can be placed once the markets or exchanges are closed for trading. You can place AMO post market hours which will result in the order in question being placed automatically by 9:15 AM - 9:30 AM the next business day. AMO orders usually need to be limit orders in order to prevent inadvertent execution in case of adverse price movement in markets at beginning of day. AMO is a useful way to place your orders in case you do not have time to place orders during market hours.
|
|
1617
1480
|
* @param {string} Trading_Symbol Trading Symbol of the Scrip
|
|
1618
|
-
* @param {string} Exchange Exchange
|
|
1619
|
-
* @param {
|
|
1620
|
-
* @param {
|
|
1621
|
-
* @param {
|
|
1481
|
+
* @param {string} Exchange Exchange value from Position book response.
|
|
1482
|
+
* @param {string} Action BUY | SELL
|
|
1483
|
+
* @param {string} Duration DAY | IOC | EOS(for BSE)
|
|
1484
|
+
* @param {string} Order_Type LIMIT | MARKET | STOP_LIMIT | STOP_MARKET
|
|
1622
1485
|
* @param {number} Quantity Quantity of the Scrip
|
|
1623
1486
|
* @param {string} Streaming_Symbol companycode_exchange to be obtained from Contract file downloaded
|
|
1624
1487
|
* @param {number} Limit_Price Limit price of Scrip
|
|
1625
1488
|
* @param {string} Disclosed_Quantity Quantity to be disclosed while order_placement
|
|
1626
1489
|
* @param {string} TriggerPrice Trigger Price applicable for SL/SL-M Orders
|
|
1627
|
-
* @param {
|
|
1490
|
+
* @param {string} ProductCode CNC | MIS | NRML | MTF
|
|
1628
1491
|
* @returns Promise that resolves/rejects to the Place AMO Trade api response
|
|
1629
1492
|
*/
|
|
1630
1493
|
PlaceAMOTrade = (
|
|
@@ -1638,7 +1501,7 @@ class APIConnect {
|
|
|
1638
1501
|
Limit_Price,
|
|
1639
1502
|
Disclosed_Quantity = "0",
|
|
1640
1503
|
TriggerPrice = "0",
|
|
1641
|
-
ProductCode
|
|
1504
|
+
ProductCode
|
|
1642
1505
|
) => {
|
|
1643
1506
|
log4js.info("Inside PlaceAMOTrade method");
|
|
1644
1507
|
const paramsObj = {
|
|
@@ -1649,12 +1512,15 @@ class APIConnect {
|
|
|
1649
1512
|
ordTyp: Order_Type,
|
|
1650
1513
|
qty: Quantity,
|
|
1651
1514
|
sym: Streaming_Symbol,
|
|
1652
|
-
Limit_Price,
|
|
1515
|
+
lmPrc: Limit_Price,
|
|
1653
1516
|
dscQty: Disclosed_Quantity,
|
|
1654
1517
|
trgPrc: TriggerPrice,
|
|
1655
1518
|
prdCode: ProductCode,
|
|
1656
1519
|
};
|
|
1657
|
-
const validateResponse = validatePlaceAMOTrade(
|
|
1520
|
+
const validateResponse = validatePlaceAMOTrade(
|
|
1521
|
+
paramsObj,
|
|
1522
|
+
this.excsAndprdDpNm
|
|
1523
|
+
);
|
|
1658
1524
|
if (validateResponse.error) {
|
|
1659
1525
|
log4js.debug(
|
|
1660
1526
|
"PlaceAMOTrade validation error -" + validateResponse.error.details
|
|
@@ -1674,7 +1540,7 @@ class APIConnect {
|
|
|
1674
1540
|
mktPro: "",
|
|
1675
1541
|
lmPrc: Limit_Price,
|
|
1676
1542
|
trgPrc: TriggerPrice,
|
|
1677
|
-
prdCode: ProductCode,
|
|
1543
|
+
prdCode: this.__constants.getValidProductCode(this.fileName, Exchange, ProductCode),
|
|
1678
1544
|
posSqr: "false",
|
|
1679
1545
|
minQty: "0",
|
|
1680
1546
|
ordSrc: "API",
|
|
@@ -1701,17 +1567,17 @@ class APIConnect {
|
|
|
1701
1567
|
/**
|
|
1702
1568
|
* Modify After Market Order
|
|
1703
1569
|
* @param {string} Trading_Symbol Trading Symbol of the Scrip
|
|
1704
|
-
* @param {string} Exchange Exchange
|
|
1705
|
-
* @param {
|
|
1706
|
-
* @param {
|
|
1707
|
-
* @param {
|
|
1570
|
+
* @param {string} Exchange Exchange value from Position book response.
|
|
1571
|
+
* @param {string} Action BUY | SELL
|
|
1572
|
+
* @param {string} Duration DAY | IOC | EOS(for BSE)
|
|
1573
|
+
* @param {string} Order_Type LIMIT | MARKET | STOP_LIMIT | STOP_MARKET
|
|
1708
1574
|
* @param {number} Quantity Quantity of the Scrip
|
|
1709
1575
|
* @param {string} Streaming_Symbol companycode_exchange to be obtained from Contract file downloaded
|
|
1710
1576
|
* @param {number} Limit_Price Limit price of Scrip
|
|
1711
1577
|
* @param {string} Order_ID Nest Order Id
|
|
1712
1578
|
* @param {string} Disclosed_Quantity Quantity to be disclosed while order_placement
|
|
1713
1579
|
* @param {string} TriggerPrice Trigger Price applicable for SL/SL-M Orders
|
|
1714
|
-
* @param {
|
|
1580
|
+
* @param {string} ProductCode Product Code of the trade
|
|
1715
1581
|
* @returns Promise that resolves/rejects to the Place AMO Trade api response
|
|
1716
1582
|
*/
|
|
1717
1583
|
ModifyAMOTrade = (
|
|
@@ -1726,7 +1592,7 @@ class APIConnect {
|
|
|
1726
1592
|
Order_ID,
|
|
1727
1593
|
Disclosed_Quantity = "0",
|
|
1728
1594
|
TriggerPrice = "0",
|
|
1729
|
-
ProductCode
|
|
1595
|
+
ProductCode
|
|
1730
1596
|
) => {
|
|
1731
1597
|
log4js.info("Inside ModifyAMOTrade method");
|
|
1732
1598
|
const paramsObj = {
|
|
@@ -1743,7 +1609,10 @@ class APIConnect {
|
|
|
1743
1609
|
trgPrc: TriggerPrice,
|
|
1744
1610
|
prdCode: ProductCode,
|
|
1745
1611
|
};
|
|
1746
|
-
const validateResponse = validateModifyAMOTrade(
|
|
1612
|
+
const validateResponse = validateModifyAMOTrade(
|
|
1613
|
+
paramsObj,
|
|
1614
|
+
this.excsAndprdDpNm
|
|
1615
|
+
);
|
|
1747
1616
|
if (validateResponse.error) {
|
|
1748
1617
|
log4js.debug(
|
|
1749
1618
|
"ModifyAMOTrade validation error -" + validateResponse.error.details
|
|
@@ -1763,7 +1632,7 @@ class APIConnect {
|
|
|
1763
1632
|
mktPro: "",
|
|
1764
1633
|
lmPrc: Limit_Price,
|
|
1765
1634
|
trgPrc: TriggerPrice,
|
|
1766
|
-
prdCode: ProductCode,
|
|
1635
|
+
prdCode: this.__constants.getValidProductCode(this.fileName, Exchange, ProductCode),
|
|
1767
1636
|
dtDays: "",
|
|
1768
1637
|
nstOID: Order_ID,
|
|
1769
1638
|
};
|
|
@@ -1796,11 +1665,11 @@ class APIConnect {
|
|
|
1796
1665
|
const data = {
|
|
1797
1666
|
nstOID: OrderId,
|
|
1798
1667
|
exc: Exchange,
|
|
1799
|
-
prdCode: Product_Code,
|
|
1668
|
+
prdCode: this.__constants.getValidProductCode(this.fileName, Exchange, Product_Code),
|
|
1800
1669
|
ordTyp: Order_Type,
|
|
1801
1670
|
};
|
|
1802
1671
|
log4js.info("Inside CancelAMOTrade method");
|
|
1803
|
-
const validateResponse = validateCancelAMOTrade(data);
|
|
1672
|
+
const validateResponse = validateCancelAMOTrade(data, this.excsAndprdDpNm);
|
|
1804
1673
|
if (validateResponse.error) {
|
|
1805
1674
|
log4js.debug(
|
|
1806
1675
|
"CancelAMOTrade validation error -" + validateResponse.error.details
|
|
@@ -1828,14 +1697,23 @@ class APIConnect {
|
|
|
1828
1697
|
* @param {Array<Order>} orderlist List of orders to be Squared Off.
|
|
1829
1698
|
* @returns Promise that resolves/rejects to the Position Square Off api response
|
|
1830
1699
|
*/
|
|
1831
|
-
PositionSquareOff = (orderlist) => {
|
|
1832
|
-
const validateResponse = validatePositionSquareOff(
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1700
|
+
PositionSquareOff = async (orderlist) => {
|
|
1701
|
+
const validateResponse = validatePositionSquareOff(
|
|
1702
|
+
orderlist,
|
|
1703
|
+
this.excsAndprdDpNm
|
|
1704
|
+
);
|
|
1705
|
+
console.log("PositionSquareOff", validateResponse);
|
|
1706
|
+
await Promise.all(
|
|
1707
|
+
validateResponse.map((item) => {
|
|
1708
|
+
if (item.error) {
|
|
1709
|
+
log4js.debug(
|
|
1710
|
+
"PositionSquareOff validation error -" + item.error.details
|
|
1711
|
+
);
|
|
1712
|
+
return Promise.reject(item.error.details);
|
|
1713
|
+
}
|
|
1714
|
+
})
|
|
1715
|
+
);
|
|
1716
|
+
|
|
1839
1717
|
const lstEq = [];
|
|
1840
1718
|
const lstComm = [];
|
|
1841
1719
|
log4js.info("Inside PositionSquareOff method");
|
|
@@ -1848,19 +1726,9 @@ class APIConnect {
|
|
|
1848
1726
|
order["ordSrc"] = "API";
|
|
1849
1727
|
order["vnCode"] = "";
|
|
1850
1728
|
order["rmk"] = "";
|
|
1729
|
+
order["prdCode"] = this.__constants.getValidProductCode(this.fileName, order.exc, order.prdCode);
|
|
1730
|
+
order["lmPrc"] = order.price;
|
|
1851
1731
|
const data = order;
|
|
1852
|
-
// remove GTCDate, rmk from order if present because we don't need to pass them in api
|
|
1853
|
-
// const data = (data = {
|
|
1854
|
-
// ...order,
|
|
1855
|
-
// flQty: "0",
|
|
1856
|
-
// mktPro: "",
|
|
1857
|
-
// dtDays: "",
|
|
1858
|
-
// posSqr: "true",
|
|
1859
|
-
// minQty: "0",
|
|
1860
|
-
// ordSrc: "API",
|
|
1861
|
-
// vnCode: "",
|
|
1862
|
-
// rmk: ""
|
|
1863
|
-
// });
|
|
1864
1732
|
|
|
1865
1733
|
order.exc == "MCX" || order.exc == "NCDEX"
|
|
1866
1734
|
? lstComm.push(data)
|
|
@@ -1868,13 +1736,13 @@ class APIConnect {
|
|
|
1868
1736
|
});
|
|
1869
1737
|
|
|
1870
1738
|
const postEq = lstEq.length
|
|
1871
|
-
? this.__http.PostMethod(
|
|
1739
|
+
? await this.__http.PostMethod(
|
|
1872
1740
|
this.__config.PositionSqOffURL(this.__constants.eqAccId),
|
|
1873
1741
|
lstEq
|
|
1874
1742
|
)
|
|
1875
1743
|
: undefined;
|
|
1876
1744
|
const postComm = lstComm.length
|
|
1877
|
-
? this.__http.PostMethod(
|
|
1745
|
+
? await this.__http.PostMethod(
|
|
1878
1746
|
this.__config.PositionSqOffURL(this.__constants.coAccId),
|
|
1879
1747
|
lstComm
|
|
1880
1748
|
)
|
|
@@ -1888,7 +1756,72 @@ class APIConnect {
|
|
|
1888
1756
|
};
|
|
1889
1757
|
|
|
1890
1758
|
/**
|
|
1891
|
-
*
|
|
1759
|
+
* Convert a Position partially for Commodity
|
|
1760
|
+
* @param {string} streamingSymbol companycode_exchange to be obtained from Contract file downloaded
|
|
1761
|
+
* @param {string} conversionType Conversion type D-- Daywise and C–carry forward position
|
|
1762
|
+
* @param {string} quantity Quantity to be converted.
|
|
1763
|
+
* @param {string} action Transaction type 'BUY' and 'SELL - SELL .
|
|
1764
|
+
* @param {string} oldProductCode Existing Product Code of the trade.
|
|
1765
|
+
* @param {string} newProductCode New Product code of the trade.
|
|
1766
|
+
* @param {string} exchange Exchange value from Position book response.
|
|
1767
|
+
* @param {string} tradingSymbol Trading Symbol of the Scrip
|
|
1768
|
+
* @returns Promise that resolves/rejects to the Convert Position api response
|
|
1769
|
+
*/
|
|
1770
|
+
ConvertPositionCOMM = (
|
|
1771
|
+
streamingSymbol,
|
|
1772
|
+
conversionType,
|
|
1773
|
+
quantity,
|
|
1774
|
+
action,
|
|
1775
|
+
oldProductCode,
|
|
1776
|
+
newProductCode,
|
|
1777
|
+
exchange,
|
|
1778
|
+
tradingSymbol
|
|
1779
|
+
) => {
|
|
1780
|
+
log4js.info(`ConvertPositionCOMM method is called.`);
|
|
1781
|
+
const data = {
|
|
1782
|
+
sym: streamingSymbol,
|
|
1783
|
+
cnvTyp: conversionType,
|
|
1784
|
+
qty: quantity,
|
|
1785
|
+
action: this.__constants.getAlternateActionName(action),
|
|
1786
|
+
prdCode: this.__constants.getValidProductCode(this.fileName, exchange, oldProductCode),
|
|
1787
|
+
prdCodeCh: this.__constants.getValidProductCode(this.fileName, exchange, newProductCode),
|
|
1788
|
+
ordSrc: "API",
|
|
1789
|
+
exc: exchange,
|
|
1790
|
+
trdSym: tradingSymbol,
|
|
1791
|
+
};
|
|
1792
|
+
const validateResponse = validateConvertPositionCOMM(
|
|
1793
|
+
data,
|
|
1794
|
+
this.excsAndprdDpNm
|
|
1795
|
+
);
|
|
1796
|
+
if (validateResponse.error) {
|
|
1797
|
+
log4js.debug(
|
|
1798
|
+
`ConvertPositionCOMM validation error - ${validateResponse.error.details}`
|
|
1799
|
+
);
|
|
1800
|
+
return Promise.reject(validateResponse.error.details);
|
|
1801
|
+
}
|
|
1802
|
+
log4js.info(
|
|
1803
|
+
`ConvertPositionCOMM method is called with data ${JSON.stringify(data)}`
|
|
1804
|
+
);
|
|
1805
|
+
if (exchange === "MCX" || exchange === "NCDEX") {
|
|
1806
|
+
const url = this.__config.ConvertPositionURL_comm(
|
|
1807
|
+
this.__constants.coAccId
|
|
1808
|
+
);
|
|
1809
|
+
log4js.debug(`ConvertPositionCOMM URLS: ${url}`);
|
|
1810
|
+
var result = this.__http.PutMethod(url, data);
|
|
1811
|
+
log4js.debug(`ConvertPositionCOMM Result : ${JSON.stringify(result)}`);
|
|
1812
|
+
return result;
|
|
1813
|
+
}
|
|
1814
|
+
// else {
|
|
1815
|
+
// const url = this.__config.ConvertPositionURL(this.__constants.eqAccId);
|
|
1816
|
+
// log4js.debug(`ConvertPosition URLS: ${url}`);
|
|
1817
|
+
// var result = this.__http.PutMethod(url, data);
|
|
1818
|
+
// log4js.debug(`ConvertPosition Result : ${JSON.stringify(result)}`);
|
|
1819
|
+
// return result;
|
|
1820
|
+
// }
|
|
1821
|
+
};
|
|
1822
|
+
|
|
1823
|
+
/**
|
|
1824
|
+
* Converts your holding position For Equity
|
|
1892
1825
|
* @param {string} Order_Id Nest Order Id
|
|
1893
1826
|
* @param {string} Fill_Id Fill Id of the trade obtained from Trade API
|
|
1894
1827
|
* @param {string} New_Product_Code New Product code of the trade
|
|
@@ -1905,46 +1838,31 @@ class APIConnect {
|
|
|
1905
1838
|
Exchange,
|
|
1906
1839
|
orderType
|
|
1907
1840
|
) => {
|
|
1908
|
-
log4js.info(
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
log4js.debug(
|
|
1923
|
-
"ConvertPosition validation error -" + validateResponse.error.details
|
|
1924
|
-
);
|
|
1925
|
-
return Promise.reject(validateResponse.error.details);
|
|
1926
|
-
}
|
|
1927
|
-
const url = this.__config.ConvertPositionURL_comm(
|
|
1928
|
-
this.__constants.coAccId
|
|
1841
|
+
log4js.info(`ConvertPosition method is called.`);
|
|
1842
|
+
const data = {
|
|
1843
|
+
nstOID: Order_Id,
|
|
1844
|
+
flID: Fill_Id,
|
|
1845
|
+
prdCodeCh: this.__constants.getValidProductCode(this.fileName, Exchange, New_Product_Code),
|
|
1846
|
+
prdCode: this.__constants.getValidProductCode(this.fileName, Exchange, Old_Product_Code),
|
|
1847
|
+
exc: Exchange,
|
|
1848
|
+
ordTyp: orderType
|
|
1849
|
+
};
|
|
1850
|
+
|
|
1851
|
+
const validateResponse = validateConvertPositionEQ(data, this.excsAndprdDpNm);
|
|
1852
|
+
if (validateResponse.error) {
|
|
1853
|
+
log4js.debug(
|
|
1854
|
+
`ConvertPosition validation error - ${validateResponse.error.details}`
|
|
1929
1855
|
);
|
|
1930
|
-
|
|
1931
|
-
var result = this.__http.PutMethod(url, data);
|
|
1932
|
-
log4js.debug("ConvertPosition Result :" + JSON.stringify(result));
|
|
1933
|
-
return result;
|
|
1934
|
-
} else {
|
|
1935
|
-
const data = {
|
|
1936
|
-
nstOID: Order_Id,
|
|
1937
|
-
flID: Fill_Id,
|
|
1938
|
-
prdCodeCh: New_Product_Code,
|
|
1939
|
-
prdCode: Old_Product_Code,
|
|
1940
|
-
};
|
|
1941
|
-
log4js.debug("ConvertPosition Data :" + JSON.stringify(data));
|
|
1942
|
-
const url = this.__config.ConvertPositionURL(this.__constants.eqAccId);
|
|
1943
|
-
log4js.debug("ConvertPosition URLS:" + url);
|
|
1944
|
-
var result = this.__http.PutMethod(url, data);
|
|
1945
|
-
log4js.debug("ConvertPosition Result :" + JSON.stringify(result));
|
|
1946
|
-
return result;
|
|
1856
|
+
return Promise.reject(validateResponse.error.details);
|
|
1947
1857
|
}
|
|
1858
|
+
log4js.debug(
|
|
1859
|
+
`ConvertPosition method error is called with data ${JSON.stringify(data)}`
|
|
1860
|
+
);
|
|
1861
|
+
const url = this.__config.ConvertPositionURL(this.__constants.eqAccId);
|
|
1862
|
+
log4js.debug(`ConvertPosition URLS: ${url}`);
|
|
1863
|
+
var result = this.__http.PutMethod(url, data);
|
|
1864
|
+
log4js.debug(`ConvertPosition Result : ${JSON.stringify(result)}`);
|
|
1865
|
+
return result;
|
|
1948
1866
|
};
|
|
1949
1867
|
|
|
1950
1868
|
// MF Methods start //
|
|
@@ -2421,4 +2339,4 @@ APIConnect.prototype.__http = new __Http(
|
|
|
2421
2339
|
APIConnect.prototype.__config.baseurl
|
|
2422
2340
|
);
|
|
2423
2341
|
|
|
2424
|
-
module.exports = { APIConnect };
|
|
2342
|
+
module.exports = { APIConnect, Order };
|