Hello all,
I am utilizing the Alpaca-py SDK “Subscribe_Trades” to get a stream of trades for a symbol. The below code works as long as I put in only one ticker like “SPY”. But as soon as I try to put in multiple symbols into the second argument for subscribe_trades in the form of a list or tuple, I get an “error: invalid syntax (400)” error. Github for the SDK is unclear as it says “symbols:str" and 'List of ticker symbols to subscribe to. "” for everything.’ (copied below).
My question is, what is the correct format that I should be entering in for multiple symbols here?
Thank you,
GitHub:
def subscribe_trades(
self, handler: Callable[[Union[Trade, Dict]], Awaitable[None]], *symbols: str
) → None:
“”"Subscribe to trades.Args: handler (Callable[[Union[Trade, Dict]], Awaitable[None]]): The coroutine callback function to handle the incoming data. *symbols: List of ticker symbols to subscribe to. "*" for everything. """ self._subscribe(handler, symbols, self._handlers["trades"])
Working Code Example:
from alpaca.data.live import StockDataStream
stream = StockDataStream(api_key, secret_key)
async def handle_trades(data):
print(data)stream.subscribe_trades(handle_trades, “SPY”)
stream.run()
Failing Code Example
from alpaca.data.live import StockDataStream
stream = StockDataStream(api_key, secret_key)
async def handle_trades(data):
print(data)stream.subscribe_trades(handle_trades, [“SPY”,“QQQ”])
stream.run()