From 27a1f8b8755aadcf63906005f297ff8b9b0678f9 Mon Sep 17 00:00:00 2001
From: Yuval Adam
Date: Sun, 10 Mar 2013 13:48:35 +0200
Subject: Send entire order messages
---
bitrade.py | 12 +++++++++++-
index.html | 20 ++++++++++++++++----
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 @@
@@ -34,8 +42,12 @@
{{ title }}
Order
-
-
+
Messages
--
cgit v1.3.1