def getQuoteData(ticker: str): """Get level 1 quotes and trades for ticker for seconds seconds.""" fundamentals = "" quote_conn = iq.QuoteConn(name="pyiqfeed-Example-lvl1") quote_listener = iq.VerboseQuoteListener("Level 1 Listener") quote_conn.add_listener(quote_listener) with iq.ConnConnector([quote_conn]) as connector: all_fields = sorted(list(iq.QuoteConn.quote_msg_map.keys())) quote_conn.select_update_fieldnames( ["Bid", "Bid Time", "Ask", "Ask Time"]) quote_conn.watch(ticker) t_end = time.time() + 5 * 60 while time.time() < t_end: fundamentals = quote_conn.fundamentals summary = quote_conn.summary if (fundamentals != "" and summary != ""): break quote_conn.unwatch(ticker) quote_conn.remove_listener(quote_listener) if (len(summary) > 0): summary = summary[0] if (len(summary) > 0): return fundamentals, summary[0] else: return ""
def get_trades_only(ticker: str, seconds: int): """Get level 1 quotes and trades for ticker for seconds seconds.""" quote_conn = iq.QuoteConn(name="pyiqfeed-Example-trades-only") quote_listener = iq.VerboseQuoteListener("Trades Listener") quote_conn.add_listener(quote_listener) with iq.ConnConnector([quote_conn]) as connector: quote_conn.trades_watch(ticker) time.sleep(seconds) quote_conn.unwatch(ticker)
def get_regional_quotes(ticker: str, seconds: int): """Get level 1 quotes and trades for ticker for seconds seconds.""" quote_conn = iq.QuoteConn(name="pyiqfeed-Example-regional") quote_listener = iq.VerboseQuoteListener("Regional Listener") quote_conn.add_listener(quote_listener) with iq.ConnConnector([quote_conn]) as connector: quote_conn.regional_watch(ticker) time.sleep(seconds) quote_conn.regional_unwatch(ticker)
def get_level_1_quotes_and_trades(ticker: str, seconds: int): """Get level 1 quotes and trades for ticker for seconds seconds.""" quote_conn = iq.QuoteConn(name="pyiqfeed-Example-lvl1") quote_listener = iq.VerboseQuoteListener("Level 1 Listener") quote_conn.add_listener(quote_listener) with iq.ConnConnector([quote_conn]) as connector: all_fields = sorted(list(iq.QuoteConn.quote_msg_map.keys())) quote_conn.select_update_fieldnames(all_fields) quote_conn.watch(ticker) time.sleep(seconds) quote_conn.unwatch(ticker) quote_conn.remove_listener(quote_listener)
def documents(): """Get level 1 quotes and trades for ticker for seconds seconds.""" quote_conn = iq.QuoteConn(name="pyiqfeed-Example-lvl1") quote_listener = iq.VerboseQuoteListener("Level 1 Listener") quote_conn = iq.QuoteConn(name="pyiqfeed-Example-lvl1") quote_conn.add_listener(quote_listener) with iq.ConnConnector([quote_conn]) as connector: all_fields = sorted(list(iq.QuoteConn.quote_msg_map.keys())) quote_conn.select_update_fieldnames(all_fields) quote_conn.watch(ticker) import time time.sleep(seconds)