Rename this here and in `crypto_get_symbol_data` and `get_symbols_data`
Closed this issue · 1 comments
github-actions commented
Rename this here and in crypto_get_symbol_data
and get_symbols_data
LiuAlgoTrader/liualgotrader/data/alpaca.py
Line 275 in 68941bc
def crypto_get_symbol_data(
self,
symbol: str,
start: datetime,
end: datetime,
timeframe: TimeFrame,
) -> pd.DataFrame:
start = start.astimezone(tz=pytz.utc)
end = end.astimezone(tz=pytz.utc)
data = self.alpaca_crypto_data.get_crypto_bars( # type:ignore
CryptoBarsRequest(
symbol_or_symbols=symbol,
start=start,
end=end,
timeframe=timeframe,
)
).df
data = data.reset_index(level=0, drop=True)
data = data.tz_convert("America/New_York")
return self._extracted_from_get_symbols_data_14(data)
def get_symbols_data(
self,
symbols: List[str],
start: datetime,
end: datetime,
scale: TimeScale = TimeScale.minute,
) -> Dict[str, pd.DataFrame]:
assert isinstance(symbols, list), f"{symbols} must be a list"
start = start.astimezone(tz=pytz.utc)
end = end.astimezone(tz=pytz.utc)
t: TimeFrame = (
TimeFrame(1, TimeFrameUnit.Minute)
if scale == TimeScale.minute
else TimeFrame(1, TimeFrameUnit.Day)
)
data = self.alpaca_stock_data.get_stock_bars( # type:ignore
StockBarsRequest(
start=start,
end=end,
timeframe=t,
symbol_or_symbols=symbols,
adjustment=Adjustment.ALL,
)
).df
data = data.tz_convert("America/New_York", level=1)
return self._extracted_from_get_symbols_data_14(data)
# TODO Rename this here and in `crypto_get_symbol_data` and `get_symbols_data`
def _extracted_from_get_symbols_data_14(self, data):
data.rename(columns={"vwap": "average"}, inplace=True)
data.rename(columns={"trade_count": "count"}, inplace=True)
data["vwap"] = np.NaN
return data
def get_symbol_data(
self,
symbol: str,
start: datetime,
end: datetime,
scale: TimeScale = TimeScale.minute,
) -> pd.DataFrame:
t: TimeFrame = (
TimeFrame(1, TimeFrameUnit.Minute)
if scale == TimeScale.minute
else TimeFrame(1, TimeFrameUnit.Day)
)
if scale == TimeScale.day and start.date() == end.date():
start -= timedelta(days=1)
end += timedelta(days=1)
if _is_crypto_symbol(symbol):
return self.crypto_get_symbol_data(
symbol=symbol, start=start, end=end, timeframe=t
)
start = start.astimezone(tz=pytz.utc)
end = end.astimezone(tz=pytz.utc)
if config.detailed_dl_debug_enabled:
tlog(f"symbol={symbol}, timeframe={t}, range=({start, end})")
try:
data = self.alpaca_stock_data.get_stock_bars( # type:ignore
StockBarsRequest(
start=start,
end=end,
timeframe=t,
symbol_or_symbols=symbol,
adjustment=Adjustment.ALL,
)
).df
except requests.exceptions.HTTPError as e:
tlog(f"received HTTPError: {e}")
if e.response.status_code in (500, 502, 504, 429):
d77f64d895f48591d83080a3875e009386766e0b
github-actions commented
Stale issue message