alpacahq / alpaca-py

The Official Python SDK for Alpaca API
https://alpaca.markets/sdks/python/getting_started.html
Apache License 2.0
602 stars 147 forks source link

[Bug]: WebSocket data streaming sudden failure, got an unexpected keyword argument 'extra_headers' #527

Closed MarcusMadumo closed 1 week ago

MarcusMadumo commented 1 week ago

Is there an existing issue for this?

Current Behavior

Here are the error logs, Note this was streaming fine until I check my container instance logs with several of this error logs with no change to the source code. Please help.

TypeError: BaseEventLoop.create_connection() got an unexpected keyword argument 'extra_headers'
error during websocket communication: BaseEventLoop.create_connection() got an unexpected keyword argument 'extra_headers'
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/alpaca/data/live/websocket.py", line 342, in _run_forever
    await self._start_ws()
  File "/usr/local/lib/python3.11/site-packages/alpaca/data/live/websocket.py", line 133, in _start_ws
    await self._connect()
  File "/usr/local/lib/python3.11/site-packages/alpaca/data/live/websocket.py", line 97, in _connect
    self._ws = await websockets.connect(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/websockets/asyncio/client.py", line 441, in __await_impl__
    self.connection = await self.create_connection()
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/websockets/asyncio/client.py", line 367, in create_connection
    _, connection = await loop.create_connection(factory, **kwargs)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: BaseEventLoop.create_connection() got an unexpected keyword argument 'extra_headers' ```

### Expected Behavior

Data streaming according to the docs

```PYTHON
from alpaca.trading.stream import TradingStream

trading_stream = TradingStream('api-key', 'secret-key', paper=True)

async def update_handler(data):
    # trade updates will arrive in our async handler
    print(data)

# subscribe to trade updates and supply the handler as a parameter
trading_stream.subscribe_trade_updates(update_handler)

# start our websocket streaming
trading_stream.run()```

### SDK Version I encountered this issue in

latest version

### Steps To Reproduce

```markdown
from alpaca.trading.stream import TradingStream

trading_stream = TradingStream('api-key', 'secret-key', paper=True)

async def update_handler(data):
    # trade updates will arrive in our async handler
    print(data)

# subscribe to trade updates and supply the handler as a parameter
trading_stream.subscribe_trade_updates(update_handler)

# start our websocket streaming
trading_stream.run()

Filled out the Steps to Reproduce section?

Anything else?

No response

MarcusMadumo commented 1 week ago

It may be my source code. apologies