From b447333fae63a1e117a9bab3dc06f601467061e3 Mon Sep 17 00:00:00 2001 From: scottsanderson Date: Wed, 4 Jul 2012 03:46:42 -0400 Subject: [PATCH] remove logging from initialize for now --- zipline/components/tradesimulation.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/zipline/components/tradesimulation.py b/zipline/components/tradesimulation.py index 87b21e55..4212d458 100644 --- a/zipline/components/tradesimulation.py +++ b/zipline/components/tradesimulation.py @@ -41,6 +41,7 @@ class TradeSimulationClient(Component): return str(zp.FINANCE_COMPONENT.TRADING_CLIENT) def set_algorithm(self, algorithm): + """ :param algorithm: must implement the algorithm protocol. See :py:mod:`zipline.test.algorithm` @@ -49,21 +50,20 @@ class TradeSimulationClient(Component): # register the trading_client's order method with the algorithm self.algorithm.set_order(self.order) - #TODO: re-enable initialization logging - + #TODO: re-enable initialization logging. This means we can't call set_algorithm + #until we have a context for this component. Possibly this could happen # ask the algorithm to initialize, routing stdout to a zmq PUSH socket. - #if self.log_socket: - # with self.zmq_out.threadbound(), \ - # self.stdout_capture(self.logger, 'Algo print capture'): - # self.algorithm.initialize() - - # if we don't have a log socket, initialize anyway. + + #with self.zmq_out.threadbound(), self.stdout_capture(self.logger, 'Algo print capture'): + # self.algorithm.initialize() + #if we don't have a log socket, initialize anyway. #else: # self.algorithm.initialize() self.algorithm.initialize() def open(self): + self.result_feed = self.connect_result() self.perf.open(self.context) @@ -80,12 +80,10 @@ class TradeSimulationClient(Component): self.zmq_out = ZeroMQLogHandler(uri = self.log_socket, context = context) self.logger = Logger("Print") self.stdout_capture = stdout_only_pipe #THIS IS A CLASS! - def do_work(self): # poll all the sockets socks = dict(self.poll.poll(self.heartbeat_timeout)) - # see if the poller has results for the result_feed if socks.get(self.result_feed) == self.zmq.POLLIN: @@ -103,6 +101,7 @@ class TradeSimulationClient(Component): event = zp.MERGE_UNFRAME(msg) self.received_count += 1 # update performance and relay the event to the algorithm + self.process_event(event) if self.perf.exceeded_max_loss: self.finish_simulation() @@ -118,7 +117,6 @@ class TradeSimulationClient(Component): self.signal_done() def process_event(self, event): - # generate transactions, if applicable txn = self.txn_sim.apply_trade_to_open_orders(event) if txn: @@ -143,10 +141,10 @@ class TradeSimulationClient(Component): # queue the event. self.queue_event(event) - # if the event is later than our current time, run the algo # otherwise, the algorithm has fallen behind the feed # and processing per event is longer than time between events. + if event.dt >= self.current_dt: # compress time by moving the current_time up to the event # time. @@ -168,13 +166,13 @@ class TradeSimulationClient(Component): current_portfolio = self.perf.get_portfolio() self.algorithm.set_portfolio(current_portfolio) data = self.get_data() - + if len(data) > 0: # data injection pipeline for log rerouting # any fields injected here should be added to # LOG_EXTRA_FIELDS in zipline/protocol.py - + if self.log_socket: def inject_event_data(record):