From 5f878300a0962a772f5c1044006a5e0b9302bc00 Mon Sep 17 00:00:00 2001 From: fawce Date: Tue, 3 Jul 2012 12:11:22 -0400 Subject: [PATCH] switched from pub/sub to push/pull for merge -> client socket. also purged source_id from the constructors of all datasources. --- tests/test_finance.py | 1 + zipline/components/tradesimulation.py | 1 - zipline/core/host.py | 2 +- zipline/finance/sources.py | 12 +++++------- zipline/lines.py | 2 +- zipline/optimize/factory.py | 2 +- zipline/utils/factory.py | 4 ++-- 7 files changed, 11 insertions(+), 13 deletions(-) diff --git a/tests/test_finance.py b/tests/test_finance.py index c208b2c5..52807b6d 100644 --- a/tests/test_finance.py +++ b/tests/test_finance.py @@ -210,6 +210,7 @@ class FinanceTestCase(TestCase): "The merge should be drained of all messages, found {n} remaining." \ .format(n=zipline.sim.merge.pending_messages()) ) + self.assertEqual( zipline.algorithm.count, zipline.algorithm.incr, diff --git a/zipline/components/tradesimulation.py b/zipline/components/tradesimulation.py index fa667a67..f130be0b 100644 --- a/zipline/components/tradesimulation.py +++ b/zipline/components/tradesimulation.py @@ -49,7 +49,6 @@ class TradeSimulationClient(Component): self.perf.open(self.context) def do_work(self): - from rdb import set_trace; set_trace() # poll all the sockets socks = dict(self.poll.poll(self.heartbeat_timeout)) diff --git a/zipline/core/host.py b/zipline/core/host.py index 21b6f2ed..137cd14f 100644 --- a/zipline/core/host.py +++ b/zipline/core/host.py @@ -93,7 +93,7 @@ class ComponentHost(object): self.components[component.get_id] = component if isinstance(component, DataSource): - self.feed.add_source(component.source_id) + self.feed.add_source(component.get_id) if isinstance(component, BaseTransform): self.merge.add_source(component.get_id) diff --git a/zipline/finance/sources.py b/zipline/finance/sources.py index 346e4673..eb7c6e9f 100644 --- a/zipline/finance/sources.py +++ b/zipline/finance/sources.py @@ -25,9 +25,9 @@ class TradeDataSource(DataSource): self.source_id = source_id self.setup_source() - @property - def get_id(self): - return 'TradeDataSource' + #@property + #def get_id(self): + # return 'TradeDataSource' def send(self, event): """ @@ -56,8 +56,7 @@ class RandomEquityTrades(TradeDataSource): Generates a random stream of trades for testing. """ - def init(self, sid, source_id, count): - self.source_id = source_id + def init(self, sid, count): self.count = count self.incr = 0 self.sid = sid @@ -95,7 +94,7 @@ class SpecificEquityTrades(TradeDataSource): Generates a random stream of trades for testing. """ - def init(self, source_id, event_list): + def init(self, event_list): """ :param event_list: should be a chronologically ordered list of dictionaries in the following form:: @@ -107,7 +106,6 @@ class SpecificEquityTrades(TradeDataSource): 'volume' : integer for volume } """ - self.source_id = source_id self.event_list = event_list self.count = 0 diff --git a/zipline/lines.py b/zipline/lines.py index 7672213d..d49ede76 100644 --- a/zipline/lines.py +++ b/zipline/lines.py @@ -279,7 +279,7 @@ class SimulatedTrading(object): self.sim.register_components([source]) # ``id`` is name of source_id, ``get_id`` is the class name - self.sources[source.source_id] = source + self.sources[source.get_id] = source def add_transform(self, transform): assert isinstance(transform, BaseTransform) diff --git a/zipline/optimize/factory.py b/zipline/optimize/factory.py index d9776a9c..4aa9abfb 100644 --- a/zipline/optimize/factory.py +++ b/zipline/optimize/factory.py @@ -65,7 +65,7 @@ def create_updown_trade_source(sid, trade_count, trading_environment, base_price trading_environment.period_end = cur - source = SpecificEquityTrades("updown_" + str(sid), events) + source = SpecificEquityTrades(events) return source diff --git a/zipline/utils/factory.py b/zipline/utils/factory.py index b979849f..6101c3b2 100644 --- a/zipline/utils/factory.py +++ b/zipline/utils/factory.py @@ -171,7 +171,7 @@ def create_returns_from_list(returns, trading_calendar): def create_random_trade_source(sid, trade_count, trading_environment): # create the source - source = RandomEquityTrades(sid, "rand-"+str(sid), trade_count) + source = RandomEquityTrades(sid, trade_count) # make the period_end of trading_environment match cur = trading_environment.first_open @@ -244,5 +244,5 @@ def create_trade_source(sids, trade_count, trade_time_increment, trading_environ #history. trading_environment.period_end = trade_history[-1].dt - source = SpecificEquityTrades("flat", trade_history) + source = SpecificEquityTrades(trade_history) return source