From 00c2ccfe72c345809e980ec990ea1b0465f64092 Mon Sep 17 00:00:00 2001 From: fawce Date: Wed, 29 Feb 2012 17:18:17 -0500 Subject: [PATCH] using an enum for finance protocol constants --- zipline/finance/trading.py | 10 +++++----- zipline/protocol.py | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/zipline/finance/trading.py b/zipline/finance/trading.py index ee13d432..e3a97e53 100644 --- a/zipline/finance/trading.py +++ b/zipline/finance/trading.py @@ -71,12 +71,12 @@ class OrderDataSource(qmsg.DataSource): 'volume' : integer for volume } """ - zm.DataSource.__init__(self, "ORDER_SIM") + zm.DataSource.__init__(self, str(zp.FINANCE_PROTOCOL.ORDER)) self.simulation_dt = simulation_dt self.last_iteration_duration = datetime.timedelta(seconds=0) def get_type(self): - return 'ORDER_SIM' + return str(zp.FINANCE_PROTOCOL.ORDER) def open(self): qmsg.DataSource.open(self) @@ -88,7 +88,7 @@ class OrderDataSource(qmsg.DataSource): def do_work(self): #mark the start time for client's processing of this event. self.event_start = datetime.datetime.utcnow() - self.result_socket.send(zp.TRANSFORM_FRAME('ORDER_SIM', self.simulation_dt), self.zmq.NOBLOCK) + self.result_socket.send(zp.TRANSFORM_FRAME(str(zp.FINANCE_PROTOCOL.ORDER), self.simulation_dt), self.zmq.NOBLOCK) self.simulation_dt = self.simulation_dt + self.last_iteration_duration @@ -139,10 +139,10 @@ class TransactionSimulator(qmsg.BaseTransform): Pulls one message from the event feed, then loops on orders until client sends DONE message. """ - if(event.type == "ORDER_SIM"): + if(event.type == zp.FINANCE_PROTOCOL.ORDER): self.add_open_order(event.sid, event.amount) self.state['value'] = self.average - elif(event.type == "EQUITY_TRADE"): + elif(event.type == zp.FINANCE_PROTOCOL.TRADE): txn = apply_trade_to_open_orders(event) self.state['value'] = txn diff --git a/zipline/protocol.py b/zipline/protocol.py index dc3fb408..22ca9712 100644 --- a/zipline/protocol.py +++ b/zipline/protocol.py @@ -429,7 +429,7 @@ def UNPACK_DATE(payload): FINANCE_PROTOCOL = Enum( - 'ORDER' , # 0 - req - 'TRANSACTION' , # 1 - req - 'STATUS' , # 2 - req + 'ORDER' , # 0 + 'TRANSACTION' , # 1 + 'TRADE' , # 2 )