alpaca-backtrader-api: concurrent.futures._base.CancelledError

Sometime after my live paper trading program reaches data.status of LIVE I get this error.

May 28 11:22:12 sleep 3 seconds and retrying https://paper-api.alpaca.markets/v2/account 3 more time(s)...
May 28 11:22:16 sleep 3 seconds and retrying https://paper-api.alpaca.markets/v2/account 3 more time(s)...
May 28 11:22:16 sleep 3 seconds and retrying https://paper-api.alpaca.markets/v2/account 3 more time(s)...
May 28 11:22:20 Reached LIVE data
May 28 11:41:59 Exception in thread Thread-6:
May 28 11:41:59 Traceback (most recent call last):
May 28 11:41:59   File "/app/.heroku/python/lib/python3.6/threading.py", line 916, in _bootstrap_inner
May 28 11:41:59     self.run()
May 28 11:41:59   File "/app/.heroku/python/lib/python3.6/threading.py", line 864, in run
May 28 11:41:59     self._target(*self._args, **self._kwargs)
May 28 11:41:59   File "/app/.heroku/python/lib/python3.6/site-packages/alpaca_backtrader_api/alpacastore.py", line 483, in _t_streaming_prices
May 28 11:41:59     streamer.run()
May 28 11:41:59   File "/app/.heroku/python/lib/python3.6/site-packages/alpaca_backtrader_api/alpacastore.py", line 132, in run
May 28 11:41:59     self.conn.run(channels)
May 28 11:41:59   File "/app/.heroku/python/lib/python3.6/site-packages/alpaca_trade_api/stream2.py", line 276, in run
May 28 11:41:59     loop.run_until_complete(self.consume())
May 28 11:41:59   File "/app/.heroku/python/lib/python3.6/asyncio/base_events.py", line 488, in run_until_complete
May 28 11:41:59     return future.result()
May 28 11:41:59 concurrent.futures._base.CancelledError
May 28 11:41:59 
May 28 12:08:07 WARNING:root:code = 1006 (connection closed abnormally [internal]), no reason
May 28 12:08:07 Exception in thread Thread-2:
May 28 12:08:07 Traceback (most recent call last):
May 28 12:08:07   File "/app/.heroku/python/lib/python3.6/threading.py", line 916, in _bootstrap_inner
May 28 12:08:07     self.run()
May 28 12:08:07   File "/app/.heroku/python/lib/python3.6/threading.py", line 864, in run
May 28 12:08:07     self._target(*self._args, **self._kwargs)
May 28 12:08:07   File "/app/.heroku/python/lib/python3.6/site-packages/alpaca_backtrader_api/alpacastore.py", line 341, in _t_streaming_events
May 28 12:08:07     streamer.run()
May 28 12:08:07   File "/app/.heroku/python/lib/python3.6/site-packages/alpaca_backtrader_api/alpacastore.py", line 132, in run
May 28 12:08:07     self.conn.run(channels)
May 28 12:08:07   File "/app/.heroku/python/lib/python3.6/site-packages/alpaca_trade_api/stream2.py", line 276, in run
May 28 12:08:07     loop.run_until_complete(self.consume())
May 28 12:08:07   File "/app/.heroku/python/lib/python3.6/asyncio/base_events.py", line 488, in run_until_complete
May 28 12:08:07     return future.result()
May 28 12:08:07 concurrent.futures._base.CancelledError

This code in the strategy logs the switch to LIVE

    def notify_data(self, data, status, *args, **kwargs):
        if status == data.LIVE:
            print("Reached LIVE data")
            self.reached_live_data = True

This error happens eventually every time I run it live.

This occurred when using the latest stable release and using git+https://github.com/alpacahq/alpaca-backtrader-api

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 27 (21 by maintainers)

Most upvoted comments

let’s try something… I’m creating a branch for you with some added resilience to the alpacastore. let’s see if that helps. install it like this: pip install -U git+https://github.com/alpacahq/alpaca-backtrader-api@more_resilience_for_alpacastore

now remember, it’s ok to get the concurrent.futures._base.CancelledError as long as the execution continues.