alpaca-trade-api-python icon indicating copy to clipboard operation
alpaca-trade-api-python copied to clipboard

[Bug]: alpaca-trade-api-python/examples/websockets/v2_example.py --> stream.subscribe_trade_updates Failed to authenticate

Open frenchthibaut opened this issue 3 years ago • 1 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

`import logging import config

from alpaca_trade_api.stream import Stream

log = logging.getLogger(name)

async def print_trade(t): print('trade', t)

async def print_quote(q): if q["x"] == "FTXU": print('quote', q)

async def print_trade_update(tu): print('trade update', tu)

async def print_crypto_trade(t): print('crypto trade', t)

def main(): logging.basicConfig(level=logging.INFO) feed = 'iex' # <- replace to SIP if you have PRO subscription stream = Stream(key_id=config.API_KEY,secret_key=config.SECRET_KEY,data_feed=feed, raw_data=True) stream.subscribe_trade_updates(print_trade_update) stream.subscribe_trades(print_trade, 'AAPL') stream.subscribe_quotes(print_quote, 'IBM') stream.subscribe_crypto_trades(print_crypto_trade, 'ETHUSD') stream.subscribe_crypto_quotes(print_quote, 'ETHUSD')

@stream.on_bar('MSFT')
async def _(bar):
    print('bar', bar)

@stream.on_updated_bar('MSFT')
async def _(bar):
    print('updated bar', bar)

@stream.on_status("*")
async def _(status):
    print('status', status)

@stream.on_luld('AAPL', 'MSFT')
async def _(luld):
    print('LULD', luld)

stream.run()

if name == "main": main() `

Expected Behavior

In the provided example, all functions work as expected but "stream.subscribe_trade_updates". It gives the following error:

INFO:alpaca_trade_api.stream:started trading stream INFO:alpaca_trade_api.stream:starting trading websocket connection ERROR:alpaca_trade_api.stream:error during websocket communication: failed to authenticate

SDK Version I encountered this issue in

alpaca_trade_api version 2.1.0

Steps To Reproduce

run stream.subscribe_trade_updates

Filled out the Steps to Reproduce section?

  • [x] I have entered valid steps to reproduce my issue or have attached a minimally reproducible case in code that shows my issue happening; and understand that without this my issue will be flagged as invalid and closed after 30 days.

Anything else?

No response

frenchthibaut avatar May 07 '22 09:05 frenchthibaut

Have you ever resolved this bug?

AleFestante avatar Jul 10 '22 12:07 AleFestante