def stream_quotes(): if len(MD_SUBSCRIPTIONS) > 0: md_batch = Stock(MD_SUBSCRIPTIONS, token=IEX_TOKEN) prices = md_batch.get_price() tops = get_tops(MD_SUBSCRIPTIONS) update_md_snaphots(tops) pub = Publisher(pubcfg) pub.publish(prices) logger.info("Publishing prices") logger.info(prices) else: logger.info("No quotes to stream") time.sleep(5) stream_quotes()
def test_TOPS_pandas(self): df = get_tops("AAPL", output_format='pandas') df2 = get_tops(["AAPL", "TSLA"], output_format='pandas') assert isinstance(df, DataFrame) assert isinstance(df2, DataFrame)
def test_TOPS_too_many_symbols(self): with pytest.raises(ValueError): get_tops(self.bad)
def test_TOPS_json_syms(self): ls = get_tops("AAPL") ls2 = get_tops(["AAPL", "TSLA"]) assert isinstance(ls, list) and len(ls) == 1 assert isinstance(ls2, list) and len(ls2) == 2
def test_TOPS_json_default(self): ls = get_tops() assert isinstance(ls, list) and len(ls) > 7500
from iexfinance.stocks import Stock from iexfinance.iexdata import get_tops import json import logging from threading import Thread, Lock import time from common_utils import Logger from common_utils.publisher import Publisher from common_utils.consumer import Consumer from config import * tops = get_tops(["AAPL"]) MD_SUBSCRIPTIONS = [] IEX_TOKEN = "Tpk_36614967265944c6b4b3e47be6b2b3ca" MUTEX = Lock() MD_BOOK = dict() logger = Logger.Logger("market_data").get() logger.setLevel(logging.DEBUG) def on_callback(body): print("Received {}".format(body)) body = json.loads(body) if 'symbol' not in body: logger.error('Unexpected trade with no symbol') else: MUTEX.acquire() MD_SUBSCRIPTIONS.append(body['symbol'])