alpacahq / alpaca-backtrader-api

Alpaca Trading API integrated with backtrader
https://pypi.org/project/alpaca-backtrader-api/
Apache License 2.0
621 stars 146 forks source link

Help with Live trading examples and ALPACA_PAPER = False crash #165

Open schwaa opened 3 years ago

schwaa commented 3 years ago

When I run the sample code of the SMACross backtest and use ALPACA_PAPER = True. Everything runs fine. Question 1 - is that actually hitting alpaca? to pull historical data for AAPL from 2015 to now? and show the results?

Then if I change ALPACA_PAPER = False - I get an error, that: AttributeError: 'Account' object has no attribute 'portfolio_value'. Question 2 - Is that expected because the sample just doesn't work with False?

First day using backtrader and just want to see that its working before I try to do anything.
Question 3 - When BT says 'live' trading, it doesn't mean actual money account, it means running on live data in the PAPER account only?

Does BT support trading live, actual money via Alpaca if the code is eventually tested as good, or that is not at all feature? so I should not look for that to be working in any way?

I have another sample script the only runs with ALPACA_PAPER = True and works fine. (I'm seeing a pattern) But when I switch that to False, that one also breaks. It however looks to start a websocket and says access denied: ERROR:root:error while consuming ws messages: Invalid Alpaca API credentials, Failed to authenticate: {'stream': 'authorization', 'data': {'action': 'authenticate', 'message': 'access key verification failed', 'status': 'unauthorized'}}

I know my paper credentials are good, because I use them all the time out of the same config file. Any help is appreciated.

jrhone commented 3 years ago

AttributeError: 'Account' object has no attribute 'portfolio_value'. occurs because we call cerebro.broker.getvalue() before cerebro.run().

If we comment the Starting Portfolio Value line the error goes away.