So, I was wondering if you can subscribe to an option while the OptionDataStream is running. What i mean is that can you run for example, option_data_stream.subscribe_quotes() after you ran the run command. I would like to know how to do this if possible and i can provide code to what i have so far.
Here’s simple example to achieve this:
import logging
import os
import time
import threading
from alpaca.data.live import OptionDataStream
logging.basicConfig(
format="%(asctime)s [%(levelname)s]: %(message)s",
level=logging.INFO,
)
async def handler(msg):
print(msg)
stream = OptionDataStream(
api_key=os.getenv("APCA_API_KEY_ID"), secret_key=os.getenv("APCA_API_SECRET_KEY")
)
thread = threading.Thread(target=stream.run)
thread.start()
logging.info("subscribe to one symbol")
stream.subscribe_quotes(handler, "AAPL241101C00230000")
time.sleep(3)
logging.info("subscribe to another symbol")
stream.subscribe_quotes(handler, "AAPL241101C00235000")
time.sleep(3)
logging.info("unsubscribe")
stream.unsubscribe_quotes("AAPL241101C00230000")