-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcryptoPublisher.html
More file actions
62 lines (54 loc) · 1.33 KB
/
cryptoPublisher.html
File metadata and controls
62 lines (54 loc) · 1.33 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<html>
<head>
<title>Crypto Publisher</title>
<script src="https://cdn.pubnub.com/sdk/javascript/pubnub.4.18.0.min.js"></script>
</head>
<body>
<script type="text/javascript">
var pubnub = new PubNub({
publishKey: 'YOUR_KEYS_HERE',
subscribeKey: 'YOUR_KEYS_HERE'
});
var xhr = new XMLHttpRequest();
function processRequest(e) {
if (xhr.readyState == 4 && xhr.status == 200) {
var response = JSON.parse(xhr.responseText);
console.log(response);
pubnub.publish({
channel: 'bitcoin-feed',
message: {
eon: {
'BitCoin': response.BTC.USD.toFixed(2)
}
}
});
pubnub.publish({
channel: 'ether-feed',
message: {
eon: {
'Ether': response.ETH.USD.toFixed(2)
}
}
});
pubnub.publish({
channel: 'litecoin-feed',
message: {
eon: {
'LiteCoin': response.LTC.USD.toFixed(2)
}
}
});
}
}
function mainApp() {
setInterval(function(){
xhr.open('GET', 'https://min-api.cryptocompare.com/data/pricemulti?fsyms=BTC,ETH,LTC&tsyms=USD', true)
xhr.send();
xhr.onreadystatechange = processRequest;
}, 10000)
};
mainApp();
</script>
</body>
</html>