@quotemedia.com/streamer 2.64.0 → 2.66.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 +136 -33
- package/examples/enduser-example.html +1 -1
- package/examples/enterprise-token-example.html +1 -1
- package/examples/oauth-token-example.html +1 -1
- package/examples/reconnect-example.html +1 -1
- package/examples/stomp-3rd-party-library-example.html +1 -1
- package/examples/streaming-news-example.html +283 -96
- package/examples/subscription-example.html +1 -1
- package/examples/wmid-example.html +1 -1
- package/package.json +1 -1
- package/{qmci-streamer-2.64.0.js → qmci-streamer-2.66.0.js} +594 -234
- package/{qmci-streamer-2.64.0.min.js → qmci-streamer-2.66.0.min.js} +8 -8
package/README.md
CHANGED
|
@@ -1,49 +1,152 @@
|
|
|
1
|
-
#
|
|
1
|
+
# QuoteMedia Streaming Data Service - JavaScript Client
|
|
2
|
+
|
|
2
3
|
JavaScript streaming client that provides easy-to-use client APIs to connect and subscribe to QuoteMedia's market data streaming services.
|
|
3
4
|
|
|
4
5
|
https://quotemedia.com/
|
|
6
|
+
|
|
5
7
|
## Getting Started
|
|
6
|
-
|
|
8
|
+
|
|
9
|
+
The JavaScript streaming client is a library that contains all the necessary dependencies to run in both `browser` and `Node.js` environments.
|
|
7
10
|
|
|
8
11
|
### Browser Usage
|
|
9
|
-
|
|
12
|
+
|
|
13
|
+
Include the library file in your HTML page:
|
|
14
|
+
```html
|
|
15
|
+
<script src="qmci-streamer-2.65.0.min.js"></script>
|
|
16
|
+
<script>
|
|
17
|
+
var Streamer = qmci.Streamer;
|
|
18
|
+
</script>
|
|
19
|
+
```
|
|
10
20
|
|
|
11
21
|
### Node.js Usage
|
|
12
|
-
|
|
13
|
-
|
|
22
|
+
|
|
23
|
+
Since the `window` object is not available in `Node.js`, it will need to be mocked before importing the library:
|
|
24
|
+
|
|
25
|
+
1. Mock the window object:
|
|
14
26
|
```javascript
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
2.
|
|
27
|
+
if (typeof global.window === 'undefined') {
|
|
28
|
+
var window = {
|
|
29
|
+
navigator: { userAgent: "atmosphere.js" },
|
|
30
|
+
document: {},
|
|
31
|
+
location: { protocol: 'https:' },
|
|
32
|
+
JSON: JSON
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
window.WebSocket = require("ws");
|
|
36
|
+
window.EventSource = require("eventsource");
|
|
37
|
+
window.XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
|
|
38
|
+
|
|
39
|
+
global.window = window;
|
|
40
|
+
global.location = window.location;
|
|
41
|
+
global.WebSocket = window.WebSocket;
|
|
42
|
+
global.EventSource = window.EventSource;
|
|
43
|
+
global.navigator = window.navigator;
|
|
44
|
+
global.document = window.document;
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
2. Import the library:
|
|
37
49
|
```javascript
|
|
38
50
|
var Streamer = require("<path to the library>");
|
|
39
51
|
```
|
|
52
|
+
|
|
40
53
|
3. The library is ready for use in your `Node.js` project.
|
|
41
54
|
|
|
55
|
+
## Quick Start
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
var Streamer = qmci.Streamer;
|
|
59
|
+
|
|
60
|
+
// Optional: enable debug logging (may impact performance)
|
|
61
|
+
// Streamer.logger = console;
|
|
62
|
+
|
|
63
|
+
Streamer.login({
|
|
64
|
+
host: 'https://app.quotemedia.com/auth',
|
|
65
|
+
credentials: {
|
|
66
|
+
wmid: 'YOUR_WMID',
|
|
67
|
+
username: 'YOUR_USERNAME',
|
|
68
|
+
password: 'YOUR_PASSWORD'
|
|
69
|
+
}
|
|
70
|
+
}, function(err, sid) {
|
|
71
|
+
if (err) { console.error(err); return; }
|
|
72
|
+
|
|
73
|
+
Streamer.open({
|
|
74
|
+
host: 'https://app.quotemedia.com/cache',
|
|
75
|
+
cors: true,
|
|
76
|
+
format: 'application/json',
|
|
77
|
+
credentials: { sid: sid }
|
|
78
|
+
}, function(err, stream) {
|
|
79
|
+
if (err) { console.error(err); return; }
|
|
80
|
+
|
|
81
|
+
stream.on('message', function(msg) {
|
|
82
|
+
switch (Streamer.marketDataTypes.get(msg)) {
|
|
83
|
+
case Streamer.marketDataTypes.PRICEDATA:
|
|
84
|
+
console.log('Price:', msg.last, msg.change);
|
|
85
|
+
break;
|
|
86
|
+
case Streamer.marketDataTypes.TRADE:
|
|
87
|
+
console.log('Trade:', msg.last, msg.volume);
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
stream.on('error', function(err) {
|
|
93
|
+
console.error('Stream error:', err);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
stream.on('close', function() {
|
|
97
|
+
console.log('Stream closed');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
stream.subscribe(['AAPL', 'MSFT'], ['PRICEDATA', 'TRADE'], function(result) {
|
|
101
|
+
console.log('Subscribed:', result.subscribed);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## API Reference
|
|
108
|
+
|
|
109
|
+
### Stream Methods
|
|
110
|
+
|
|
111
|
+
#### Market Data
|
|
112
|
+
```javascript
|
|
113
|
+
stream.subscribe(symbols, types, [opts], callback)
|
|
114
|
+
stream.unsubscribe(symbols, types, [opts], callback)
|
|
115
|
+
stream.subscribeExchange(exchanges, [opts], callback)
|
|
116
|
+
stream.unsubscribeExchange(exchanges, [opts], callback)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
## Subscription Types
|
|
121
|
+
|
|
122
|
+
Use these with `stream.subscribe()`:
|
|
123
|
+
|
|
124
|
+
`QUOTE` · `PRICEDATA` · `TRADE` · `MMQUOTE` · `ORDERBOOK` · `INTERVAL` · `NETHOUSEPOSITION` · `LASTSALE` · `LIMITUPLIMITDOWN` · `IVGREEKS` · `IMBALANCESTATUS` · `ORDEREXECUTED`
|
|
125
|
+
|
|
126
|
+
> **Note:** `ORDERBOOK` subscription generates `BOOKORDER`, `BOOKDELETE`, `PURGEBOOK`, `PRICELEVEL`, and `MMPRICELEVEL` message types.
|
|
127
|
+
|
|
128
|
+
## Market Data Message Types
|
|
129
|
+
|
|
130
|
+
Use `Streamer.marketDataTypes.get(msg)` to identify incoming messages:
|
|
131
|
+
|
|
132
|
+
`QUOTE` · `PRICEDATA` · `TRADE` · `INTERVAL` · `LASTSALE` · `SYMBOLINFO` · `SYMBOLSTATUS` · `MMQUOTE` · `PRICELEVEL` · `MMPRICELEVEL` · `BOOKORDER` · `BOOKDELETE` · `PURGEBOOK` · `DERIVATIVEINFO` · `LIMITUPLIMITDOWN` · `IVGREEKS` · `IMBALANCESTATUS` · `NETHOUSEPOSITION` · `NEWS` · `ALERT` · `TRADENOTIFICATION` · `DIVIDEND` · `ORDEREXECUTED`
|
|
133
|
+
|
|
134
|
+
## Formatting
|
|
135
|
+
|
|
136
|
+
Use the built-in formatter to produce human-readable message strings:
|
|
137
|
+
```javascript
|
|
138
|
+
var formatter = new Streamer.formatting.Formatter();
|
|
139
|
+
var readable = formatter.fmt(message);
|
|
140
|
+
```
|
|
141
|
+
|
|
42
142
|
## Examples
|
|
43
143
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
-
|
|
47
|
-
-
|
|
48
|
-
-
|
|
49
|
-
-
|
|
144
|
+
The following example HTML files are included in the package:
|
|
145
|
+
|
|
146
|
+
- **enterprise-token-example.html** - Connect and subscribe using enterprise token authentication.
|
|
147
|
+
- **enduser-example.html** - Authenticate with end-user credentials (username/password) and subscribe to market data.
|
|
148
|
+
- **oauth-token-example.html** - Connect and subscribe using OAuth token authentication.
|
|
149
|
+
- **wmid-example.html** - Connect using webmaster ID (IP-based authentication).
|
|
150
|
+
- **subscription-example.html** - Subscribe and unsubscribe to trade data with detailed message handling.
|
|
151
|
+
- **reconnect-example.html** - Configure automatic reconnection on connection loss.
|
|
152
|
+
- **streaming-news-example.html** - Subscribe to news filters and handle incoming news messages.
|