@quotemedia.com/streamer 2.33.0 → 2.39.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 -133
- 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 +682 -0
- package/examples/subscription-example.html +252 -252
- package/examples/test_example.html +126 -0
- package/examples/wmid-example.html +176 -176
- package/package.json +38 -38
- package/{qmci-streamer-2.33.0.js → qmci-streamer-2.39.0.js} +2133 -1568
- package/qmci-streamer-2.39.0.min.js +115 -0
- package/examples/user-access-token-example.html +0 -177
- package/qmci-streamer-2.33.0.min.js +0 -115
|
@@ -1,253 +1,253 @@
|
|
|
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
|
-
credentials: { sid: sid }
|
|
59
|
-
}, then(function(stream) {
|
|
60
|
-
// After successfully opening the stream,
|
|
61
|
-
// listen for its events.
|
|
62
|
-
stream
|
|
63
|
-
// The stream will asynchronously callback with
|
|
64
|
-
// incoming market data messages.
|
|
65
|
-
.on("message", function(message) {
|
|
66
|
-
switch (Streamer.
|
|
67
|
-
case Streamer.
|
|
68
|
-
print("Price data: " + message.symbol, "blue");
|
|
69
|
-
break;
|
|
70
|
-
// For checking all the available
|
|
71
|
-
case Streamer.
|
|
72
|
-
print("Quote :" + message.symbol, "blue");
|
|
73
|
-
break;
|
|
74
|
-
case Streamer.
|
|
75
|
-
print("MMQuote :" + message.symbol, "blue");
|
|
76
|
-
break;
|
|
77
|
-
case Streamer.
|
|
78
|
-
print("Orderbook :" + message.symbol, "blue");
|
|
79
|
-
break;
|
|
80
|
-
case Streamer.
|
|
81
|
-
print("Interval :" + message.symbol, "blue");
|
|
82
|
-
break;
|
|
83
|
-
case Streamer.
|
|
84
|
-
print("Nethouse Position :" + message.symbol, "blue");
|
|
85
|
-
break;
|
|
86
|
-
case Streamer.
|
|
87
|
-
print("Last Sale :" + message.symbol, "blue");
|
|
88
|
-
break;
|
|
89
|
-
case Streamer.
|
|
90
|
-
print("LULD :" + message.symbol, "blue");
|
|
91
|
-
break;
|
|
92
|
-
case Streamer.
|
|
93
|
-
print("IVGreeks :" + message.symbol, "blue");
|
|
94
|
-
break;
|
|
95
|
-
case Streamer.
|
|
96
|
-
print("Imbalance status :" + message.symbol, "blue");
|
|
97
|
-
break;
|
|
98
|
-
case Streamer.
|
|
99
|
-
print("Trade :" + message.symbol + " " + message.price, "blue");
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
// It's recommended to attach an error handler
|
|
105
|
-
// to help diagnose unexpected errors.
|
|
106
|
-
.on("error", function(err) {
|
|
107
|
-
print(err, "red");
|
|
108
|
-
})
|
|
109
|
-
.on("stats", function(msg) {
|
|
110
|
-
print("STATS. Number of l1 symbols available: " + msg.numberOfAvailableSymbolsL1 +
|
|
111
|
-
", number of l2 symbols available " + msg.numberOfAvailableSymbolsL2 +
|
|
112
|
-
", number of subscribed exchanges: " + msg.numberOfSubscribedExchanges +
|
|
113
|
-
", number of available connections: " + msg.numberOfAvailableConnections, "green");
|
|
114
|
-
})
|
|
115
|
-
.on("slow", function(msg) {
|
|
116
|
-
print("Slow -> TimesExceeded: " + msg.timesExceeded + " MaxExceed: " + msg.maxExceed);
|
|
117
|
-
})
|
|
118
|
-
.on("initialDataSent", function(msg) {
|
|
119
|
-
print("Initial data sent. Timestamp: " + msg.timestamp);
|
|
120
|
-
})
|
|
121
|
-
.on("resubscribeMessage", function(msg) {
|
|
122
|
-
print("Resubscription has been triggered. Timestamp: " + msg.timestamp);
|
|
123
|
-
})
|
|
124
|
-
// Due to network hiccups or other unexepected errors,
|
|
125
|
-
// the stream may be unexpectedly closed.
|
|
126
|
-
// For robustness, it's recommended to add reconnection logic.
|
|
127
|
-
.on("close", function(msg) {
|
|
128
|
-
print("Closed: " + msg);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
// Subscribe for symbols and
|
|
132
|
-
// These can be either single strings or arrays of strings.
|
|
133
|
-
// See Object.keys(Streamer.
|
|
134
|
-
// An optional options object can also be passed in. Current available options include:
|
|
135
|
-
// - skipHeavyInitialLoad: whether to skip initial heavy loads (e.g., previous trades and intervals), defaults to false.
|
|
136
|
-
// - conflation: Override default connection conflation, default to null. A matching conflation must be supplied when unsubscribing.
|
|
137
|
-
stream.subscribe(["GOOG"], [Streamer.
|
|
138
|
-
// The subscription result will include the successful subscriptions
|
|
139
|
-
// as well as the unentitled and rejected subscriptions and invalid symbols.
|
|
140
|
-
var subscribed = result.subscribed;
|
|
141
|
-
for (var i = 0; i < subscribed.length; ++i) {
|
|
142
|
-
print("Subscribed: " + subscribed[i].symbol + " - " + subscribed[i].type + " (" + subscribed[i].entitlement + ")");
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Retrieve available number of symbols and connections, number of currently open connections and subscribed symbols.
|
|
146
|
-
stream.getSessionStats();
|
|
147
|
-
|
|
148
|
-
setTimeout(function() {
|
|
149
|
-
// Unsubscribe for symbols and data types.
|
|
150
|
-
// These can be either single strings or arrays of strings.
|
|
151
|
-
// An optional options object can also be passed in. Current available options include:
|
|
152
|
-
// - conflation: Override default connection conflation, default to null. Should match a subscribe conflation.
|
|
153
|
-
stream.unsubscribe(["GOOG"], [Streamer.
|
|
154
|
-
// The unsubscription result will include the unsubscriptions.
|
|
155
|
-
var unsubscribed = result.unsubscribed;
|
|
156
|
-
for (var i = 0; i < unsubscribed.length; ++i) {
|
|
157
|
-
print("Unsubscribed: " + unsubscribed[i].symbol + " - " + unsubscribed[i].type);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Finally, close the stream.
|
|
161
|
-
//stream.close(then(function(){
|
|
162
|
-
//
|
|
163
|
-
//}));
|
|
164
|
-
}));
|
|
165
|
-
}, 5000);
|
|
166
|
-
}));
|
|
167
|
-
|
|
168
|
-
//Another example for a subscription for the Trade datatype
|
|
169
|
-
stream.subscribe(["MSFT"], [Streamer.
|
|
170
|
-
var subscribed = result.subscribed;
|
|
171
|
-
for (var i = 0; i < subscribed.length; ++i) {
|
|
172
|
-
print("Subscribed: " + subscribed[i].symbol + " - " + subscribed[i].type + " (" + subscribed[i].entitlement + ")");
|
|
173
|
-
}
|
|
174
|
-
stream.getSessionStats();
|
|
175
|
-
|
|
176
|
-
setTimeout(function() {
|
|
177
|
-
|
|
178
|
-
stream.unsubscribe(["MSFT"], [Streamer.
|
|
179
|
-
|
|
180
|
-
var unsubscribed = result.unsubscribed;
|
|
181
|
-
for (var i = 0; i < unsubscribed.length; ++i) {
|
|
182
|
-
print("Unsubscribed: " + unsubscribed[i].symbol + " - " + unsubscribed[i].type);
|
|
183
|
-
}
|
|
184
|
-
// Finally, close the stream.
|
|
185
|
-
stream.close(then(function() {
|
|
186
|
-
print("Streamer connection closed", "red");
|
|
187
|
-
}));
|
|
188
|
-
}));
|
|
189
|
-
}, 5000);
|
|
190
|
-
}));
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Subscription to an exchange to receive stock status messages containing data such as halt,
|
|
195
|
-
* resume, regSHO.
|
|
196
|
-
* ************** NOTE: **************
|
|
197
|
-
* The stock status by exchange feature in the streaming datafeed api is considered a premium service
|
|
198
|
-
* that requires additional entitlements for clients to have access to the service and helps active traders
|
|
199
|
-
* to monitor the market. If you are entitled to this premium service and you want exchange data,
|
|
200
|
-
* you can uncomment the code below.
|
|
201
|
-
*
|
|
202
|
-
* Please inquire about your account if you need further information in this regard.
|
|
203
|
-
* @see https://quotemediasupport.freshdesk.com/support/solutions/articles/13000088921-exchange-level-subscriptions-only-stock-status-halt-regsho-is-supported
|
|
204
|
-
* ***********************************
|
|
205
|
-
*
|
|
206
|
-
* An optional options object can also be passed in. Current available options include:
|
|
207
|
-
* - conflation: Override default connection conflation, default to null.
|
|
208
|
-
*/
|
|
209
|
-
|
|
210
|
-
// stream.subscribeExchange("NYE", then(function(result) {
|
|
211
|
-
// print("Subscribed Exchange: " + result.exchange);
|
|
212
|
-
|
|
213
|
-
// setTimeout(function() {
|
|
214
|
-
// // Unsubscribe from the exchange.
|
|
215
|
-
// // An optional options object can also be passed in. Current available options include:
|
|
216
|
-
// // - conflation: Override default connection conflation, default to null. Should match a subscribe conflation.
|
|
217
|
-
// stream.unsubscribeExchange("NYE", then(function(result) {
|
|
218
|
-
// print("Unsubscribed Exchange: " + result.exchange);
|
|
219
|
-
|
|
220
|
-
// // Finally, close the stream.
|
|
221
|
-
// stream.close(then(function() {
|
|
222
|
-
|
|
223
|
-
// }));
|
|
224
|
-
// }));
|
|
225
|
-
// }, 5000);
|
|
226
|
-
// }));
|
|
227
|
-
}));
|
|
228
|
-
|
|
229
|
-
}));
|
|
230
|
-
|
|
231
|
-
function print(msg, color) {
|
|
232
|
-
var el = document.createElement("div");
|
|
233
|
-
el.innerText = msg;
|
|
234
|
-
if (color) {
|
|
235
|
-
el.style.color = color;
|
|
236
|
-
}
|
|
237
|
-
document.body.appendChild(el);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function then(onSuccess) {
|
|
241
|
-
return function(err, result) {
|
|
242
|
-
if (err) {
|
|
243
|
-
print(err, "red");
|
|
244
|
-
} else {
|
|
245
|
-
onSuccess(result);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
};
|
|
250
|
-
</script>
|
|
251
|
-
</body>
|
|
252
|
-
|
|
1
|
+
<html>
|
|
2
|
+
|
|
3
|
+
<head>
|
|
4
|
+
<script src="qmci-streamer-2.39.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
|
+
credentials: { sid: sid }
|
|
59
|
+
}, then(function(stream) {
|
|
60
|
+
// After successfully opening the stream,
|
|
61
|
+
// listen for its events.
|
|
62
|
+
stream
|
|
63
|
+
// The stream will asynchronously callback with
|
|
64
|
+
// incoming market data messages.
|
|
65
|
+
.on("message", function(message) {
|
|
66
|
+
switch (Streamer.marketDataTypes.get(message)) {
|
|
67
|
+
case Streamer.marketDataTypes.PRICEDATA:
|
|
68
|
+
print("Price data: " + message.symbol, "blue");
|
|
69
|
+
break;
|
|
70
|
+
// For checking all the available marketDataTypes, go to the README.md file or check Object.keys(Streamer.marketDataTypes)
|
|
71
|
+
case Streamer.marketDataTypes.QUOTE:
|
|
72
|
+
print("Quote :" + message.symbol, "blue");
|
|
73
|
+
break;
|
|
74
|
+
case Streamer.marketDataTypes.MMQUOTE:
|
|
75
|
+
print("MMQuote :" + message.symbol, "blue");
|
|
76
|
+
break;
|
|
77
|
+
case Streamer.marketDataTypes.ORDERBOOK:
|
|
78
|
+
print("Orderbook :" + message.symbol, "blue");
|
|
79
|
+
break;
|
|
80
|
+
case Streamer.marketDataTypes.INTERVAL:
|
|
81
|
+
print("Interval :" + message.symbol, "blue");
|
|
82
|
+
break;
|
|
83
|
+
case Streamer.marketDataTypes.NETHOUSEPOSITION:
|
|
84
|
+
print("Nethouse Position :" + message.symbol, "blue");
|
|
85
|
+
break;
|
|
86
|
+
case Streamer.marketDataTypes.LASTSALE:
|
|
87
|
+
print("Last Sale :" + message.symbol, "blue");
|
|
88
|
+
break;
|
|
89
|
+
case Streamer.marketDataTypes.LIMITUPLIMITDOWN:
|
|
90
|
+
print("LULD :" + message.symbol, "blue");
|
|
91
|
+
break;
|
|
92
|
+
case Streamer.marketDataTypes.IVGREEKS:
|
|
93
|
+
print("IVGreeks :" + message.symbol, "blue");
|
|
94
|
+
break;
|
|
95
|
+
case Streamer.marketDataTypes.IMBALANCESTATUS:
|
|
96
|
+
print("Imbalance status :" + message.symbol, "blue");
|
|
97
|
+
break;
|
|
98
|
+
case Streamer.marketDataTypes.TRADE:
|
|
99
|
+
print("Trade :" + message.symbol + " " + message.price, "blue");
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
// It's recommended to attach an error handler
|
|
105
|
+
// to help diagnose unexpected errors.
|
|
106
|
+
.on("error", function(err) {
|
|
107
|
+
print(err, "red");
|
|
108
|
+
})
|
|
109
|
+
.on("stats", function(msg) {
|
|
110
|
+
print("STATS. Number of l1 symbols available: " + msg.numberOfAvailableSymbolsL1 +
|
|
111
|
+
", number of l2 symbols available " + msg.numberOfAvailableSymbolsL2 +
|
|
112
|
+
", number of subscribed exchanges: " + msg.numberOfSubscribedExchanges +
|
|
113
|
+
", number of available connections: " + msg.numberOfAvailableConnections, "green");
|
|
114
|
+
})
|
|
115
|
+
.on("slow", function(msg) {
|
|
116
|
+
print("Slow -> TimesExceeded: " + msg.timesExceeded + " MaxExceed: " + msg.maxExceed);
|
|
117
|
+
})
|
|
118
|
+
.on("initialDataSent", function(msg) {
|
|
119
|
+
print("Initial data sent. Timestamp: " + msg.timestamp);
|
|
120
|
+
})
|
|
121
|
+
.on("resubscribeMessage", function(msg) {
|
|
122
|
+
print("Resubscription has been triggered. Timestamp: " + msg.timestamp);
|
|
123
|
+
})
|
|
124
|
+
// Due to network hiccups or other unexepected errors,
|
|
125
|
+
// the stream may be unexpectedly closed.
|
|
126
|
+
// For robustness, it's recommended to add reconnection logic.
|
|
127
|
+
.on("close", function(msg) {
|
|
128
|
+
print("Closed: " + msg);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// Subscribe for symbols and subscription types.
|
|
132
|
+
// These can be either single strings or arrays of strings.
|
|
133
|
+
// See Object.keys(Streamer.subscriptionTypes) for available types.
|
|
134
|
+
// An optional options object can also be passed in. Current available options include:
|
|
135
|
+
// - skipHeavyInitialLoad: whether to skip initial heavy loads (e.g., previous trades and intervals), defaults to false.
|
|
136
|
+
// - conflation: Override default connection conflation, default to null. A matching conflation must be supplied when unsubscribing.
|
|
137
|
+
stream.subscribe(["GOOG"], [Streamer.subscriptionTypes.PRICEDATA], { skipHeavyInitialLoad: false }, then(function(result) {
|
|
138
|
+
// The subscription result will include the successful subscriptions
|
|
139
|
+
// as well as the unentitled and rejected subscriptions and invalid symbols.
|
|
140
|
+
var subscribed = result.subscribed;
|
|
141
|
+
for (var i = 0; i < subscribed.length; ++i) {
|
|
142
|
+
print("Subscribed: " + subscribed[i].symbol + " - " + subscribed[i].type + " (" + subscribed[i].entitlement + ")");
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Retrieve available number of symbols and connections, number of currently open connections and subscribed symbols.
|
|
146
|
+
stream.getSessionStats();
|
|
147
|
+
|
|
148
|
+
setTimeout(function() {
|
|
149
|
+
// Unsubscribe for symbols and data types.
|
|
150
|
+
// These can be either single strings or arrays of strings.
|
|
151
|
+
// An optional options object can also be passed in. Current available options include:
|
|
152
|
+
// - conflation: Override default connection conflation, default to null. Should match a subscribe conflation.
|
|
153
|
+
stream.unsubscribe(["GOOG"], [Streamer.subscriptionTypes.PRICEDATA], {}, then(function(result) {
|
|
154
|
+
// The unsubscription result will include the unsubscriptions.
|
|
155
|
+
var unsubscribed = result.unsubscribed;
|
|
156
|
+
for (var i = 0; i < unsubscribed.length; ++i) {
|
|
157
|
+
print("Unsubscribed: " + unsubscribed[i].symbol + " - " + unsubscribed[i].type);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Finally, close the stream.
|
|
161
|
+
//stream.close(then(function(){
|
|
162
|
+
//
|
|
163
|
+
//}));
|
|
164
|
+
}));
|
|
165
|
+
}, 5000);
|
|
166
|
+
}));
|
|
167
|
+
|
|
168
|
+
//Another example for a subscription for the Trade datatype
|
|
169
|
+
stream.subscribe(["MSFT"], [Streamer.subscriptionTypes.TRADE], { skipHeavyInitialLoad: false }, then(function(result) {
|
|
170
|
+
var subscribed = result.subscribed;
|
|
171
|
+
for (var i = 0; i < subscribed.length; ++i) {
|
|
172
|
+
print("Subscribed: " + subscribed[i].symbol + " - " + subscribed[i].type + " (" + subscribed[i].entitlement + ")");
|
|
173
|
+
}
|
|
174
|
+
stream.getSessionStats();
|
|
175
|
+
|
|
176
|
+
setTimeout(function() {
|
|
177
|
+
|
|
178
|
+
stream.unsubscribe(["MSFT"], [Streamer.subscriptionTypes.TRADE], {}, then(function(result) {
|
|
179
|
+
|
|
180
|
+
var unsubscribed = result.unsubscribed;
|
|
181
|
+
for (var i = 0; i < unsubscribed.length; ++i) {
|
|
182
|
+
print("Unsubscribed: " + unsubscribed[i].symbol + " - " + unsubscribed[i].type);
|
|
183
|
+
}
|
|
184
|
+
// Finally, close the stream.
|
|
185
|
+
stream.close(then(function() {
|
|
186
|
+
print("Streamer connection closed", "red");
|
|
187
|
+
}));
|
|
188
|
+
}));
|
|
189
|
+
}, 5000);
|
|
190
|
+
}));
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Subscription to an exchange to receive stock status messages containing data such as halt,
|
|
195
|
+
* resume, regSHO.
|
|
196
|
+
* ************** NOTE: **************
|
|
197
|
+
* The stock status by exchange feature in the streaming datafeed api is considered a premium service
|
|
198
|
+
* that requires additional entitlements for clients to have access to the service and helps active traders
|
|
199
|
+
* to monitor the market. If you are entitled to this premium service and you want exchange data,
|
|
200
|
+
* you can uncomment the code below.
|
|
201
|
+
*
|
|
202
|
+
* Please inquire about your account if you need further information in this regard.
|
|
203
|
+
* @see https://quotemediasupport.freshdesk.com/support/solutions/articles/13000088921-exchange-level-subscriptions-only-stock-status-halt-regsho-is-supported
|
|
204
|
+
* ***********************************
|
|
205
|
+
*
|
|
206
|
+
* An optional options object can also be passed in. Current available options include:
|
|
207
|
+
* - conflation: Override default connection conflation, default to null.
|
|
208
|
+
*/
|
|
209
|
+
|
|
210
|
+
// stream.subscribeExchange("NYE", then(function(result) {
|
|
211
|
+
// print("Subscribed Exchange: " + result.exchange);
|
|
212
|
+
|
|
213
|
+
// setTimeout(function() {
|
|
214
|
+
// // Unsubscribe from the exchange.
|
|
215
|
+
// // An optional options object can also be passed in. Current available options include:
|
|
216
|
+
// // - conflation: Override default connection conflation, default to null. Should match a subscribe conflation.
|
|
217
|
+
// stream.unsubscribeExchange("NYE", then(function(result) {
|
|
218
|
+
// print("Unsubscribed Exchange: " + result.exchange);
|
|
219
|
+
|
|
220
|
+
// // Finally, close the stream.
|
|
221
|
+
// stream.close(then(function() {
|
|
222
|
+
|
|
223
|
+
// }));
|
|
224
|
+
// }));
|
|
225
|
+
// }, 5000);
|
|
226
|
+
// }));
|
|
227
|
+
}));
|
|
228
|
+
|
|
229
|
+
}));
|
|
230
|
+
|
|
231
|
+
function print(msg, color) {
|
|
232
|
+
var el = document.createElement("div");
|
|
233
|
+
el.innerText = msg;
|
|
234
|
+
if (color) {
|
|
235
|
+
el.style.color = color;
|
|
236
|
+
}
|
|
237
|
+
document.body.appendChild(el);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function then(onSuccess) {
|
|
241
|
+
return function(err, result) {
|
|
242
|
+
if (err) {
|
|
243
|
+
print(err, "red");
|
|
244
|
+
} else {
|
|
245
|
+
onSuccess(result);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
</script>
|
|
251
|
+
</body>
|
|
252
|
+
|
|
253
253
|
</html>
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
<html>
|
|
2
|
+
<head>
|
|
3
|
+
<meta charset="UTF-8">
|
|
4
|
+
<meta name="viewport"
|
|
5
|
+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
7
|
+
<title>Document</title>
|
|
8
|
+
<script src="qmci-streamer-2.38.0.min.js"></script>
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<div id="test">
|
|
12
|
+
</div>
|
|
13
|
+
</body>
|
|
14
|
+
<script>
|
|
15
|
+
var streamer = new qmci.Streamer;
|
|
16
|
+
let loginPromise = new Promise((resolve, reject)=>{
|
|
17
|
+
Streamer.login({
|
|
18
|
+
host: 'https://qa.quotemedia.com/auth',
|
|
19
|
+
credentials: {
|
|
20
|
+
wmid: "YourWebmasterID",
|
|
21
|
+
username: "YourUsername",
|
|
22
|
+
password: "YourPassword"
|
|
23
|
+
}
|
|
24
|
+
}, (sid)=>{
|
|
25
|
+
if(sid != null){
|
|
26
|
+
resolve(sid);
|
|
27
|
+
}
|
|
28
|
+
else{
|
|
29
|
+
reject();
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
let openPromise = loginPromise.then((sid)=>{
|
|
36
|
+
Streamer.open({
|
|
37
|
+
host: 'http://localhost:9000',
|
|
38
|
+
cors: true,
|
|
39
|
+
rejectExcessiveConnection: false,
|
|
40
|
+
conflation: null,
|
|
41
|
+
format: 'application/json',
|
|
42
|
+
credentials: {sid: sid}
|
|
43
|
+
}, (stream) =>{
|
|
44
|
+
stream
|
|
45
|
+
// The stream will asynchronously callback with
|
|
46
|
+
// incoming market data messages.
|
|
47
|
+
.on("message", function(message) {
|
|
48
|
+
switch (Streamer.marketDataTypes.get(message)) {
|
|
49
|
+
case Streamer.marketDataTypes.PRICEDATA:
|
|
50
|
+
print("Price data: " + message.symbol, "blue");
|
|
51
|
+
break;
|
|
52
|
+
// For checking all the available marketDataTypes, go to the README.md file or check Object.keys(Streamer.marketDataTypes)
|
|
53
|
+
case Streamer.marketDataTypes.QUOTE:
|
|
54
|
+
print("Quote :" + message.symbol, "blue");
|
|
55
|
+
break;
|
|
56
|
+
case Streamer.marketDataTypes.MMQUOTE:
|
|
57
|
+
print("MMQuote :" + message.symbol, "blue");
|
|
58
|
+
break;
|
|
59
|
+
case Streamer.marketDataTypes.ORDERBOOK:
|
|
60
|
+
print("Orderbook :" + message.symbol, "blue");
|
|
61
|
+
break;
|
|
62
|
+
case Streamer.marketDataTypes.INTERVAL:
|
|
63
|
+
print("Interval :" + message.symbol, "blue");
|
|
64
|
+
break;
|
|
65
|
+
case Streamer.marketDataTypes.NETHOUSEPOSITION:
|
|
66
|
+
print("Nethouse Position :" + message.symbol, "blue");
|
|
67
|
+
break;
|
|
68
|
+
case Streamer.marketDataTypes.LASTSALE:
|
|
69
|
+
print("Last Sale :" + message.symbol, "blue");
|
|
70
|
+
break;
|
|
71
|
+
case Streamer.marketDataTypes.LIMITUPLIMITDOWN:
|
|
72
|
+
print("LULD :" + message.symbol, "blue");
|
|
73
|
+
break;
|
|
74
|
+
case Streamer.marketDataTypes.IVGREEKS:
|
|
75
|
+
print("IVGreeks :" + message.symbol, "blue");
|
|
76
|
+
break;
|
|
77
|
+
case Streamer.marketDataTypes.IMBALANCESTATUS:
|
|
78
|
+
print("Imbalance status :" + message.symbol, "blue");
|
|
79
|
+
break;
|
|
80
|
+
case Streamer.marketDataTypes.TRADE:
|
|
81
|
+
print("Trade :" + message.symbol + " " + message.price, "blue");
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
// It's recommended to attach an error handler
|
|
87
|
+
// to help diagnose unexpected errors.
|
|
88
|
+
.on("error", function(err) {
|
|
89
|
+
print(err, "red");
|
|
90
|
+
})
|
|
91
|
+
.on("stats", function(msg) {
|
|
92
|
+
print("STATS. Number of l1 symbols available: " + msg.numberOfAvailableSymbolsL1 +
|
|
93
|
+
", number of l2 symbols available " + msg.numberOfAvailableSymbolsL2 +
|
|
94
|
+
", number of subscribed exchanges: " + msg.numberOfSubscribedExchanges +
|
|
95
|
+
", number of available connections: " + msg.numberOfAvailableConnections, "green");
|
|
96
|
+
})
|
|
97
|
+
.on("slow", function(msg) {
|
|
98
|
+
print("Slow -> TimesExceeded: " + msg.timesExceeded + " MaxExceed: " + msg.maxExceed);
|
|
99
|
+
})
|
|
100
|
+
.on("initialDataSent", function(msg) {
|
|
101
|
+
print("Initial data sent. Timestamp: " + msg.timestamp);
|
|
102
|
+
})
|
|
103
|
+
.on("resubscribeMessage", function(msg) {
|
|
104
|
+
print("Resubscription has been triggered. Timestamp: " + msg.timestamp);
|
|
105
|
+
})
|
|
106
|
+
// Due to network hiccups or other unexepected errors,
|
|
107
|
+
// the stream may be unexpectedly closed.
|
|
108
|
+
// For robustness, it's recommended to add reconnection logic.
|
|
109
|
+
.on("close", function(msg) {
|
|
110
|
+
print("Closed: " + msg);
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
});
|
|
114
|
+
}).then()
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
function print(msg, color) {
|
|
118
|
+
var el = document.createElement("div");
|
|
119
|
+
el.innerText = msg;
|
|
120
|
+
if (color) {
|
|
121
|
+
el.style.color = color;
|
|
122
|
+
}
|
|
123
|
+
document.body.appendChild(el);
|
|
124
|
+
}
|
|
125
|
+
</script>
|
|
126
|
+
</html>
|