From 433170df9bcb1e8f51fa26418a94e0ef53682783 Mon Sep 17 00:00:00 2001 From: fawce Date: Mon, 28 May 2012 21:39:54 -0400 Subject: [PATCH] removed old order protocol cruft. --- tests/test_finance.py | 1 - tests/test_protocol.py | 43 ------------ zipline/components/tradesimulation.py | 3 - zipline/protocol.py | 98 --------------------------- 4 files changed, 145 deletions(-) diff --git a/tests/test_finance.py b/tests/test_finance.py index 3676bea9..bbceac25 100644 --- a/tests/test_finance.py +++ b/tests/test_finance.py @@ -438,7 +438,6 @@ class FinanceTestCase(TestCase): { 'sid' : sid, 'amount' : order_amount * alternator**i, - 'type' : zp.DATASOURCE_TYPE.ORDER, 'dt' : order_date }) diff --git a/tests/test_protocol.py b/tests/test_protocol.py index a61ab246..c90b09dc 100644 --- a/tests/test_protocol.py +++ b/tests/test_protocol.py @@ -75,46 +75,3 @@ class ProtocolTestCase(TestCase): event.delete('helloworld') self.assertEqual(zp.ndict(trade), event) - - @timed(DEFAULT_TIMEOUT) - def test_order_protocol(self): - #client places an order - now = datetime.utcnow().replace(tzinfo=pytz.utc) - order = zp.ndict({ - 'dt':now, - 'sid':133, - 'amount':100 - }) - order_msg = zp.ORDER_FRAME(order) - - #order datasource receives - order = zp.ORDER_UNFRAME(order_msg) - self.assertEqual(order.sid, 133) - self.assertEqual(order.amount, 100) - self.assertEqual(order.dt, now) - - #order datasource datasource frames the order - order_event = zp.ndict({ - "sid" : order.sid, - "amount" : order.amount, - "dt" : order.dt, - "source_id" : zp.FINANCE_COMPONENT.ORDER_SOURCE, - "type" : zp.DATASOURCE_TYPE.ORDER - }) - - - order_ds_msg = zp.DATASOURCE_FRAME(order_event) - - #transaction transform unframes - recovered_order = zp.DATASOURCE_UNFRAME(order_ds_msg) - - self.assertEqual(now, recovered_order.dt) - - #create a transaction from the order - txn = zp.ndict({ - 'sid' : recovered_order.sid, - 'amount' : recovered_order.amount, - 'dt' : recovered_order.dt, - 'price' : 10.0, - 'commission' : 0.50 - }) diff --git a/zipline/components/tradesimulation.py b/zipline/components/tradesimulation.py index 06aa7272..827a8d00 100644 --- a/zipline/components/tradesimulation.py +++ b/zipline/components/tradesimulation.py @@ -150,9 +150,6 @@ class TradeSimulationClient(Component): self.perf.log_order(order) self.txn_sim.add_open_order(order) - def signal_order_done(self): - self.order_socket.send(str(zp.ORDER_PROTOCOL.DONE)) - def queue_event(self, event): if self.event_queue == None: self.event_queue = [] diff --git a/zipline/protocol.py b/zipline/protocol.py index 7828cc06..8ff24389 100644 --- a/zipline/protocol.py +++ b/zipline/protocol.py @@ -246,12 +246,6 @@ def DATASOURCE_FRAME(event): event.source_id, TRADE_FRAME(event) ])) - elif(event.type == DATASOURCE_TYPE.ORDER): - return msgpack.dumps(tuple([ - event.type, - event.source_id, - ORDER_SOURCE_FRAME(event) - ])) else: raise INVALID_DATASOURCE_FRAME(str(event)) @@ -286,8 +280,6 @@ def DATASOURCE_UNFRAME(msg): child_value = ndict({'dt':None}) elif(ds_type == DATASOURCE_TYPE.TRADE): child_value = TRADE_UNFRAME(payload) - elif(ds_type == DATASOURCE_TYPE.ORDER): - child_value = ORDER_SOURCE_UNFRAME(payload) else: raise INVALID_DATASOURCE_FRAME(msg) @@ -395,12 +387,6 @@ def MERGE_UNFRAME(msg): raise INVALID_MERGE_FRAME(msg) -# ----------------------- -# Finance Protocol -# ----------------------- -INVALID_ORDER_FRAME = FrameExceptionFactory('ORDER') -INVALID_TRADE_FRAME = FrameExceptionFactory('TRADE') - # ----------------------- # Trades # ----------------------- @@ -454,83 +440,6 @@ def TRADE_UNFRAME(msg): except ValueError: raise INVALID_TRADE_FRAME(msg) -# ----------------------- -# Orders -# ----------------------- -# - from client to order source - -def ORDER_FRAME(order): - assert isinstance(order.sid, int) - assert isinstance(order.amount, int) #no partial shares... - PACK_DATE(order) - return msgpack.dumps(tuple([ - order.sid, - order.amount, - order.dt - ])) - - -def ORDER_UNFRAME(msg): - try: - sid, amount, dt = msgpack.loads(msg) - assert isinstance(sid, int) - assert isinstance(amount, int) - rval = ndict({ - 'sid':sid, - 'amount':amount, - 'dt':dt - }) - UNPACK_DATE(rval) - return rval - except TypeError: - raise INVALID_ORDER_FRAME(msg) - except ValueError: - raise INVALID_ORDER_FRAME(msg) - -# ----------------------- -# ORDERS -# ----------------------- -# -# - from order source to feed -# - should only be called from inside DATASOURCE_(UN)FRAME - - -def ORDER_SOURCE_FRAME(event): - assert isinstance(event.sid, int) - assert isinstance(event.amount, int) #no partial shares... - assert isinstance(event.source_id, basestring) - assert event.type == DATASOURCE_TYPE.ORDER - PACK_DATE(event) - return msgpack.dumps(tuple([ - event.sid, - event.amount, - event.dt, - event.source_id, - event.type - ])) - - -def ORDER_SOURCE_UNFRAME(msg): - try: - sid, amount, dt, source_id, source_type = msgpack.loads(msg) - event = ndict({ - "sid" : sid, - "amount" : amount, - "dt" : dt, - "source_id" : source_id, - "type" : source_type - }) - assert isinstance(sid, int) - assert isinstance(amount, int) - assert isinstance(source_id, basestring) - assert isinstance(source_type, int) - UNPACK_DATE(event) - return event - except TypeError: - raise INVALID_ORDER_FRAME(msg) - except ValueError: - raise INVALID_ORDER_FRAME(msg) - # ----------------------- # Performance and Risk # ----------------------- @@ -667,16 +576,10 @@ def tuple_to_date(date_tuple): return dt DATASOURCE_TYPE = Enum( - 'ORDER', 'TRADE', 'EMPTY', ) -ORDER_PROTOCOL = Enum( - 'DONE', - 'BREAK', -) - #Transform type needs to be a ndict to facilitate merging. TRANSFORM_TYPE = ndict({ @@ -688,7 +591,6 @@ TRANSFORM_TYPE = ndict({ FINANCE_COMPONENT = namelookup({ 'TRADING_CLIENT' : 'TRADING_CLIENT', 'PORTFOLIO_CLIENT' : 'PORTFOLIO_CLIENT', - 'ORDER_SOURCE' : 'ORDER_SOURCE', })