api_connect_nodejs 1.0.1 → 2.0.2
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 +3 -3
- package/conf/settings.ini +9 -10
- package/enums/streamingConstants.js +11 -0
- package/index.js +2 -2
- package/package.json +2 -14
- package/src/{edelconnect.js → apiConnect.js} +401 -182
- package/src/{edelweissApiUtils.js → apiUtils.js} +1 -1
- package/src/config.js +1 -1
- package/src/feed/feed.js +139 -0
- package/src/feed/liveNewsFeed.js +112 -0
- package/src/feed/ordersFeed.js +124 -0
- package/src/feed/quotesFeed.js +121 -0
- package/src/http.js +1 -0
- package/src/iniparser.js +4 -3
- package/src/logger.js +1 -1
- package/validations/{edelconnectValidator.js → apiConnectValidator.js} +77 -188
- package/validations/feedStreamerValidator.js +68 -0
- package/.prettierrc.json +0 -19
- package/gitignore +0 -23
- package/src/feed.js +0 -166
- package/validations/feedValidator.js +0 -31
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 };
|