1+ from collections .abc import Sequence
12from datetime import datetime
23
34import pandas as pd
4- from sqlalchemy import case , delete , func , or_ , select , update
5+ from sqlalchemy import Row , case , delete , func , or_ , select , update
56from sqlalchemy .dialects .postgresql import insert
67from sqlalchemy .ext .asyncio import AsyncSession
78
@@ -70,7 +71,7 @@ async def query_options_tickers(
7071 months_hist : int = 24 ,
7172 all_ = False ,
7273 unexpired = False ,
73- ) -> list [ OptionsTickerModel ]:
74+ ) -> Sequence [ Row ]:
7475 """
7576 This is to pull all options contracts for a given underlying ticker.
7677 The batch input is to only pull o_ticker_ids for given o_tickers
@@ -103,12 +104,12 @@ async def query_options_tickers(
103104
104105
105106@Session
106- async def query_stock_tickers (session : AsyncSession , all_ : bool = True , tickers : list [str ] = [] ) -> list [TickerModel ]:
107+ async def query_stock_tickers (session : AsyncSession , tickers : list [str ], all_ : bool = True ) -> list [TickerModel ]:
107108 """only returns tickers likely to have options contracts"""
108109 stmt = select (StockTickers .id , StockTickers .ticker ).where (StockTickers .type .in_ (["ADRC" , "ETF" , "CS" ]))
109110 if not all_ :
110111 stmt = stmt .where (StockTickers .ticker .in_ (tickers ))
111- return (await session .execute (stmt )).all ()
112+ return (await session .execute (stmt )).all () # type: ignore
112113
113114
114115@Session
@@ -128,8 +129,8 @@ async def ticker_imported(session: AsyncSession, ticker_id: int):
128129async def update_stock_metadata (session : AsyncSession , data : list [TickerModel ]):
129130 df = pd .DataFrame (data )
130131 df = df .drop_duplicates (subset = ["ticker" ], keep = "last" )
131- data = df .to_dict (orient = "records" )
132- stmt = insert (StockTickers ).values (data )
132+ clean_data = df .to_dict (orient = "records" )
133+ stmt = insert (StockTickers ).values (clean_data )
133134 stmt = stmt .on_conflict_do_update (
134135 index_elements = ["ticker" ],
135136 set_ = dict (
@@ -242,7 +243,7 @@ async def delete_stock_ticker(session: AsyncSession, ticker: str):
242243
243244
244245@Session
245- async def latest_date_per_ticker (session : AsyncSession , tickers : list [str ] = [] , options = False ):
246+ async def latest_date_per_ticker (session : AsyncSession , tickers : list [str ], options = False ):
246247 """query to retrieve the most recent date of record for ticker data (prices/quotes for stock/options).
247248 If tickers is [] empty, return all
248249 """
0 commit comments