api_connect_nodejs 1.0.1 → 2.0.1

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.
Files changed (43) hide show
  1. package/README.md +31 -31
  2. package/conf/settings.ini +19 -20
  3. package/enums/actionType.js +10 -10
  4. package/enums/assetType.js +25 -25
  5. package/enums/chartExchangeType.js +15 -15
  6. package/enums/chartType.js +13 -13
  7. package/enums/eodIntervalType.js +11 -11
  8. package/enums/exchangeType.js +14 -14
  9. package/enums/intradayIntervalType.js +14 -14
  10. package/enums/marketCapType.js +12 -12
  11. package/enums/orderType.js +21 -21
  12. package/enums/productType.js +24 -24
  13. package/enums/segementsType.js +13 -13
  14. package/enums/streamingConstants.js +11 -0
  15. package/enums/termsType.js +12 -12
  16. package/enums/validity.js +22 -22
  17. package/index.js +3 -3
  18. package/package.json +25 -37
  19. package/src/{edelconnect.js → apiConnect.js} +2424 -2211
  20. package/src/{edelweissApiUtils.js → apiUtils.js} +129 -129
  21. package/src/chart.js +258 -258
  22. package/src/config.js +326 -326
  23. package/src/feed/feed.js +139 -0
  24. package/src/feed/liveNewsFeed.js +112 -0
  25. package/src/feed/ordersFeed.js +124 -0
  26. package/src/feed/quotesFeed.js +121 -0
  27. package/src/http.js +197 -196
  28. package/src/iniparser.js +42 -41
  29. package/src/liveNews.js +362 -362
  30. package/src/logger.js +16 -16
  31. package/src/order.js +48 -48
  32. package/src/researchCalls.js +175 -175
  33. package/src/watchlist.js +378 -378
  34. package/validations/{edelconnectValidator.js → apiConnectValidator.js} +508 -619
  35. package/validations/chartValidator.js +85 -85
  36. package/validations/feedStreamerValidator.js +68 -0
  37. package/validations/liveNewsValidator.js +60 -60
  38. package/validations/researchCallsValidator.js +86 -86
  39. package/validations/watchlistValidator.js +60 -60
  40. package/.prettierrc.json +0 -19
  41. package/gitignore +0 -23
  42. package/src/feed.js +0 -166
  43. package/validations/feedValidator.js +0 -31
package/gitignore DELETED
@@ -1,23 +0,0 @@
1
- # Dependency directories
2
- node_modules/
3
-
4
- # Optional npm cache directory
5
- .npm
6
-
7
- # dotenv environment variables file
8
- .env
9
-
10
- #Ignore instruments and mfInstruments file and OutputFile.csv
11
- instruments.csv
12
-
13
- mfInstruments.csv
14
-
15
- OutputFile.csv
16
-
17
- #Ignore Log files
18
- logs/
19
-
20
- edel-connect.*
21
-
22
- *.txt
23
- *.json
package/src/feed.js DELETED
@@ -1,166 +0,0 @@
1
- const net = require("net");
2
- const configData = require("./iniparser.js");
3
- const log4js = require("./logger.js");
4
- const {
5
- validateSubscribe,
6
- validateUnsubsribe,
7
- } = require("../validations/feedValidator");
8
-
9
- class Feed {
10
- /**
11
- * Streamer
12
- *
13
- * To subscribe to the streamer, Create the single instance of this mentioning `callback` method. After successsful subscription, `callback` method will be called whenever packet is available at the streamer.
14
- * @param {Array<string>} symbols Symbol list for subscription: Symbol_exchange to be obtained from Contract File
15
- * @param {string} accid Customer Account ID
16
- * @param {string} userid User ID
17
- * @param {(err?, data?, close?: number) => void} callBack Callback to receive the Feed in
18
- * @param {boolean} subscribe_order
19
- * @param {boolean} subscribe_quote
20
- */
21
- constructor(accid, userid) {
22
- this.userid = userid;
23
- this.accid = accid;
24
- this.sock = new net.Socket();
25
- }
26
-
27
- // function that connect the client to the server
28
- connect = (subscribe_quote, subscribe_order, symbols) => {
29
- var hostName = configData.hostName;
30
- var port = configData.port;
31
-
32
- this.sock.connect(port, hostName, () => {
33
- console.log("connected to server!");
34
- log4js.debug("connected to server!");
35
- this.sock.setKeepAlive(true, 3000);
36
- });
37
-
38
- if (subscribe_quote) {
39
- const quote = this.__CreateMessage_quote(symbols);
40
- this.sock.write(JSON.stringify(quote) + "\n");
41
- }
42
-
43
- if (subscribe_order) {
44
- const orderFiler = this.__CreateMessage_OrderFiler();
45
- this.sock.write(JSON.stringify(orderFiler) + "\n");
46
- }
47
- this.sock.on("error", (err) => {
48
- log4js.debug("connection error " + err);
49
- this.cb(err, null, null);
50
- });
51
-
52
- this.sock.on("close", (val) => {
53
- console.log("connection closed");
54
- log4js.debug("connection closed");
55
- this.cb(null, null, val);
56
- });
57
- };
58
-
59
- subscribe = (
60
- symbols,
61
- callBack,
62
- subscribe_order = true,
63
- subscribe_quote = true
64
- ) => {
65
- this.cb = callBack;
66
- this.symbols = symbols;
67
- // var hostName = configData.hostName;
68
- // var port = configData.port;
69
- this.__appID = configData.ApiIdKey;
70
-
71
- //Validation
72
- const validateResponse = validateSubscribe(
73
- symbols,
74
- subscribe_order,
75
- subscribe_quote
76
- );
77
- if (validateResponse.error) {
78
- log4js.debug(
79
- "subscribe validation error -" + validateResponse.error.details
80
- );
81
- console.log(validateResponse.error.details);
82
- return;
83
- }
84
-
85
- //coonect to server
86
- this.connect(subscribe_quote, subscribe_order, symbols);
87
-
88
- //when we get data from the server
89
- this.sock.on("data", (data) => {
90
- try {
91
- this.cb(null, JSON.parse(data), null);
92
- } catch (error) {
93
- return false;
94
- }
95
- });
96
-
97
- this.sock.on("close", (val) => {
98
- this.cb(null, null, val);
99
- });
100
-
101
- this.sock.on("end", (val) => {
102
- console.log("Connection ended");
103
- });
104
- };
105
-
106
- __CreateMessage_quote = (symbols) => {
107
- const symset = symbols.map((sym) => ({ symbol: sym }));
108
-
109
- return {
110
- request: {
111
- streaming_type: "quote3", //ini
112
- data: {
113
- symbols: symset,
114
- },
115
- formFactor: configData.formFactor,
116
- appID: this.__appID,
117
- response_format: "json",
118
- request_type: "subscribe",
119
- },
120
- echo: {},
121
- };
122
- };
123
-
124
- __CreateMessage_OrderFiler = () => {
125
- return {
126
- request: {
127
- streaming_type: "orderFiler", //ini
128
- data: {
129
- userID: this.userid,
130
- accID: this.accid,
131
- responseType: ["ORDER_UPDATE", "TRADE_UPDATE"],
132
- },
133
- formFactor: configData.formFactor,
134
- appID: this.__appID,
135
- response_format: "json",
136
- request_type: "subscribe",
137
- },
138
- echo: {},
139
- };
140
- };
141
-
142
- /**
143
- * This method will unsubscribe the symbols from the streamer. After successful invokation of this, will stop the streamer packets of these symbols.
144
- * @param {Array<string>} symbols `streaming symbol` for the scrips which need to be unsubscribed
145
- */
146
- unsubscribe = (symbols) => {
147
- const symset = symbols.map((sym) => ({ symbol: sym }));
148
- const req = {
149
- request: {
150
- streaming_type: "quote3", //ini
151
- data: {
152
- symbols: symset,
153
- },
154
- formFactor: configData.formFactor,
155
- appID: this.__appID,
156
- response_format: "json",
157
- request_type: "unsubscribe",
158
- },
159
- echo: {},
160
- };
161
-
162
- this.sock.write(JSON.stringify(req) + "\n");
163
- };
164
- }
165
-
166
- module.exports = Feed;
@@ -1,31 +0,0 @@
1
- const Joi = require("joi");
2
-
3
- validateSubscribe = (symbols, subscribe_order, subscribe_quote) => {
4
- const subsribeObj = {
5
- symbols: symbols,
6
- subscribe_order: subscribe_order,
7
- subscribe_quote: subscribe_quote,
8
- };
9
-
10
- const subsribeSchema = Joi.object({
11
- symbols: Joi.array().required(),
12
- subscribe_order: Joi.boolean().strict().required(),
13
- subscribe_quote: Joi.boolean().strict().required(),
14
- }).options({ abortEarly: false });
15
-
16
- return subsribeSchema.validate(subsribeObj);
17
- };
18
-
19
- validateUnsubsribe = (symbols) => {
20
- const unsubsribeObj = {
21
- symbols: symbols,
22
- };
23
-
24
- const unsubsribeSchema = Joi.object({
25
- symbols: Joi.array().required(),
26
- }).options({ abortEarly: false });
27
-
28
- return unsubsribeSchema.validate(unsubsribeObj);
29
- };
30
-
31
- module.exports = { validateSubscribe, validateUnsubsribe };