summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bitrade.py13
-rw-r--r--index.html11
2 files changed, 14 insertions, 10 deletions
diff --git a/bitrade.py b/bitrade.py
index 75dc3c5..ee4fd19 100644
--- a/bitrade.py
+++ b/bitrade.py
@@ -1,4 +1,5 @@
# encoding: utf8
+import json
import logging
import os
@@ -16,15 +17,15 @@ c = tornadoredis.Client()
c.connect()
-class Order:
- def __init__(self, msg):
+class Order(object):
+ def __init__(self, data):
self.id = uuid4().hex
self.time = str(int(time() * 1000)) # ms resolution
- self.client, self.type, self.price, self.amount = msg.split('|')
+ for key in data:
+ setattr(self, key, data[key])
def __unicode__(self):
- fields = [self.id, self.time, self.client, self.type, self.price, self.amount]
- return '|'.join(fields)
+ return json.dumps(self.__dict__)
class MainHandler(tornado.web.RequestHandler):
@@ -46,7 +47,7 @@ class OrderHandler(tornado.websocket.WebSocketHandler):
@tornado.gen.engine
def on_message(self, msg):
- order = Order(msg)
+ order = Order(json.loads(msg))
with c.pipeline() as pipe:
order_str = unicode(order)
pipe.zadd('order_log', order.time, order_str)
diff --git a/index.html b/index.html
index ba53bb6..a72baf1 100644
--- a/index.html
+++ b/index.html
@@ -24,13 +24,16 @@
}
$('#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');
+ var order = {
+ type: type,
+ amount: amount,
+ price: price,
+ client: client_id
+ };
+ ws.send(JSON.stringify(order));
return false;
});
});