@quotemedia.com/streamer 2.40.0 → 2.41.0
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 +157 -157
- package/examples/enduser-example.html +198 -198
- package/examples/enterprise-token-example.html +177 -177
- package/examples/reconnect-example.html +278 -278
- package/examples/stomp-3rd-party-library-example.html +681 -681
- package/examples/subscription-example.html +252 -252
- package/examples/user-access-token-example.html +177 -0
- package/examples/wmid-example.html +176 -176
- package/package.json +38 -38
- package/{qmci-streamer-2.40.0.js → qmci-streamer-2.41.0.js} +1468 -1452
- package/{qmci-streamer-2.40.0.min.js → qmci-streamer-2.41.0.min.js} +2 -2
- package/examples/test_example.html +0 -126
|
@@ -1,279 +1,279 @@
|
|
|
1
|
-
<html>
|
|
2
|
-
|
|
3
|
-
<head>
|
|
4
|
-
<script src="qmci-streamer-2.
|
|
5
|
-
</head>
|
|
6
|
-
|
|
7
|
-
<body>
|
|
8
|
-
<script type="text/javascript">
|
|
9
|
-
/**
|
|
10
|
-
* Demonstrates how to:
|
|
11
|
-
* - Configure and creating stream
|
|
12
|
-
* - Configure and opening connection
|
|
13
|
-
* - Set up callback to handle messages
|
|
14
|
-
* - Subscribe for symbols with different type of messages
|
|
15
|
-
* - Unsubscribe for the symbols and the messages type
|
|
16
|
-
* - Close the connection and stream
|
|
17
|
-
*/
|
|
18
|
-
window.onload = function() {
|
|
19
|
-
var Streamer = qmci.Streamer;
|
|
20
|
-
/**
|
|
21
|
-
* Step 1: Configure your login credentials inside the login method to get an SID
|
|
22
|
-
* Step 2: Open the streaming connection
|
|
23
|
-
* Step 3: Add the event listeners and the handlers for the messages
|
|
24
|
-
* Step 4: Make a subscription
|
|
25
|
-
* Step 5: Make unsubscribe
|
|
26
|
-
* Step 6: Close stream
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
// Log in to get an SID.
|
|
30
|
-
// This can be done by directly calling to QuoteMedia's auth service.
|
|
31
|
-
Streamer.login({
|
|
32
|
-
host: 'https://app.quotemedia.com/auth',
|
|
33
|
-
credentials: {
|
|
34
|
-
wmid: "YourWebmasterID",
|
|
35
|
-
username: "YourUsername",
|
|
36
|
-
password: "YourPassword"
|
|
37
|
-
}
|
|
38
|
-
}, then(function(sid) {
|
|
39
|
-
// After obtaining the SID, use it to authenticate
|
|
40
|
-
// and open a data stream.
|
|
41
|
-
// Set rejectExcessiveConnection:true to reject new connections when limit is reached. If not specified or value is false,
|
|
42
|
-
// first open connection will be closed instead.
|
|
43
|
-
// If needed, there is ability to specify conflation value per connection. When conflation value is null
|
|
44
|
-
// or not specified, default conflation is used.
|
|
45
|
-
// Set format value to 'application/qitch' to use this binary protocol.
|
|
46
|
-
// Please note that although QITCH protocol uses less bandwidth it can cause significant performance degradation.
|
|
47
|
-
// In case if no format was specified JSON will be used by default.
|
|
48
|
-
|
|
49
|
-
// Can also enable the built-in logging by setting the browser console as the logger.
|
|
50
|
-
// Must be set before calling open(). NOTE: May cause performance degradation.
|
|
51
|
-
// Streamer.logger = console;
|
|
52
|
-
Streamer.open({
|
|
53
|
-
host: 'https://app.quotemedia.com/cache',
|
|
54
|
-
cors: true,
|
|
55
|
-
rejectExcessiveConnection: false,
|
|
56
|
-
conflation: null,
|
|
57
|
-
format: 'application/json',
|
|
58
|
-
isReconnect: true,
|
|
59
|
-
credentials: { sid: sid }
|
|
60
|
-
}, then(function(stream) {
|
|
61
|
-
// After successfully opening the stream,
|
|
62
|
-
// listen for its events.
|
|
63
|
-
stream
|
|
64
|
-
// The stream will asynchronously callback with
|
|
65
|
-
// incoming market data messages.
|
|
66
|
-
.on("message", function(message) {
|
|
67
|
-
switch (Streamer.marketDataTypes.get(message)) {
|
|
68
|
-
case Streamer.marketDataTypes.PRICEDATA:
|
|
69
|
-
print("Price data: " + message.symbol, "blue");
|
|
70
|
-
break;
|
|
71
|
-
// For checking all the available marketDataTypes, go to the README.md file or check Object.keys(Streamer.marketDataTypes)
|
|
72
|
-
case Streamer.marketDataTypes.QUOTE:
|
|
73
|
-
print("Quote :" + message.symbol, "blue");
|
|
74
|
-
break;
|
|
75
|
-
case Streamer.marketDataTypes.MMQUOTE:
|
|
76
|
-
print("MMQuote :" + message.symbol, "blue");
|
|
77
|
-
break;
|
|
78
|
-
case Streamer.marketDataTypes.ORDERBOOK:
|
|
79
|
-
print("Orderbook :" + message.symbol, "blue");
|
|
80
|
-
break;
|
|
81
|
-
case Streamer.marketDataTypes.INTERVAL:
|
|
82
|
-
print("Interval :" + message.symbol, "blue");
|
|
83
|
-
break;
|
|
84
|
-
case Streamer.marketDataTypes.NETHOUSEPOSITION:
|
|
85
|
-
print("Nethouse Position :" + message.symbol, "blue");
|
|
86
|
-
break;
|
|
87
|
-
case Streamer.marketDataTypes.LASTSALE:
|
|
88
|
-
print("Last Sale :" + message.symbol, "blue");
|
|
89
|
-
break;
|
|
90
|
-
case Streamer.marketDataTypes.LIMITUPLIMITDOWN:
|
|
91
|
-
print("LULD :" + message.symbol, "blue");
|
|
92
|
-
break;
|
|
93
|
-
case Streamer.marketDataTypes.IVGREEKS:
|
|
94
|
-
print("IVGreeks :" + message.symbol, "blue");
|
|
95
|
-
break;
|
|
96
|
-
case Streamer.marketDataTypes.IMBALANCESTATUS:
|
|
97
|
-
print("Imbalance status :" + message.symbol, "blue");
|
|
98
|
-
break;
|
|
99
|
-
case Streamer.marketDataTypes.TRADE:
|
|
100
|
-
print("Trade :" + message.symbol + " " + message.price, "blue");
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
// It's recommended to attach an error handler
|
|
106
|
-
// to help diagnose unexpected errors.
|
|
107
|
-
.on("error", function(err) {
|
|
108
|
-
print(err, "red");
|
|
109
|
-
})
|
|
110
|
-
.on("stats", function(msg) {
|
|
111
|
-
print("STATS. Number of l1 symbols available: " + msg.numberOfAvailableSymbolsL1 +
|
|
112
|
-
", number of l2 symbols available " + msg.numberOfAvailableSymbolsL2 +
|
|
113
|
-
", number of subscribed exchanges: " + msg.numberOfSubscribedExchanges +
|
|
114
|
-
", number of available connections: " + msg.numberOfAvailableConnections, "green");
|
|
115
|
-
})
|
|
116
|
-
.on("slow", function(msg) {
|
|
117
|
-
print("Slow -> TimesExceeded: " + msg.timesExceeded + " MaxExceed: " + msg.maxExceed);
|
|
118
|
-
})
|
|
119
|
-
.on("initialDataSent", function(msg) {
|
|
120
|
-
print("Initial data sent. Timestamp: " + msg.timestamp);
|
|
121
|
-
})
|
|
122
|
-
.on("resubscribeMessage", function(msg) {
|
|
123
|
-
print("Resubscription has been triggered. Timestamp: " + msg.timestamp);
|
|
124
|
-
})
|
|
125
|
-
//When reconnecting, you will need to listen to the main reconnect events. They will be in the following order:
|
|
126
|
-
// -reconnectSuccess: connection was successfully re-establish. reconnectSucess contains previousconnectionId and CurrentconnectionId.
|
|
127
|
-
// You should receive this along with a 200 ConnnectResponse.
|
|
128
|
-
// -reconnectMessage: once connection was estabished, if there where any previous subscriptions, you will recieve a
|
|
129
|
-
// reconnectMessage with the status code and symbols resubscribed
|
|
130
|
-
// -missedDatamessage: TODO
|
|
131
|
-
.on("reconnectSuccess", (msg) => {
|
|
132
|
-
print(`${msg.previousConnectionId} -> ${msg.currentConnectionId}`)
|
|
133
|
-
})
|
|
134
|
-
.on("reconnectMessage", (msg) => {
|
|
135
|
-
print(JSON.stringify(msg.entitlements), "blue");
|
|
136
|
-
})
|
|
137
|
-
// Due to network hiccups or other unexepected errors,
|
|
138
|
-
// the stream may be unexpectedly closed.
|
|
139
|
-
// For robustness, it's recommended to add reconnection logic.
|
|
140
|
-
.on("close", function(msg) {
|
|
141
|
-
print("Closed: " + msg);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
// Subscribe for symbols and subscription types.
|
|
145
|
-
// These can be either single strings or arrays of strings.
|
|
146
|
-
// See Object.keys(Streamer.subscriptionTypes) for available types.
|
|
147
|
-
// An optional options object can also be passed in. Current available options include:
|
|
148
|
-
// - skipHeavyInitialLoad: whether to skip initial heavy loads (e.g., previous trades and intervals), defaults to false.
|
|
149
|
-
// - conflation: Override default connection conflation, default to null. A matching conflation must be supplied when unsubscribing.
|
|
150
|
-
stream.subscribe(["GOOG"], [Streamer.subscriptionTypes.PRICEDATA], { skipHeavyInitialLoad: false }, then(function(result) {
|
|
151
|
-
// The subscription result will include the successful subscriptions
|
|
152
|
-
// as well as the unentitled and rejected subscriptions and invalid symbols.
|
|
153
|
-
var subscribed = result.subscribed;
|
|
154
|
-
for (var i = 0; i < subscribed.length; ++i) {
|
|
155
|
-
print("Subscribed: " + subscribed[i].symbol + " - " + subscribed[i].type + " (" + subscribed[i].entitlement + ")");
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// Retrieve available number of symbols and connections, number of currently open connections and subscribed symbols.
|
|
159
|
-
stream.getSessionStats();
|
|
160
|
-
|
|
161
|
-
setTimeout(function() {
|
|
162
|
-
// Unsubscribe for symbols and data types.
|
|
163
|
-
// These can be either single strings or arrays of strings.
|
|
164
|
-
// An optional options object can also be passed in. Current available options include:
|
|
165
|
-
// - conflation: Override default connection conflation, default to null. Should match a subscribe conflation.
|
|
166
|
-
stream.unsubscribe(["GOOG"], [Streamer.subscriptionTypes.PRICEDATA], {}, then(function(result) {
|
|
167
|
-
// The unsubscription result will include the unsubscriptions.
|
|
168
|
-
var unsubscribed = result.unsubscribed;
|
|
169
|
-
for (var i = 0; i < unsubscribed.length; ++i) {
|
|
170
|
-
print("Unsubscribed: " + unsubscribed[i].symbol + " - " + unsubscribed[i].type);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// Finally, close the stream.
|
|
174
|
-
//stream.close(then(function(){
|
|
175
|
-
//
|
|
176
|
-
//}));
|
|
177
|
-
}));
|
|
178
|
-
}, 5000);
|
|
179
|
-
}));
|
|
180
|
-
|
|
181
|
-
//Another example for a subscription for the Trade datatype
|
|
182
|
-
stream.subscribe(["MSFT"], [Streamer.subscriptionTypes.TRADE], { skipHeavyInitialLoad: false }, then(function(result) {
|
|
183
|
-
var subscribed = result.subscribed;
|
|
184
|
-
for (var i = 0; i < subscribed.length; ++i) {
|
|
185
|
-
print("Subscribed: " + subscribed[i].symbol + " - " + subscribed[i].type + " (" + subscribed[i].entitlement + ")");
|
|
186
|
-
}
|
|
187
|
-
stream.getSessionStats();
|
|
188
|
-
|
|
189
|
-
setTimeout(function() {
|
|
190
|
-
|
|
191
|
-
stream.unsubscribe(["MSFT"], [Streamer.subscriptionTypes.TRADE], {}, then(function(result) {
|
|
192
|
-
|
|
193
|
-
var unsubscribed = result.unsubscribed;
|
|
194
|
-
for (var i = 0; i < unsubscribed.length; ++i) {
|
|
195
|
-
print("Unsubscribed: " + unsubscribed[i].symbol + " - " + unsubscribed[i].type);
|
|
196
|
-
}
|
|
197
|
-
// Finally, close the stream.
|
|
198
|
-
stream.close(then(function() {
|
|
199
|
-
print("Streamer connection closed", "red");
|
|
200
|
-
}));
|
|
201
|
-
}));
|
|
202
|
-
}, 5000);
|
|
203
|
-
}));
|
|
204
|
-
|
|
205
|
-
//Now one thing to notice when using reconnect is that you can implement your own reconnect logic in the case
|
|
206
|
-
//that you close your connection for an other reason like slow, errors, etc.
|
|
207
|
-
//For this you will need to first close the previous conection and then call the performReconnect method as follows
|
|
208
|
-
//Also your reconnections do have a limit after closing this is set to 3 maxAttempts, once this is reached, any type of reconnections will stop.
|
|
209
|
-
|
|
210
|
-
//NOTICE: Transport errors are ALREADY HANDLED by default no need of doing these extra steps, since the call will fail due to connection
|
|
211
|
-
//already being up
|
|
212
|
-
|
|
213
|
-
// Stream already closed above
|
|
214
|
-
//stream.close();
|
|
215
|
-
stream.performReconnect(then(() => {
|
|
216
|
-
print("Successfull reconnection", "red")
|
|
217
|
-
}));
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Subscription to an exchange to receive stock status messages containing data such as halt,
|
|
221
|
-
* resume, regSHO.
|
|
222
|
-
* ************** NOTE: **************
|
|
223
|
-
* The stock status by exchange feature in the streaming datafeed api is considered a premium service
|
|
224
|
-
* that requires additional entitlements for clients to have access to the service and helps active traders
|
|
225
|
-
* to monitor the market. If you are entitled to this premium service and you want exchange data,
|
|
226
|
-
* you can uncomment the code below.
|
|
227
|
-
*
|
|
228
|
-
* Please inquire about your account if you need further information in this regard.
|
|
229
|
-
* @see https://quotemediasupport.freshdesk.com/support/solutions/articles/13000088921-exchange-level-subscriptions-only-stock-status-halt-regsho-is-supported
|
|
230
|
-
* ***********************************
|
|
231
|
-
*
|
|
232
|
-
* An optional options object can also be passed in. Current available options include:
|
|
233
|
-
* - conflation: Override default connection conflation, default to null.
|
|
234
|
-
*/
|
|
235
|
-
|
|
236
|
-
// stream.subscribeExchange("NYE", then(function(result) {
|
|
237
|
-
// print("Subscribed Exchange: " + result.exchange);
|
|
238
|
-
|
|
239
|
-
// setTimeout(function() {
|
|
240
|
-
// // Unsubscribe from the exchange.
|
|
241
|
-
// // An optional options object can also be passed in. Current available options include:
|
|
242
|
-
// // - conflation: Override default connection conflation, default to null. Should match a subscribe conflation.
|
|
243
|
-
// stream.unsubscribeExchange("NYE", then(function(result) {
|
|
244
|
-
// print("Unsubscribed Exchange: " + result.exchange);
|
|
245
|
-
|
|
246
|
-
// // Finally, close the stream.
|
|
247
|
-
// stream.close(then(function() {
|
|
248
|
-
|
|
249
|
-
// }));
|
|
250
|
-
// }));
|
|
251
|
-
// }, 5000);
|
|
252
|
-
// }));
|
|
253
|
-
}));
|
|
254
|
-
|
|
255
|
-
}));
|
|
256
|
-
|
|
257
|
-
function print(msg, color) {
|
|
258
|
-
var el = document.createElement("div");
|
|
259
|
-
el.innerText = msg;
|
|
260
|
-
if (color) {
|
|
261
|
-
el.style.color = color;
|
|
262
|
-
}
|
|
263
|
-
document.body.appendChild(el);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
function then(onSuccess) {
|
|
267
|
-
return function(err, result) {
|
|
268
|
-
if (err) {
|
|
269
|
-
print(err, "red");
|
|
270
|
-
} else {
|
|
271
|
-
onSuccess(result);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
</script>
|
|
277
|
-
</body>
|
|
278
|
-
|
|
1
|
+
<html>
|
|
2
|
+
|
|
3
|
+
<head>
|
|
4
|
+
<script src="qmci-streamer-2.41.0.min.js"></script>
|
|
5
|
+
</head>
|
|
6
|
+
|
|
7
|
+
<body>
|
|
8
|
+
<script type="text/javascript">
|
|
9
|
+
/**
|
|
10
|
+
* Demonstrates how to:
|
|
11
|
+
* - Configure and creating stream
|
|
12
|
+
* - Configure and opening connection
|
|
13
|
+
* - Set up callback to handle messages
|
|
14
|
+
* - Subscribe for symbols with different type of messages
|
|
15
|
+
* - Unsubscribe for the symbols and the messages type
|
|
16
|
+
* - Close the connection and stream
|
|
17
|
+
*/
|
|
18
|
+
window.onload = function() {
|
|
19
|
+
var Streamer = qmci.Streamer;
|
|
20
|
+
/**
|
|
21
|
+
* Step 1: Configure your login credentials inside the login method to get an SID
|
|
22
|
+
* Step 2: Open the streaming connection
|
|
23
|
+
* Step 3: Add the event listeners and the handlers for the messages
|
|
24
|
+
* Step 4: Make a subscription
|
|
25
|
+
* Step 5: Make unsubscribe
|
|
26
|
+
* Step 6: Close stream
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
// Log in to get an SID.
|
|
30
|
+
// This can be done by directly calling to QuoteMedia's auth service.
|
|
31
|
+
Streamer.login({
|
|
32
|
+
host: 'https://app.quotemedia.com/auth',
|
|
33
|
+
credentials: {
|
|
34
|
+
wmid: "YourWebmasterID",
|
|
35
|
+
username: "YourUsername",
|
|
36
|
+
password: "YourPassword"
|
|
37
|
+
}
|
|
38
|
+
}, then(function(sid) {
|
|
39
|
+
// After obtaining the SID, use it to authenticate
|
|
40
|
+
// and open a data stream.
|
|
41
|
+
// Set rejectExcessiveConnection:true to reject new connections when limit is reached. If not specified or value is false,
|
|
42
|
+
// first open connection will be closed instead.
|
|
43
|
+
// If needed, there is ability to specify conflation value per connection. When conflation value is null
|
|
44
|
+
// or not specified, default conflation is used.
|
|
45
|
+
// Set format value to 'application/qitch' to use this binary protocol.
|
|
46
|
+
// Please note that although QITCH protocol uses less bandwidth it can cause significant performance degradation.
|
|
47
|
+
// In case if no format was specified JSON will be used by default.
|
|
48
|
+
|
|
49
|
+
// Can also enable the built-in logging by setting the browser console as the logger.
|
|
50
|
+
// Must be set before calling open(). NOTE: May cause performance degradation.
|
|
51
|
+
// Streamer.logger = console;
|
|
52
|
+
Streamer.open({
|
|
53
|
+
host: 'https://app.quotemedia.com/cache',
|
|
54
|
+
cors: true,
|
|
55
|
+
rejectExcessiveConnection: false,
|
|
56
|
+
conflation: null,
|
|
57
|
+
format: 'application/json',
|
|
58
|
+
isReconnect: true,
|
|
59
|
+
credentials: { sid: sid }
|
|
60
|
+
}, then(function(stream) {
|
|
61
|
+
// After successfully opening the stream,
|
|
62
|
+
// listen for its events.
|
|
63
|
+
stream
|
|
64
|
+
// The stream will asynchronously callback with
|
|
65
|
+
// incoming market data messages.
|
|
66
|
+
.on("message", function(message) {
|
|
67
|
+
switch (Streamer.marketDataTypes.get(message)) {
|
|
68
|
+
case Streamer.marketDataTypes.PRICEDATA:
|
|
69
|
+
print("Price data: " + message.symbol, "blue");
|
|
70
|
+
break;
|
|
71
|
+
// For checking all the available marketDataTypes, go to the README.md file or check Object.keys(Streamer.marketDataTypes)
|
|
72
|
+
case Streamer.marketDataTypes.QUOTE:
|
|
73
|
+
print("Quote :" + message.symbol, "blue");
|
|
74
|
+
break;
|
|
75
|
+
case Streamer.marketDataTypes.MMQUOTE:
|
|
76
|
+
print("MMQuote :" + message.symbol, "blue");
|
|
77
|
+
break;
|
|
78
|
+
case Streamer.marketDataTypes.ORDERBOOK:
|
|
79
|
+
print("Orderbook :" + message.symbol, "blue");
|
|
80
|
+
break;
|
|
81
|
+
case Streamer.marketDataTypes.INTERVAL:
|
|
82
|
+
print("Interval :" + message.symbol, "blue");
|
|
83
|
+
break;
|
|
84
|
+
case Streamer.marketDataTypes.NETHOUSEPOSITION:
|
|
85
|
+
print("Nethouse Position :" + message.symbol, "blue");
|
|
86
|
+
break;
|
|
87
|
+
case Streamer.marketDataTypes.LASTSALE:
|
|
88
|
+
print("Last Sale :" + message.symbol, "blue");
|
|
89
|
+
break;
|
|
90
|
+
case Streamer.marketDataTypes.LIMITUPLIMITDOWN:
|
|
91
|
+
print("LULD :" + message.symbol, "blue");
|
|
92
|
+
break;
|
|
93
|
+
case Streamer.marketDataTypes.IVGREEKS:
|
|
94
|
+
print("IVGreeks :" + message.symbol, "blue");
|
|
95
|
+
break;
|
|
96
|
+
case Streamer.marketDataTypes.IMBALANCESTATUS:
|
|
97
|
+
print("Imbalance status :" + message.symbol, "blue");
|
|
98
|
+
break;
|
|
99
|
+
case Streamer.marketDataTypes.TRADE:
|
|
100
|
+
print("Trade :" + message.symbol + " " + message.price, "blue");
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
// It's recommended to attach an error handler
|
|
106
|
+
// to help diagnose unexpected errors.
|
|
107
|
+
.on("error", function(err) {
|
|
108
|
+
print(err, "red");
|
|
109
|
+
})
|
|
110
|
+
.on("stats", function(msg) {
|
|
111
|
+
print("STATS. Number of l1 symbols available: " + msg.numberOfAvailableSymbolsL1 +
|
|
112
|
+
", number of l2 symbols available " + msg.numberOfAvailableSymbolsL2 +
|
|
113
|
+
", number of subscribed exchanges: " + msg.numberOfSubscribedExchanges +
|
|
114
|
+
", number of available connections: " + msg.numberOfAvailableConnections, "green");
|
|
115
|
+
})
|
|
116
|
+
.on("slow", function(msg) {
|
|
117
|
+
print("Slow -> TimesExceeded: " + msg.timesExceeded + " MaxExceed: " + msg.maxExceed);
|
|
118
|
+
})
|
|
119
|
+
.on("initialDataSent", function(msg) {
|
|
120
|
+
print("Initial data sent. Timestamp: " + msg.timestamp);
|
|
121
|
+
})
|
|
122
|
+
.on("resubscribeMessage", function(msg) {
|
|
123
|
+
print("Resubscription has been triggered. Timestamp: " + msg.timestamp);
|
|
124
|
+
})
|
|
125
|
+
//When reconnecting, you will need to listen to the main reconnect events. They will be in the following order:
|
|
126
|
+
// -reconnectSuccess: connection was successfully re-establish. reconnectSucess contains previousconnectionId and CurrentconnectionId.
|
|
127
|
+
// You should receive this along with a 200 ConnnectResponse.
|
|
128
|
+
// -reconnectMessage: once connection was estabished, if there where any previous subscriptions, you will recieve a
|
|
129
|
+
// reconnectMessage with the status code and symbols resubscribed
|
|
130
|
+
// -missedDatamessage: TODO
|
|
131
|
+
.on("reconnectSuccess", (msg) => {
|
|
132
|
+
print(`${msg.previousConnectionId} -> ${msg.currentConnectionId}`)
|
|
133
|
+
})
|
|
134
|
+
.on("reconnectMessage", (msg) => {
|
|
135
|
+
print(JSON.stringify(msg.entitlements), "blue");
|
|
136
|
+
})
|
|
137
|
+
// Due to network hiccups or other unexepected errors,
|
|
138
|
+
// the stream may be unexpectedly closed.
|
|
139
|
+
// For robustness, it's recommended to add reconnection logic.
|
|
140
|
+
.on("close", function(msg) {
|
|
141
|
+
print("Closed: " + msg);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// Subscribe for symbols and subscription types.
|
|
145
|
+
// These can be either single strings or arrays of strings.
|
|
146
|
+
// See Object.keys(Streamer.subscriptionTypes) for available types.
|
|
147
|
+
// An optional options object can also be passed in. Current available options include:
|
|
148
|
+
// - skipHeavyInitialLoad: whether to skip initial heavy loads (e.g., previous trades and intervals), defaults to false.
|
|
149
|
+
// - conflation: Override default connection conflation, default to null. A matching conflation must be supplied when unsubscribing.
|
|
150
|
+
stream.subscribe(["GOOG"], [Streamer.subscriptionTypes.PRICEDATA], { skipHeavyInitialLoad: false }, then(function(result) {
|
|
151
|
+
// The subscription result will include the successful subscriptions
|
|
152
|
+
// as well as the unentitled and rejected subscriptions and invalid symbols.
|
|
153
|
+
var subscribed = result.subscribed;
|
|
154
|
+
for (var i = 0; i < subscribed.length; ++i) {
|
|
155
|
+
print("Subscribed: " + subscribed[i].symbol + " - " + subscribed[i].type + " (" + subscribed[i].entitlement + ")");
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Retrieve available number of symbols and connections, number of currently open connections and subscribed symbols.
|
|
159
|
+
stream.getSessionStats();
|
|
160
|
+
|
|
161
|
+
setTimeout(function() {
|
|
162
|
+
// Unsubscribe for symbols and data types.
|
|
163
|
+
// These can be either single strings or arrays of strings.
|
|
164
|
+
// An optional options object can also be passed in. Current available options include:
|
|
165
|
+
// - conflation: Override default connection conflation, default to null. Should match a subscribe conflation.
|
|
166
|
+
stream.unsubscribe(["GOOG"], [Streamer.subscriptionTypes.PRICEDATA], {}, then(function(result) {
|
|
167
|
+
// The unsubscription result will include the unsubscriptions.
|
|
168
|
+
var unsubscribed = result.unsubscribed;
|
|
169
|
+
for (var i = 0; i < unsubscribed.length; ++i) {
|
|
170
|
+
print("Unsubscribed: " + unsubscribed[i].symbol + " - " + unsubscribed[i].type);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Finally, close the stream.
|
|
174
|
+
//stream.close(then(function(){
|
|
175
|
+
//
|
|
176
|
+
//}));
|
|
177
|
+
}));
|
|
178
|
+
}, 5000);
|
|
179
|
+
}));
|
|
180
|
+
|
|
181
|
+
//Another example for a subscription for the Trade datatype
|
|
182
|
+
stream.subscribe(["MSFT"], [Streamer.subscriptionTypes.TRADE], { skipHeavyInitialLoad: false }, then(function(result) {
|
|
183
|
+
var subscribed = result.subscribed;
|
|
184
|
+
for (var i = 0; i < subscribed.length; ++i) {
|
|
185
|
+
print("Subscribed: " + subscribed[i].symbol + " - " + subscribed[i].type + " (" + subscribed[i].entitlement + ")");
|
|
186
|
+
}
|
|
187
|
+
stream.getSessionStats();
|
|
188
|
+
|
|
189
|
+
setTimeout(function() {
|
|
190
|
+
|
|
191
|
+
stream.unsubscribe(["MSFT"], [Streamer.subscriptionTypes.TRADE], {}, then(function(result) {
|
|
192
|
+
|
|
193
|
+
var unsubscribed = result.unsubscribed;
|
|
194
|
+
for (var i = 0; i < unsubscribed.length; ++i) {
|
|
195
|
+
print("Unsubscribed: " + unsubscribed[i].symbol + " - " + unsubscribed[i].type);
|
|
196
|
+
}
|
|
197
|
+
// Finally, close the stream.
|
|
198
|
+
stream.close(then(function() {
|
|
199
|
+
print("Streamer connection closed", "red");
|
|
200
|
+
}));
|
|
201
|
+
}));
|
|
202
|
+
}, 5000);
|
|
203
|
+
}));
|
|
204
|
+
|
|
205
|
+
//Now one thing to notice when using reconnect is that you can implement your own reconnect logic in the case
|
|
206
|
+
//that you close your connection for an other reason like slow, errors, etc.
|
|
207
|
+
//For this you will need to first close the previous conection and then call the performReconnect method as follows
|
|
208
|
+
//Also your reconnections do have a limit after closing this is set to 3 maxAttempts, once this is reached, any type of reconnections will stop.
|
|
209
|
+
|
|
210
|
+
//NOTICE: Transport errors are ALREADY HANDLED by default no need of doing these extra steps, since the call will fail due to connection
|
|
211
|
+
//already being up
|
|
212
|
+
|
|
213
|
+
// Stream already closed above
|
|
214
|
+
//stream.close();
|
|
215
|
+
stream.performReconnect(then(() => {
|
|
216
|
+
print("Successfull reconnection", "red")
|
|
217
|
+
}));
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Subscription to an exchange to receive stock status messages containing data such as halt,
|
|
221
|
+
* resume, regSHO.
|
|
222
|
+
* ************** NOTE: **************
|
|
223
|
+
* The stock status by exchange feature in the streaming datafeed api is considered a premium service
|
|
224
|
+
* that requires additional entitlements for clients to have access to the service and helps active traders
|
|
225
|
+
* to monitor the market. If you are entitled to this premium service and you want exchange data,
|
|
226
|
+
* you can uncomment the code below.
|
|
227
|
+
*
|
|
228
|
+
* Please inquire about your account if you need further information in this regard.
|
|
229
|
+
* @see https://quotemediasupport.freshdesk.com/support/solutions/articles/13000088921-exchange-level-subscriptions-only-stock-status-halt-regsho-is-supported
|
|
230
|
+
* ***********************************
|
|
231
|
+
*
|
|
232
|
+
* An optional options object can also be passed in. Current available options include:
|
|
233
|
+
* - conflation: Override default connection conflation, default to null.
|
|
234
|
+
*/
|
|
235
|
+
|
|
236
|
+
// stream.subscribeExchange("NYE", then(function(result) {
|
|
237
|
+
// print("Subscribed Exchange: " + result.exchange);
|
|
238
|
+
|
|
239
|
+
// setTimeout(function() {
|
|
240
|
+
// // Unsubscribe from the exchange.
|
|
241
|
+
// // An optional options object can also be passed in. Current available options include:
|
|
242
|
+
// // - conflation: Override default connection conflation, default to null. Should match a subscribe conflation.
|
|
243
|
+
// stream.unsubscribeExchange("NYE", then(function(result) {
|
|
244
|
+
// print("Unsubscribed Exchange: " + result.exchange);
|
|
245
|
+
|
|
246
|
+
// // Finally, close the stream.
|
|
247
|
+
// stream.close(then(function() {
|
|
248
|
+
|
|
249
|
+
// }));
|
|
250
|
+
// }));
|
|
251
|
+
// }, 5000);
|
|
252
|
+
// }));
|
|
253
|
+
}));
|
|
254
|
+
|
|
255
|
+
}));
|
|
256
|
+
|
|
257
|
+
function print(msg, color) {
|
|
258
|
+
var el = document.createElement("div");
|
|
259
|
+
el.innerText = msg;
|
|
260
|
+
if (color) {
|
|
261
|
+
el.style.color = color;
|
|
262
|
+
}
|
|
263
|
+
document.body.appendChild(el);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function then(onSuccess) {
|
|
267
|
+
return function(err, result) {
|
|
268
|
+
if (err) {
|
|
269
|
+
print(err, "red");
|
|
270
|
+
} else {
|
|
271
|
+
onSuccess(result);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
</script>
|
|
277
|
+
</body>
|
|
278
|
+
|
|
279
279
|
</html>
|