Hello,
I am attempting to subscribe to a stream, but unable to get this to work. Does anyone know suggested fixes? I have 2 different types of errors:
-
When I run it without the “trade_info” function, I get the following repetitive error:
ERROR:root:error while consuming ws messages: As of 3.10, the loop parameter was removed from Lock() since it is no longer necessary -
When I run it with the “trade_info” function, I get the following repetitive error:
ERROR:root:error while consuming ws messages: unknown channel trade_info (you may need to specify the right data_stream)
import alpaca_trade_api as tradeapi
import config as cfg
import threading#instantiate REST API
api = tradeapi.REST(cfg.API_KEY, cfg.SECRET_KEY, base_url=cfg.BASE_URL, api_version=‘v2’)#obtain account information
account = api.get_account()
print(account)ws_url = ‘wss://data.alpaca.markets’
conn = tradeapi.stream2.StreamConn(cfg.API_KEY, cfg.SECRET_KEY, base_url=cfg.BASE_URL,
data_url=ws_url, data_stream=‘alpacadatav1’)@conn.on(r’^account_updates$')
async def on_account_updates(conn, channel, account):
print(‘account’, account)@conn.on(r’^trade_updates$')
async def on_trade_updates(conn, channel, trade):
print(‘trade’, trade)@conn.on(r’^T.AAPL$')
async def trade_info(conn, channel, bar):
print(‘bars’, bar)
#print(bar._raw)
print(bar.price)def ws_start():
conn.run([‘account_updates’, ‘trade_updates’])#start WebSocket in a thread
ws_thread = threading.Thread(target=ws_start, daemon=True)
ws_thread.start()