api_connect_nodejs 2.0.2 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -30
- package/conf/settings.ini +19 -19
- package/enums/actionType.js +10 -10
- package/enums/assetType.js +25 -25
- package/enums/chartExchangeType.js +15 -15
- package/enums/chartType.js +13 -13
- package/enums/eodIntervalType.js +11 -11
- package/enums/exchangeType.js +14 -14
- package/enums/intradayIntervalType.js +14 -14
- package/enums/marketCapType.js +12 -12
- package/enums/orderType.js +21 -21
- package/enums/productType.js +24 -24
- package/enums/segementsType.js +13 -13
- package/enums/streamingConstants.js +14 -11
- package/enums/termsType.js +12 -12
- package/enums/validity.js +22 -22
- package/index.js +3 -3
- package/package.json +25 -25
- package/src/apiConnect.js +2397 -2430
- package/src/apiUtils.js +221 -129
- package/src/chart.js +258 -258
- package/src/config.js +321 -326
- package/src/feed/depthFeed.js +137 -0
- package/src/feed/feed.js +162 -139
- package/src/feed/liveNewsFeed.js +112 -112
- package/src/feed/miniQuoteFeed.js +121 -0
- package/src/feed/ordersFeed.js +124 -124
- package/src/feed/quotesFeed.js +226 -121
- package/src/http.js +197 -197
- package/src/iniparser.js +42 -42
- package/src/liveNews.js +362 -362
- package/src/logger.js +16 -16
- package/src/order.js +48 -48
- package/src/quote.js +75 -0
- package/src/researchCalls.js +175 -175
- package/src/watchlist.js +378 -378
- package/validations/apiConnectValidator.js +521 -508
- package/validations/chartValidator.js +85 -85
- package/validations/feedStreamerValidator.js +162 -68
- package/validations/liveNewsValidator.js +60 -60
- package/validations/quoteValidator.js +19 -0
- package/validations/researchCallsValidator.js +86 -86
- package/validations/watchlistValidator.js +60 -60
package/src/feed/quotesFeed.js
CHANGED
|
@@ -1,121 +1,226 @@
|
|
|
1
|
-
const log4js = require("../logger");
|
|
2
|
-
const configData = require("../iniparser");
|
|
3
|
-
const { QUOTE_SREAM_REQ_CODE } = require("../../enums/streamingConstants");
|
|
4
|
-
const {
|
|
5
|
-
validateSubscribeQuotesFeed,
|
|
6
|
-
validateUnsubscribeQuotesFeed,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* @
|
|
47
|
-
* @
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
body.request.request_type = "
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
*
|
|
73
|
-
* @
|
|
74
|
-
* @
|
|
75
|
-
* @
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
this.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
*
|
|
105
|
-
* @
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
1
|
+
const log4js = require("../logger");
|
|
2
|
+
const configData = require("../iniparser");
|
|
3
|
+
const { QUOTE_SREAM_REQ_CODE, REDUCED_QUOTE_SREAM_REQ_CODE } = require("../../enums/streamingConstants");
|
|
4
|
+
const {
|
|
5
|
+
validateSubscribeQuotesFeed,
|
|
6
|
+
validateUnsubscribeQuotesFeed,
|
|
7
|
+
validateSubscribeReducedQuotesFeed,
|
|
8
|
+
validateUnsubscribeReducedQuotesFeed,
|
|
9
|
+
} = require("../../validations/feedStreamerValidator");
|
|
10
|
+
|
|
11
|
+
class QuotesFeed {
|
|
12
|
+
/**
|
|
13
|
+
* Streamer
|
|
14
|
+
* QuotesFeed Class for subsribe or unsubsribe Quotes
|
|
15
|
+
*/
|
|
16
|
+
constructor(feed) {
|
|
17
|
+
this.feed = feed;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* QutoesFeed RequestBody Structure
|
|
22
|
+
* Return QuotesFeed RequestBody Structure
|
|
23
|
+
* @function quotesFeedRequestBody
|
|
24
|
+
* @returns object
|
|
25
|
+
*/
|
|
26
|
+
requestBody = () => {
|
|
27
|
+
return {
|
|
28
|
+
request: {
|
|
29
|
+
streaming_type: "quote3",
|
|
30
|
+
data: {
|
|
31
|
+
"accType": "EQ",
|
|
32
|
+
symbols: [],
|
|
33
|
+
},
|
|
34
|
+
formFactor: configData.formFactor,
|
|
35
|
+
appID: configData.ApiIdKey,
|
|
36
|
+
response_format: "json",
|
|
37
|
+
request_type: "",
|
|
38
|
+
},
|
|
39
|
+
echo: {},
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Create QuotesFeed RequestBody
|
|
45
|
+
* Return QuotesFeed RequestBody
|
|
46
|
+
* @function createQuotesFeedRequest
|
|
47
|
+
* @param {Object[]} symbols - Array of subsribe Symbols
|
|
48
|
+
* @param {boolean} order - true for subsribe and false for unsubsribe
|
|
49
|
+
* @returns object
|
|
50
|
+
*/
|
|
51
|
+
createQuotesFeedRequest = (symbols, quote = false) => {
|
|
52
|
+
let body = {};
|
|
53
|
+
try {
|
|
54
|
+
body = this.requestBody();
|
|
55
|
+
const symset = symbols.map((sym) => ({ symbol: sym.trim() }));
|
|
56
|
+
|
|
57
|
+
body.request.data.symbols = symset;
|
|
58
|
+
|
|
59
|
+
if (quote) {
|
|
60
|
+
body.request.request_type = "subscribe";
|
|
61
|
+
} else {
|
|
62
|
+
body.request.request_type = "unsubscribe";
|
|
63
|
+
}
|
|
64
|
+
} catch (error) {
|
|
65
|
+
log4js.debug("createQuotesFeedRequest error - " + error);
|
|
66
|
+
} finally {
|
|
67
|
+
return body;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 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.
|
|
73
|
+
* @async
|
|
74
|
+
* @function subscribeQuotesFeed
|
|
75
|
+
* @param {(err?, data?, close?: number) => void} callBack Callback to receive the Feed in
|
|
76
|
+
* @param {Array<string>} symbols Symbol list for subscription: Symbol_exchange to be obtained from Contract File
|
|
77
|
+
* @returns
|
|
78
|
+
*/
|
|
79
|
+
subscribeQuotesFeed = async (symbols, callback) => {
|
|
80
|
+
try {
|
|
81
|
+
/** Validation Start */
|
|
82
|
+
const validateResponse = validateSubscribeQuotesFeed(callback, symbols);
|
|
83
|
+
|
|
84
|
+
if (validateResponse.error) {
|
|
85
|
+
log4js.debug(
|
|
86
|
+
"subscribeQuotesFeed validation error - " +
|
|
87
|
+
validateResponse.error.details
|
|
88
|
+
);
|
|
89
|
+
return Promise.reject(validateResponse.error.details);
|
|
90
|
+
}
|
|
91
|
+
/** Validation End */
|
|
92
|
+
|
|
93
|
+
/** Create Streaming Quote Request */
|
|
94
|
+
let quoteRequest = this.createQuotesFeedRequest(symbols, true);
|
|
95
|
+
/** Call connect method of Feed Class */
|
|
96
|
+
this.feed.subsribe(QUOTE_SREAM_REQ_CODE, quoteRequest, callback);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
log4js.debug("subscribeQuotesFeed error - " + error);
|
|
99
|
+
console.log(error);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* This method will unsubscribe the symbols from the streamer. After successful invokation of this, will stop the streamer packets of these symbols.
|
|
105
|
+
* @async
|
|
106
|
+
* @function unsubscribeQuotesFeed
|
|
107
|
+
* @returns
|
|
108
|
+
*/
|
|
109
|
+
unsubscribeQuotesFeed = async () => {
|
|
110
|
+
try {
|
|
111
|
+
/** Get Streaming Quote Request */
|
|
112
|
+
const quoteRequest = this.createQuotesFeedRequest([]);
|
|
113
|
+
|
|
114
|
+
/** Unsubsribe symbols */
|
|
115
|
+
this.feed.unsubsribe(QUOTE_SREAM_REQ_CODE, quoteRequest);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
log4js.debug("unsubscribeQuotesFeed error - " + error);
|
|
118
|
+
console.log(error);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
//Reduced Quote
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Reduced QutoesFeed RequestBody Structure
|
|
126
|
+
* Return Reduced QuotesFeed RequestBody Structure
|
|
127
|
+
* @function reducedQuotesFeedRequestBody
|
|
128
|
+
* @returns object
|
|
129
|
+
*/
|
|
130
|
+
reducedQuoteRequestBody = () => {
|
|
131
|
+
return {
|
|
132
|
+
request: {
|
|
133
|
+
streaming_type: "quote",
|
|
134
|
+
data: {
|
|
135
|
+
"accType": "EQ",
|
|
136
|
+
symbols: [],
|
|
137
|
+
},
|
|
138
|
+
formFactor: configData.formFactor,
|
|
139
|
+
appID: configData.ApiIdKey,
|
|
140
|
+
response_format: "json",
|
|
141
|
+
request_type: "",
|
|
142
|
+
},
|
|
143
|
+
echo: {},
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Create ReducedQuotesFeed RequestBody
|
|
148
|
+
* Return ReducedQuotesFeed RequestBody
|
|
149
|
+
* @function createReducedQuotesFeedRequest
|
|
150
|
+
* @param {Object[]} symbols - Array of subsribe Symbols
|
|
151
|
+
* @param {boolean} order - true for subsribe and false for unsubsribe
|
|
152
|
+
* @returns object
|
|
153
|
+
*/
|
|
154
|
+
createReducedQuotesFeedRequest = (symbols, reducedQuote = false) => {
|
|
155
|
+
let body = {};
|
|
156
|
+
try {
|
|
157
|
+
body = this.reducedQuoteRequestBody();
|
|
158
|
+
const symset = symbols.map((sym) => ({ symbol: sym.trim() }));
|
|
159
|
+
|
|
160
|
+
body.request.data.symbols = symset;
|
|
161
|
+
|
|
162
|
+
if (reducedQuote) {
|
|
163
|
+
body.request.request_type = "subscribe";
|
|
164
|
+
} else {
|
|
165
|
+
body.request.request_type = "unsubscribe";
|
|
166
|
+
}
|
|
167
|
+
} catch (error) {
|
|
168
|
+
log4js.debug("createReducedQuotesFeedRequest error - " + error);
|
|
169
|
+
} finally {
|
|
170
|
+
return body;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* 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.
|
|
176
|
+
* @async
|
|
177
|
+
* @function subscribeReducedQuotesFeed
|
|
178
|
+
* @param {(err?, data?, close?: number) => void} callBack Callback to receive the Feed in
|
|
179
|
+
* @param {Array<string>} symbols Symbol list for subscription: Symbol_exchange to be obtained from Contract File
|
|
180
|
+
* @returns
|
|
181
|
+
*/
|
|
182
|
+
subscribeReducedQuotesFeed = async (symbols, callback) => {
|
|
183
|
+
try {
|
|
184
|
+
/** Validation Start */
|
|
185
|
+
const validateResponse = validateSubscribeReducedQuotesFeed(callback, symbols);
|
|
186
|
+
|
|
187
|
+
if (validateResponse.error) {
|
|
188
|
+
log4js.debug(
|
|
189
|
+
"subscribeReducedQuotesFeed validation error - " +
|
|
190
|
+
validateResponse.error.details
|
|
191
|
+
);
|
|
192
|
+
return Promise.reject(validateResponse.error.details);
|
|
193
|
+
}
|
|
194
|
+
/** Validation End */
|
|
195
|
+
|
|
196
|
+
/** Create Streaming Quote Request */
|
|
197
|
+
let reducedQuoteRequest = this.createReducedQuotesFeedRequest(symbols, true);
|
|
198
|
+
/** Call connect method of Feed Class */
|
|
199
|
+
this.feed.subsribe(REDUCED_QUOTE_SREAM_REQ_CODE, reducedQuoteRequest, callback);
|
|
200
|
+
} catch (error) {
|
|
201
|
+
log4js.debug("subscribeReducedQuotesFeed error - " + error);
|
|
202
|
+
console.log(error);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* This method will unsubscribe the symbols from the streamer. After successful invokation of this, will stop the streamer packets of these symbols.
|
|
208
|
+
* @async
|
|
209
|
+
* @function unsubscribeReducedQuotesFeed
|
|
210
|
+
* @returns
|
|
211
|
+
*/
|
|
212
|
+
unsubscribeReducedQuotesFeed = async () => {
|
|
213
|
+
try {
|
|
214
|
+
/** Get Streaming Reduced Quote Request */
|
|
215
|
+
const reducedQuoteRequest = this.createReducedQuotesFeedRequest([]);
|
|
216
|
+
|
|
217
|
+
/** Unsubsribe symbols */
|
|
218
|
+
this.feed.unsubsribe(REDUCED_QUOTE_SREAM_REQ_CODE, reducedQuoteRequest);
|
|
219
|
+
} catch (error) {
|
|
220
|
+
log4js.debug("unsubscribeReducedQuotesFeed error - " + error);
|
|
221
|
+
console.log(error);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
module.exports = QuotesFeed;
|