update cron list for etf holding

This commit is contained in:
MuslemRahimi 2024-11-22 18:00:13 +01:00
parent 3003a2fb20
commit cd2655142d
2 changed files with 5 additions and 4 deletions

View File

@ -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):

View File

@ -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)