blob: 91a10b24a5c1264ee185ef944d47745091db50ab (
plain)
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
|
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>BTC Ticker</title>
<style>
body {
font-family: monospace;
}
</style>
<script>
const socket = new WebSocket("wss://stream.binance.com:9443/stream");
socket.onopen = () => {
socket.send(JSON.stringify({
"method": "SUBSCRIBE",
"params": ["btcusdt@trade"],
"id": 1
}));
};
socket.onmessage = (event) => {
const data = JSON.parse(event.data);
if (data.data !== undefined) {
const d = data.data;
const price = d.p;
const priceElement = document.querySelector("#price");
priceElement.innerText = price;
}
};
</script>
</head>
<body>
<p id="price"></p>
</body>
</html>
|