From 87c9d913d6f1a8c4ee7e2bc8b502c2e666f54dd6 Mon Sep 17 00:00:00 2001 From: fawce Date: Mon, 19 Mar 2012 16:08:53 -0400 Subject: [PATCH] working on elminating the need for signaling order done. --- zipline/component.py | 7 +++++++ zipline/lines.py | 4 +--- zipline/messaging.py | 4 ++++ zipline/test/client.py | 17 +++++++++-------- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/zipline/component.py b/zipline/component.py index db9b7bc8..119138e3 100644 --- a/zipline/component.py +++ b/zipline/component.py @@ -448,6 +448,13 @@ class Component(object): """ raise NotImplementedError + + @property + def is_blocking(self): + """ + True if a zipline be held open for this component. + """ + return False @property def get_pure(self): diff --git a/zipline/lines.py b/zipline/lines.py index 93356154..58e7eed7 100644 --- a/zipline/lines.py +++ b/zipline/lines.py @@ -170,15 +170,13 @@ class SimulatedTrading(object): self.started = False ################################################################## - #TODO: the next three lines of code need refactoring from RealDiehl + #TODO: the next two lines of code need refactoring from RealDiehl ################################################################## #wire up a callback inside the algorithm to receive frames from the #trading client self.trading_client.add_event_callback(self.algorithm.handle_frame) #register the trading_client's order method with the algorithm self.algorithm.set_order(self.trading_client.order) - #register the algorithm to signal order's are done - self.algorithm.set_done(self.trading_client.signal_order_done) def add_source(self, source): assert isinstance(source, zmsg.DataSource) diff --git a/zipline/messaging.py b/zipline/messaging.py index 5d3e5fd0..921daafb 100644 --- a/zipline/messaging.py +++ b/zipline/messaging.py @@ -550,6 +550,10 @@ class DataSource(Component): @property def get_id(self): return self.id + + @property + def is_blocking(self): + return True @property def get_type(self): diff --git a/zipline/test/client.py b/zipline/test/client.py index 7cad8a6f..74c556f7 100644 --- a/zipline/test/client.py +++ b/zipline/test/client.py @@ -94,13 +94,9 @@ class TestAlgorithm(): self.incr = 0 self.done = False self.order = None - self.on_done = None def set_order(self, order_callable): self.order = order_callable - - def set_done(self, done_callable): - self.on_done = done_callable def handle_frame(self, frame): for dt, s in frame.iteritems(): @@ -111,7 +107,12 @@ class TestAlgorithm(): if self.incr < self.count: self.order(self.sid, self.amount) self.incr += 1 - elif not self.done: - if self.on_done: - self.on_done() - self.done = True + +class NoopAlgorithm(object): + + def set_order(self, order_callable): + pass + + def handle_frame(self, frame): + pass + \ No newline at end of file