diff --git a/app/cron_list.py b/app/cron_list.py index a7daeea..3c93a0b 100644 --- a/app/cron_list.py +++ b/app/cron_list.py @@ -88,7 +88,7 @@ async def get_etf_holding(etf_symbols, etf_con): try: # Load holdings data from the SQL query result data = orjson.loads(df['holding'].iloc[0]) - + last_update = data[0]['updated'][0:10] # Rename 'asset' to 'symbol' and keep other keys the same res = [{'symbol': item['asset'], 'weightPercentage': item['weightPercentage'], @@ -117,7 +117,7 @@ async def get_etf_holding(etf_symbols, etf_con): item['name'] = quote_data.get('name') if quote_data else None except Exception as e: - print(e) + last_update = None res = [] # Save results to a file if there's data to write @@ -125,7 +125,8 @@ async def get_etf_holding(etf_symbols, etf_con): for rank, item in enumerate(res, 1): item['rank'] = rank with open(f"json/etf/holding/{ticker}.json", 'wb') as file: - file.write(orjson.dumps(res)) + final_res = {'lastUpdate': last_update, 'holdings': res} + file.write(orjson.dumps(final_res)) async def get_etf_provider(etf_con): diff --git a/app/main.py b/app/main.py index 1e69e6c..bb466d0 100755 --- a/app/main.py +++ b/app/main.py @@ -1767,7 +1767,7 @@ async def etf_holdings(data: TickerData, api_key: str = Security(get_api_key)): with open(f"json/etf/holding/{ticker}.json", 'rb') as file: res = orjson.loads(file.read()) except: - res = [] + res = {} data = orjson.dumps(res) compressed_data = gzip.compress(data)