summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Adam <yuv.adm@gmail.com>2013-03-10 13:48:35 +0200
committerYuval Adam <yuv.adm@gmail.com>2013-03-10 13:48:35 +0200
commit27a1f8b8755aadcf63906005f297ff8b9b0678f9 (patch)
treefae18f5ed4961b2182c1c36cdc17882db3105d40
parent6b2e0794d3e1786370368ade88b042f96bb0607a (diff)
Send entire order messages
-rw-r--r--bitrade.py12
-rw-r--r--index.html20
2 files changed, 27 insertions, 5 deletions
diff --git a/bitrade.py b/bitrade.py
index 0d72693..9bbd9ba 100644
--- a/bitrade.py
+++ b/bitrade.py
@@ -1,4 +1,5 @@
# encoding: utf8
+import logging
import os
import tornado.httpserver
@@ -8,6 +9,8 @@ import tornado.ioloop
import tornado.gen
import tornadoredis
+from time import time
+from uuid import uuid4
c = tornadoredis.Client()
c.connect()
@@ -30,8 +33,15 @@ class OrderHandler(tornado.websocket.WebSocketHandler):
yield tornado.gen.Task(self.client.subscribe, 'test_channel')
self.client.listen(self.on_order)
+ @tornado.gen.engine
def on_message(self, msg):
- c.publish('test_channel', msg)
+ order_time = time()
+ order_id = uuid4().hex
+ order = '{}|{}'.format(order_id, msg)
+ with c.pipeline() as pipe:
+ pipe.zadd('order_log', order_time, order)
+ pipe.publish('test_channel', order)
+ yield tornado.gen.Task(pipe.execute)
def on_order(self, msg):
if msg.kind == 'message':
diff --git a/index.html b/index.html
index bbc2d6a..ba53bb6 100644
--- a/index.html
+++ b/index.html
@@ -6,6 +6,8 @@
<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>');
}
@@ -21,9 +23,15 @@
show_message('B⃦ Closed.');
}
- $('#order').click(function() {
- var order = $('#order-msg').val();
+ $('#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>
@@ -34,8 +42,12 @@
<h1>{{ title }}</h1>
<h2>Order</h2>
<p>
- <input id="order-msg" value=""/>
- <input id="order" type="submit" value="Send Order"/>
+ <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>