forked from js-sodasu/bitmex-trading-volume
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
191 lines (169 loc) · 5.05 KB
/
index.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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bitmex Trading Volume Viewer</title>
<meta charset="utf-8" />
<script src="jquery-2.2.4.min.js"></script>
<script src="howler.min.js"></script>
<script type="text/javascript">
$(function(){
var t = JSON.parse('{"otherSellSmall":[1330,1221],"otherSellBig":[2550,1183],"otherBuySmall":[3740,1140],"otherBuyBig":[4882,1017],"myLimitOrderExecutedSmall":[5900,2940],"myLimitOrderExecutedBig":[8841,3027],"myLimitOrderExpired":[11868,677]}');
var h = new Howl({
src: ['sound.mp3'],
format: ["mp3"],
sprite: t,
autoplay: !1,
loop: !1,
volume: .5
});
var calcVolume = function(data){
//console.log(data.action,data.data);
var tVolume = 0;
var tPrice = 0.0;
var tSide = null;
var tTimestamp = null;
var dTrade = data.data;
var minVol = parseInt($("#minVol").val());
var maxTradeLength = dTrade.length;
var smallBuy = parseInt($("#smallBuy").val());
var bigBuy = parseInt($("#bigBuy").val());
var smallSell = parseInt($("#smallSell").val());
var bigSell = parseInt($("#bigSell").val());
for(var cntTrade=0;cntTrade<maxTradeLength;cntTrade+=1)
{
var tmpTrade = dTrade[cntTrade];
tVolume += tmpTrade['size'];
tPrice = tmpTrade['price'];
tSide = tmpTrade['side'];
tTimestamp = tmpTrade['timestamp'];
}
//console.log(tTimestamp,tSide,tPrice,tVolume);
if($("#chkSound").is(":checked"))
{
if(tVolume>=smallSell && tSide == 'Sell') h.play('otherSellBig');
else if(tVolume>=smallSell && tVolume < bigSell && tSide == 'Sell') h.play('otherSellSmall');
if(tVolume>=smallBuy && tSide == 'Buy') h.play('otherBuyBig');
else if(tVolume>=smallBuy && tVolume < bigBuy && tSide == 'Buy') h.play('otherBuySmall');
}
if(tVolume < minVol) return;
var tDate = new Date(tTimestamp);
var tTime = tDate.toLocaleString('en-US', { hour: 'numeric', minute: 'numeric', hour12: true });
tVolume = new Intl.NumberFormat('en-US').format(tVolume);
var html = '<tr class="'+tSide+'">';
html += '<td class="t-price">' + tPrice + '</td>';
html += '<td class="t-volume">' + tVolume + '</td>';
html += '<td class="t-timestamp">' + tTime + '</td>';
html += '</tr>';
$('.trading').prepend(html);
};
//
$(document)
.on("click","#smallBuyPlay",function(){
h.play('otherBuySmall');
return false;
})
.on("click","#bigBuyPlay",function(){
h.play('otherBuyBig');
return false;
})
.on("click","#smallSellPlay",function(){
h.play('otherSellSmall');
return false;
})
.on("click","#bigSellPlay",function(){
h.play('otherSellBig');
return false;
});
//
var oSocket = new WebSocket("wss://www.bitmex.com/realtime?subscribe=trade:XBTUSD");
oSocket.onmessage = function (e) {
//console.log(e.data);
var data = JSON.parse(e.data);
if(data.success == false)
oSocket.close(); //failed to connect socket :(
if(data.table=='trade')
calcVolume(data);
else
console.log(data);
};
oSocket.onopen = function (e) {
};
oSocket.onclose = function (e) {
};
oSocket.send('{"op": "subscribe", "args": ["trade:XBTUSD"]}');
});
</script>
<style>
.menu{
font-size:12px;
padding:10px;
}
.menu-cell{
padding:5px;
}
.menu-cell label{
display: inline-block;
width:100px;
}
.trading{
border-collapse: collapse;
width:500px;
color:#fff;
}
.trading tr.Sell td{
background: #ae543b;
}
.trading tr.Buy td{
background: #3e8654;
}
.trading td{
border:1px solid #fff;
padding:10px;
}
.t-price{
text-align:center;
}
.t-volume{
text-align:center;
}
.t-timestamp{
text-align:center;
}
</style>
</head>
<body>
<div class="menu">
<div class="menu-cell">
<label>Min. Volume</label>
<input type="text" id="minVol" value="5000" />
</div>
</div>
<div class="menu">
<div class="menu-cell">
<label>Sound on/off</label>
<input type="checkbox" id="chkSound" checked />
</div>
<div class="menu-cell">
<label>small buy</label>
<input type="text" id="smallBuy" value="70000" />
<a href="#" id="smallBuyPlay">[Play]</a>
</div>
<div class="menu-cell">
<label>big buy</label>
<input type="text" id="bigBuy" value="1000000" />
<a href="#" id="bigBuyPlay">[Play]</a>
</div>
<div class="menu-cell">
<label>small sell</label>
<input type="text" id="smallSell" value="70000" />
<a href="#" id="smallSellPlay">[Play]</a>
</div>
<div class="menu-cell">
<label>big sell</label>
<input type="text" id="bigSell" value="1000000" />
<a href="#" id="bigSellPlay">[Play]</a>
</div>
</div>
<table class="trading"></table>
</body>
</html>