I’m trying to get the data of a stock every second using the A channel. My code is below:
import alpaca_trade_api as tradeapi
base_url = 'https://paper-api.alpaca.markets'
api_key_id = 'your api key id'
api_secret = 'your api secret'
api = tradeapi.REST(
key_id=api_key_id,
secret_key=api_secret,
base_url=base_url,
)
if __name__ == "__main__":
conn = tradeapi.StreamConn(
key_id=api_key_id,
secret_key=api_secret,
base_url=base_url,
)
@conn.on(r'A.AAPL)
async def handle_second_bar(conn, channel, data):
print("second", data)
@conn.on(r'AM.AAPL)
async def on_minute_bars(conn, channel, bars):
print('bars', bars)
conn.run(['A.AAPL', "AM.AAPL"])
I get an error saying ERROR:root:error while consuming ws messages: unknown channel A.* (you may need to specify the right data_stream). The AM channel works and I am getting updates every minute but the A channel doesn’t work. This question has been asked ValueError: unknown channel A.TSLA (you may need to specify the right data_stream) but no solution was provided. How can I fix this issue?