For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
"sleep 3 seconds and retrying.." warning when connecting to Alpaca paper account and not hitting limit
-
Algo runs fine when during backtest (is_live=False in code below), but get the warning
WARNING:alpaca_trade_api.rest:sleep 3 seconds and retrying https://paper-api.alpaca.markets/v2/account 3 more time(s)...
when trying to run algo on Alpaca paper account during live trading hours (is_live=True). I don't think I'm hitting anywhere near the limit of 200 requests/min for Alpaca. Read through the following 2 threads and solutions didn't help:
- https://community.backtrader.com/topic/2693/timeframe-days-works-but-timeframe-minutes-doesn-t/20?page=1
- https://forum.alpaca.markets/t/lagging-and-dropping-connections/714
import alpaca_backtrader_api import backtrader as bt import pandas as pd from datetime import datetime from alpaca_strategies import MAcrossover from dotenv import load_dotenv import os load_dotenv() stock = 'AAPL' is_live = True api_key = os.getenv('API_KEY_ID') api_secret = os.getenv('API_SECRET') alpaca_paper = os.getenv('ALPACA_PAPER') cerebro = bt.Cerebro() cerebro.addstrategy(MAcrossover) cerebro.addsizer(bt.sizers.SizerFix, stake=10) store = alpaca_backtrader_api.AlpacaStore( key_id=api_key, secret_key=api_secret, paper=alpaca_paper ) DataFactory = store.getdata # or use alpaca_backtrader_api.AlpacaData if is_live: broker = store.getbroker() cerebro.setbroker(broker) data0 = DataFactory( dataname=stock, timeframe=bt.TimeFrame.TFrame("Minutes"), ) else: cerebro.broker.setcash(27000) cerebro.broker.setcommission(commission=0.0) data0 = DataFactory( dataname=stock, timeframe=bt.TimeFrame.TFrame("Minutes"), fromdate=pd.Timestamp('2021-01-13'), todate=pd.Timestamp('2021-01-14'), historical=True) cerebro.adddata(data0) start_portfolio_value = cerebro.broker.getvalue() print('Starting Portfolio Value: %.2f' % start_portfolio_value) cerebro.run() end_portfolio_value = cerebro.broker.getvalue() pnl = end_portfolio_value - start_portfolio_value print('Final Portfolio Value: %.2f' % end_portfolio_value) print(f'PnL: {pnl:.2f}') cerebro.plot()
Can also show code for strategy if that helps--I'm still learning and it's from a tutorial. Want to check if the front end has any errors first.