class TestEquityIndex(object): def setup(self): self.idx = EquityIndex('TEST') def test_repr(self): eq_(self.idx.__repr__(), "<EquityIndex(name='TEST')>") def test_filename(self): eq_(self.idx.filename, 'test_idx.csv') def test_trade_file(self): expected = 'test_trades_HHMM.csv' eq_(self.idx.trade_file('HHMM'), expected) def test_component_tickers(self): expected = ['AAA', 'BBB', 'CCC', 'DDD'] assert_list_equal(self.idx.component_tickers, expected) # tests that the first `Equity` found in the collection/list # is the one expected def test_component_equities(self): equity = self.idx.components()[0] eq_(equity.ticker, 'AAA') # just tests that a dict is returned def test_components_last_px(self): last_prices = self.idx.components_last_px('HHMM') assert_is_instance(last_prices, dict) @raises(Exception) def test_non_exist_index(self): EquityIndex('NOT_THERE')
def zmq_qry_pub(context): """PUB -- queries and PUBLISHES the data """ app.logger.info("zmq_qry_pub started") socket = context.socket(zmq.PUB) socket.connect('tcp://127.0.0.1:7000') timestamps = ['0810', '0811', '0812'] idx = EquityIndex('CAC') # for ts in cycle(timestamps): for ts in timestamps: price_data = idx.components_last_px(ts) for topic, msg_data in price_data.iteritems(): if msg_data: # push the code/ticker into the dict msg_data['ticker'] = topic # reformat with a colon msg_data['ts'] = ts[:2] + ':' + ts[2:] # and jsonify.... msg = json.dumps(msg_data) socket.send(msg) gevent.sleep(WAIT) app.logger.info("zmq_qry_pub closed")
def setup(self): self.idx = EquityIndex('TEST')