alpaca-backtrader-api: your connection is rejected while another connection is open under the same account

Hey, I am running into an error with multiple data feeds, e.g. with the example https://github.com/alpacahq/alpaca-backtrader-api/blob/master/sample/strategy_multiple_datas.py

Error: alpaca_trade_api\stream2.py", line 52, in _connect raise Exception(f"Error while connecting to {self._endpoint}:" Exception: Error while connecting to wss://data.alpaca.markets/stream:your connection is rejected while another connection is open under the same account


It’s working with one data feed, and I restarted my computer, tried another account, … & the same message appears.

Running Windows 10, Python 3.6

My guess is, that it is related to me not having a “full” account because I’m non-US and the datafeed might only allow one feed per paper account?

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Comments: 18 (6 by maintainers)

Most upvoted comments

Hi Justin it is not related to your account type alpaca-backtrader opens a websocket to each data you add. there’s a branch that I work on to bypass this issue. it is not compelte so I still don’t merge it to the master branch but you may try it out (and give me your feedback) install it like this: pip install -U git+https://github.com/alpacahq/alpaca-backtrader-api@shared_websocket_streamer

Hey @shlomikushchi I fixed it. Wasn’t an issue with alpaca-backtrader. Had to add an environment variable to redirect my requests to the proxy agent.

Thanks

Sorry, it’s my bad, the default IP is not 192.168.99.100. The OS is Ubuntu 16.04.

After connected to the Websocket, it gives the following log:

connected to: ws://172.17.0.2:8765/stream
connected to: ws://172.17.0.2:8765/stream
code = 1000 (OK), no reason
error while consuming ws messages: consume cancelled

It’s not in the regular trading hours when I was testing the code, I guess that’s probably the reason behind the error. Anyway, thanks for the hint!

Hi, you are running more than one ws connections still. this is the error you get. I am now making final modifications to this repo to make it compatible with the alpaca-proxy-agent. you can see the changes here: https://github.com/alpacahq/alpaca-backtrader-api/pull/109

in this readme there’s a section explaining how to use the proxy agent: https://github.com/alpacahq/alpaca-backtrader-api/blob/make_project_compatible_to_proxy_agent/README.md

also make sure you have the correct branch installed ( not yet released to pypi). you can install it like this: pip install git+https://github.com/alpacahq/alpaca-backtrader-api@make_project_compatible_to_proxy_agent

Installing the branch shared_websocket_streamer worked for me running against the samples, although I’ll need to wait for the market to open for a true test.

Perfect! I’ll check it out and let you know!