-
Notifications
You must be signed in to change notification settings - Fork 24
/
websocket-example.html
42 lines (41 loc) · 1.3 KB
/
websocket-example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<html>
<body>
Websocket data printed in browser console...
<script src="../../dist/ccxt.browser.js"></script>
<script>
const symbol = 'ETH/BTC';
const event = 'ticker';
const params = {};
const proxy = 'https://cors-anywhere.herokuapp.com/';
const exchange = new ccxt['kucoin']({
enableRateLimit: true,
verbose: true,
timeout: 20000,
proxy: proxy,
// agent: agent
});
exchange.on('err', (err, conxid) => {
try {
console.log(err);
exchange.websocketClose(conxid);
} catch (ex) {
console.log(ex);
}
});
exchange.on(event, (market, data) => {
console.log(event, ' received: ', market, data);
});
exchange.loadMarkets().
then ((response) => {
exchange.websocketSubscribe(event, symbol, params).
then(response => {
console.log("subscribed");
}).catch(ex => {
console.log(ex);
});
}).catch((ex) => {
console.log(ex);
});
</script>
</body>
</html>