I am a paid member using paper trading.
I planned on using the method to retrieve past stock data to calculate the EMAs of various stocks.
So, I ran this function:
def validate_ema9(bar,symbol):
client = StockHistoricalDataClient(api_options.ALPACA_API_KEY,api_options.ALPACA_SECRET_KEY)
bars_request = StockBarsRequest(
symbol_or_symbols=symbol,
timeframe=TimeFrame.Minute,
start=pd.Timestamp.now() - pd.Timedelta(days=20),
end=pd.Timestamp.now()
)
bars = client.get_stock_bars(bars_request).df
bars['EMA9'] = bars['close'].ewm(span=9, adjust=False).mean()
last_ema9 = bars['EMA9'].iloc[-1]
last_bar_timestamp = bars.index[-1]
print(f"Most recent bar timestamp: {last_bar_timestamp}")
return bar['close'] > last_ema9
The problem is the data is 8 hours old… Is there a better way to get past data?