@quotemedia.com/streamer 2.31.0 → 2.36.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.
@@ -1,177 +0,0 @@
1
- <html>
2
-
3
- <head>
4
- <script src="qmci-streamer-2.31.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
- Streamer.open({
30
- host: 'https://app.quotemedia.com/cache',
31
- cors: true,
32
- rejectExcessiveConnection: false,
33
- conflation: null,
34
- format: 'application/json',
35
- credentials: {
36
- data_token: "YourDatoToolToken",
37
- userAccessToken: "YourUserAccessToken"
38
- }
39
- }, then(function(stream) {
40
- // After successfully opening the stream,
41
- // listen for its events.
42
- stream
43
- // The stream will asynchronously callback with
44
- // incoming market data messages.
45
- .on("message", function(message) {
46
- switch (Streamer.dataTypes.get(message)) {
47
- case Streamer.dataTypes.PRICEDATA:
48
- print("Price data: " + message.symbol, "blue");
49
- break;
50
- }
51
- })
52
-
53
- // It's recommended to attach an error handler
54
- // to help diagnose unexpected errors.
55
- .on("error", function(err) {
56
- print(err, "red");
57
- })
58
- .on("stats", function(msg) {
59
- print("STATS. Number of l1 symbols available: " + msg.numberOfAvailableSymbolsL1 +
60
- ", number of l2 symbols available " + msg.numberOfAvailableSymbolsL2 +
61
- ", number of subscribed exchanges: " + msg.numberOfSubscribedExchanges +
62
- ", number of available connections: " + msg.numberOfAvailableConnections, "green");
63
- })
64
- .on("slow", function(msg) {
65
- print("Slow -> TimesExceeded: " + msg.timesExceeded + " MaxExceed: " + msg.maxExceed);
66
- })
67
- .on("initialDataSent", function(msg) {
68
- print("Initial data sent. Timestamp: " + msg.timestamp);
69
- })
70
- .on("resubscribeMessage", function(msg) {
71
- print("Resubscription has been triggered. Timestamp: " + msg.timestamp);
72
- })
73
- // Due to network hiccups or other unexepected errors,
74
- // the stream may be unexpectedly closed.
75
- // For robustness, it's recommended to add reconnection logic.
76
- .on("close", function(msg) {
77
- print("Closed: " + msg);
78
- });
79
-
80
- // Subscribe for symbols and data types.
81
- // These can be either single strings or arrays of strings.
82
- // See Object.keys(Streamer.datatTypes) for available types.
83
- // An optional options object can also be passed in. Current available options include:
84
- // - skipHeavyInitialLoad: whether to skip initial heavy loads (e.g., previous trades and intervals), defaults to false.
85
- // - conflation: Override default connection conflation, default to null. A matching conflation must be supplied when unsubscribing.
86
- stream.subscribe(["GOOG"], [Streamer.dataTypes.PRICEDATA], { skipHeavyInitialLoad: false }, then(function(result) {
87
- // The subscription result will include the successful subscriptions
88
- // as well as the unentitled and rejected subscriptions and invalid symbols.
89
- var subscribed = result.subscribed;
90
- for (var i = 0; i < subscribed.length; ++i) {
91
- print("Subscribed: " + subscribed[i].symbol + " - " + subscribed[i].type + " (" + subscribed[i].entitlement + ")");
92
- }
93
-
94
- // Retrieve available number of symbols and connections, number of currently open connections and subscribed symbols.
95
- stream.getSessionStats();
96
-
97
- setTimeout(function() {
98
- // Unsubscribe for symbols and data types.
99
- // These can be either single strings or arrays of strings.
100
- // An optional options object can also be passed in. Current available options include:
101
- // - conflation: Override default connection conflation, default to null. Should match a subscribe conflation.
102
- stream.unsubscribe(["GOOG"], [Streamer.dataTypes.PRICEDATA], {}, then(function(result) {
103
- // The unsubscription result will include the unsubscriptions.
104
- var unsubscribed = result.unsubscribed;
105
- for (var i = 0; i < unsubscribed.length; ++i) {
106
- print("Unsubscribed: " + unsubscribed[i].symbol + " - " + unsubscribed[i].type);
107
- }
108
-
109
- // Finally, close the stream.
110
- //stream.close(then(function(){
111
- //
112
- //}));
113
- }));
114
- }, 5000);
115
- }));
116
-
117
-
118
- /**
119
- * Subscription to an exchange to receive stock status messages containing data such as halt,
120
- * resume, regSHO.
121
- * ************** NOTE: **************
122
- * The stock status by exchange feature in the streaming datafeed api is considered a premium service
123
- * that requires additional entitlements for clients to have access to the service and helps active traders
124
- * to monitor the market. If you are entitled to this premium service and you want exchange data,
125
- * you can uncomment the code below.
126
- *
127
- * Please inquire about your account if you need further information in this regard.
128
- * @see https://quotemediasupport.freshdesk.com/support/solutions/articles/13000088921-exchange-level-subscriptions-only-stock-status-halt-regsho-is-supported
129
- * ***********************************
130
- *
131
- * An optional options object can also be passed in. Current available options include:
132
- * - conflation: Override default connection conflation, default to null.
133
- */
134
-
135
- // stream.subscribeExchange("NYE", then(function(result) {
136
- // print("Subscribed Exchange: " + result.exchange);
137
-
138
- // setTimeout(function() {
139
- // // Unsubscribe from the exchange.
140
- // // An optional options object can also be passed in. Current available options include:
141
- // // - conflation: Override default connection conflation, default to null. Should match a subscribe conflation.
142
- // stream.unsubscribeExchange("NYE", then(function(result) {
143
- // print("Unsubscribed Exchange: " + result.exchange);
144
-
145
- // // Finally, close the stream.
146
- // stream.close(then(function() {
147
-
148
- // }));
149
- // }));
150
- // }, 5000);
151
- // }));
152
- }));
153
-
154
-
155
- function print(msg, color) {
156
- var el = document.createElement("div");
157
- el.innerText = msg;
158
- if (color) {
159
- el.style.color = color;
160
- }
161
- document.body.appendChild(el);
162
- }
163
-
164
- function then(onSuccess) {
165
- return function(err, result) {
166
- if (err) {
167
- print(err, "red");
168
- } else {
169
- onSuccess(result);
170
- }
171
- }
172
- }
173
- };
174
- </script>
175
- </body>
176
-
177
- </html>