# How to use backtrader with alpaca live streaming data?

**URL:** <https://forum.alpaca.markets/t/how-to-use-backtrader-with-alpaca-live-streaming-data/2620>\
**Category:** Tutorial Requests\
**Created:** [September 12, 2020, 4:54am UTC](https://forum.alpaca.markets/t/how-to-use-backtrader-with-alpaca-live-streaming-data/2620 "2020-09-12T04:54:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![algilama](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/algilama/32/1237_2.png) [@algilama](https://forum.alpaca.markets/u/algilama)\
**Post date:** [September 12, 2020, 4:54am UTC](https://forum.alpaca.markets/t/how-to-use-backtrader-with-alpaca-live-streaming-data/2620/1 "2020-09-12T04:54:06Z")

</div>

Is there any documentation on how to use Alpaca live streaming data with Backtrader?

These results didn’t help,

> [@Alpaca + Backtrader + Live Feed](https://forum.alpaca.markets/t/alpaca-backtrader-live-feed/1398/3):
>
> Hi, first let’s upgrade the alpaca-backtrader-api version: pip install -U alpaca-backtrader-api then, you have example code here: make sure you change the API keys to your own. if that’s still does not work - let me know

> [@Live feed alpaca-backtrader-api - KeyError: 'bidprice'](https://forum.alpaca.markets/t/live-feed-alpaca-backtrader-api-keyerror-bidprice/1402):
>
> When stock is hold by exchange or sometimes after overnight I see that type of error. How I can catch this? File "/home/x777/anaconda3/envs/env\_backtrader/lib/python3.6/site-packages/backtrader/cerebro.py", line 1130, in run runstrat = self.runstrategies(iterstrat) File "/home/x777/anaconda3/envs/env\_backtrader/lib/python3.6/site-packages/backtrader/cerebro.py", line 1301, in runstrategies self.\_runnext(runstrats) File "/home/x777/anaconda3/envs/env\_backtrader/lib/python3.6/site-p…

---

<div class="post-metadata">

**Author:** ![Shlomik](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/shlomik/32/793_2.png) [@Shlomik](https://forum.alpaca.markets/u/Shlomik)\
**Post date:** [September 14, 2020, 12:25pm UTC](https://forum.alpaca.markets/t/how-to-use-backtrader-with-alpaca-live-streaming-data/2620/2 "2020-09-14T12:25:34Z")

</div>

Hi,  
inside the repository of the project you have example files you could use to start with. for example: [https://github.com/alpacahq/alpaca-backtrader-api/blob/master/sample/strategy\_sma\_crossover.py](https://github.com/alpacahq/alpaca-backtrader-api/blob/master/sample/strategy_sma_crossover.py)

---

<div class="post-metadata">

**Author:** ![ealgoo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/ealgoo/32/1381_2.png) [@ealgoo](https://forum.alpaca.markets/u/ealgoo)\
**Post date:** [October 7, 2020, 8:18pm UTC](https://forum.alpaca.markets/t/how-to-use-backtrader-with-alpaca-live-streaming-data/2620/3 "2020-10-07T20:18:55Z")

</div>

I ran those samples file in live mode (after setting up the API keys and funded my account)

But sample code didn’t generate verbous enough output to show whether the algorithm is working as intended. I am only seeing starting account value and one trading info in another page in alpaca.market webpage.

Is there a way to check more verbously whether the algorithm is working?

---

<div class="post-metadata">

**Author:** ![Shlomik](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/shlomik/32/793_2.png) [@Shlomik](https://forum.alpaca.markets/u/Shlomik)\
**Post date:** [October 12, 2020, 6:21am UTC](https://forum.alpaca.markets/t/how-to-use-backtrader-with-alpaca-live-streaming-data/2620/4 "2020-10-12T06:21:53Z")

</div>

Hi,  
you shouldn’t use the sample code in live trading. these are not profitable strategies, they are samples to base your code on.  
you could run them in paper mode, so you will not lose real money.

you could add logs/prints in different locations of the script to make it more verbose

---

<div class="post-metadata">

**Author:** ![skumwt](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@skumwt](https://forum.alpaca.markets/u/skumwt)\
**Post date:** [November 20, 2022, 1:36pm UTC](https://forum.alpaca.markets/t/how-to-use-backtrader-with-alpaca-live-streaming-data/2620/5 "2022-11-20T13:36:37Z")

</div>

I tried the above GitHub strategy in paper trading. I am getting output  
subscribed to trades: , quotes: , bars: [‘AMZN’], dailyBars: , statuses: , lulds: , cancelErrors: , corrections:

But there are not trades happening when I see in the Alpaca UI. Does the above line make sure that the tades should happen?

Also will the above code work for the BTC?
