blob: ba53bb6e903679aed4ea0cc5c30942ad994e8445 (
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>{{ title }}</title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function() {
var client_id = Math.random().toString(36).substring(7);
function show_message(msg){
$('#messages').prepend('<p>' + msg + '<p>');
}
var ws = new WebSocket('ws://127.0.0.1:9000/orders');
ws.onopen = function() {
show_message('B⃦ Connected.');
}
ws.onmessage = function(event) {
show_message('B⃦ ' + event.data);
}
ws.onclose = function() {
show_message('B⃦ Closed.');
}
$('#order-submit').click(function() {
console.log('presub');
var type = $('input:radio[name=type]:checked').val();
var price = $('#order-price').val();
var amount = $('#order-amount').val();
var order = client_id + '|' + type + '|' + price + '|' + amount
ws.send(order);
console.log('postsub');
return false;
});
});
</script>
</head>
<body>
<h1>{{ title }}</h1>
<h2>Order</h2>
<p>
<form id="order-form">
<input id="order-bid" type="radio" name="type" value="bid">Buy (bid)</input>
<input id="order-ask" type="radio" name="type" value="ask">Sell (ask)</input>
<input id="order-price" name="price" placeholder="Price" value=""/>
<input id="order-amount" name="amount" placeholder="Amount" value=""/>
<input id="order-submit" type="submit" value="Send Order"/>
</p>
<h2>Messages</h2>
<div id="messages"></div>
</body>
</html>
|