forked from karthik947/Visualize-Orderbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.html
More file actions
89 lines (74 loc) · 2.91 KB
/
demo.html
File metadata and controls
89 lines (74 loc) · 2.91 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<html>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.6/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<body>
<div class="container">
<div class="row">
<h1>Visualize Orderbook</h1>
</div>
<div class="row">
<input id="symbol" type="text" class="col-sm-2" placeholder="Symbol" value="BTCUSDT">
</div>
<div class="row">
<div class="col-sm-12" id="chartContainer1" style="height: 400px;width: 100%"></div>
</div>
<div class="row">
<div class="col-sm-12" id="chartContainer2" style="height: 400px;width: 100%"></div>
</div>
</div>
</body>
<script>
setInterval(orderBook,1000);
function orderBook(){
var ourRequest = new XMLHttpRequest();
ourRequest.open('GET','https://api.binance.com/api/v1/depth?symbol=' + document.getElementById("symbol").value + '&limit=5',true);
ourRequest.onload = function(){
ourData = JSON.parse(ourRequest.responseText);
//console.log(ourData);
var xAsk=[],yAsk=[],xBid=[],yBid=[];
//Collect Data for Asks
for(i=0;i<5;i++){
xAsk.push(parseFloat(ourData["asks"][i][1]));
yAsk.push((ourData["asks"][i][0]*1).toString() + '_');
}
//Collect Data for Bids
for(i=4;i>=0;i--){
xBid.push(parseFloat(ourData["bids"][i][1]));
yBid.push((ourData["bids"][i][0]*1).toString() + '_');
}
//Display Chart for Asks
var data1 = [{
type: 'bar',
x: xAsk,
y: yAsk,
marker: {
color: 'rgb(160, 9, 9)',
},
orientation: 'h'
}];
var layout1 = {
title: "Asks"
}
Plotly.newPlot('chartContainer1', data1,layout1);
//Display Chart for Bids
var data2 = [{
type: 'bar',
x: xBid,
y: yBid,
marker: {
color: 'rgb(3, 119, 73)'
},
orientation: 'h'
}];
var layout2 = {
title: "Bids"
}
Plotly.newPlot('chartContainer2', data2, layout2);
}
ourRequest.send();
}
</script>
</html>