async def add_stock_data_for_date(self, symbol: str, when: date) -> None: _minute_data = self.data_loader[symbol][when:when + timedelta(days=1 ) # type: ignore ] await asyncio.sleep(0) if _minute_data[symbol].empty: daily_bar = StockOhlc( symbol=symbol, symbol_date=when, open=0.0, high=0.0, low=0.0, close=0.0, volume=0, indicators={}, ) await daily_bar.save() else: for index, row in _minute_data[symbol].iterrows(): daily_bar = StockOhlc( symbol=symbol, symbol_date=index, open=row["open"], high=row["high"], low=row["low"], close=row["close"], volume=int(row["volume"]), indicators={}, ) await daily_bar.save() print(f"saved data for {symbol} @ {index}")
async def load_symbol_data( self, symbol: str, days: int, ) -> None: start_date = date.today() - timedelta(days=days) _minute_data = get_historical_data_from_polygon_by_range( self.data_api, [symbol], start_date, "day") for index, row in _minute_data[symbol].iterrows(): indicators: Dict = {} if self.indicators: for indicator in self.indicators: if indicator == "mama": mama, fama = MAMA( _minute_data[symbol]["close"][:index].dropna()) indicators["mama"] = ( mama[-1] if not math.isnan(mama[-1]) else None) indicators["fama"] = ( fama[-1] if not math.isnan(fama[-1]) else None) daily_bar = StockOhlc( symbol=symbol, symbol_date=index, open=row["open"], high=row["high"], low=row["low"], close=row["close"], volume=int(row["volume"]), indicators=indicators, ) await daily_bar.save() tlog(f"saved {len(_minute_data[symbol].index)} days for {symbol}")