TimeFrame.Days works but TimeFrame.Minutes doesn't
-
When I try to paper trade live with any strategy using TimeFrame.Minutes I get:
sleep 3 seconds and retrying https://api.alpaca.markets/v2/account 3 more time(s)...
If I click the link it gives:
{"code":40110000,"message":"access key verification failed : access key not found (Code = 40110000)"}
Tried making new keycodes several times so it's not that...seems to just be when I use Minutes instead of Days.
-
Has anyone else had this problem? Could someone at least try using Minutes instead of Days and lmk what happens? Make sure you do it during market hours though that's when the error comes up.
-
Here is code i have used it and its working perfectly also there resample it
if not alpaca_paper: broker = store.getbroker() # or just alpaca_backtrader_api.AlpacaBroker() cerebro.setbroker(broker) DataFactory = store.getdata # or use alpaca_backtrader_api.AlpacaData data0 = DataFactory( dataname='AAPL', timeframe=bt.TimeFrame.TFrame("Minutes"), fromdate=pd.Timestamp('2018-11-15'), todate=pd.Timestamp('2018-11-17'), historical=True) cerebro.adddata(data0) #Resampler for 15 minutes cerebro.resampledata(data0,timeframe=bt.TimeFrame.Minutes,compression=15)
-
@mudassar031
full code example using alpaca api with TimeFrame.minutes and resample dataimport alpaca_backtrader_api import backtrader as bt import pandas as pd from datetime import datetime from strategies.tos_strategy import TOS from dotenv import load_dotenv import os load_dotenv() api_key = os.getenv('API_KEY_ID') api_secret = os.getenv('API_SECRET') alpaca_paper = os.getenv('ALPACA_PAPER') cerebro = bt.Cerebro() cerebro.addstrategy(TOS) cerebro.broker.setcash(100000) cerebro.broker.setcommission(commission=0.0) cerebro.addsizer(bt.sizers.PercentSizer, percents=20) store = alpaca_backtrader_api.AlpacaStore( key_id=api_key, secret_key=api_secret, paper=alpaca_paper ) if not alpaca_paper: broker = store.getbroker() # or just alpaca_backtrader_api.AlpacaBroker() cerebro.setbroker(broker) DataFactory = store.getdata # or use alpaca_backtrader_api.AlpacaData data0 = DataFactory( dataname='AAPL', timeframe=bt.TimeFrame.TFrame("Minutes"), fromdate=pd.Timestamp('2018-11-15'), todate=pd.Timestamp('2018-11-17'), historical=True) cerebro.adddata(data0) #Resampler for 15 minutes cerebro.resampledata(data0,timeframe=bt.TimeFrame.Minutes,compression=15) print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue()) cerebro.run() print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue()) cerebro.plot()
-
@mudassar031 Thank you! I will try it.
-
@mudassar031 I don't know what resampling is. I don't understand it. I googled it and it made no sense there either. Apparently that's what i'm missing though because I wasn't doing w/e it is lol.
-
@Wayne-Filkins
resample data means if you have minute of data and you want to convert it into 15 minutes period or 30 minutes period etc... -
@mudassar031 Thanks, I was googling it and getting the statistics definition. I get it now :) I have literally done it before when working on machine learning (with stock candle data) just never knew the term for it haha
-
@Wayne-Filkins
haha no worries you are welcome -
@mudassar031 If that's supposed to be run live, why do you have historical=True and fromdate and todate? When I try to run it it just does a backtest.
-
@mudassar031 When I changed historical and got rid of todate it did run without the error though! That's a first for me using minutes.
-
@mudassar031 said in TimeFrame.Days works but TimeFrame.Minutes doesn't:
if not alpaca_paper:
broker = store.getbroker() # or just alpaca_backtrader_api.AlpacaBroker()
cerebro.setbroker(broker)this part confuses me:
if not alpaca_paper: broker = store.getbroker() # or just alpaca_backtrader_api.AlpacaBroker() cerebro.setbroker(broker)
Wouldn't it be if alpaca_paper is True? Because you use Alpaca Broker for live, not backtest right?
I can get it working if I do it this way, but it's not using my Alpaca paper trade account.
-
@Wayne-Filkins
yes right ALPACA_PAPER=True in my case
right now i am using paper trade for back-testing -
@Wayne-Filkins
here is my .env file formatALPACA_PAPER=True API_KEY_ID=xxxxxxxxxxxxxxx API_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxx
-
I'm getting the error when live paper trading (not backtesting)
-
@Wayne-Filkins
What is the error ? -
Original post we are commenting on lol
-
@Wayne-Filkins
i have't tried live trading yet
please check this
https://forum.alpaca.markets/t/lagging-and-dropping-connections/714/4 -
I don't see how i'm exceeding 200 requests per minute. There must be something wrong with this thing. Does no one trade live with it?
-
Nevermind, figured it out. At first I thought it was the date going too far back (for 1-minute data) but then deleted all alpaca stuff from my pc and reinstalled just alpaca-backtrader and now it's working. I think maybe it was somehow using some old keycodes from the alpaca api in a different folder or something...idk really. Got it working though I think!