Skip to content

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

@frenchthibaut

Description

@frenchthibaut

Is there an existing issue for this?

  • 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?

  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions