update cron list for etf holding
This commit is contained in:
parent
3003a2fb20
commit
cd2655142d
@ -88,7 +88,7 @@ async def get_etf_holding(etf_symbols, etf_con):
|
|||||||
try:
|
try:
|
||||||
# Load holdings data from the SQL query result
|
# Load holdings data from the SQL query result
|
||||||
data = orjson.loads(df['holding'].iloc[0])
|
data = orjson.loads(df['holding'].iloc[0])
|
||||||
|
last_update = data[0]['updated'][0:10]
|
||||||
# Rename 'asset' to 'symbol' and keep other keys the same
|
# Rename 'asset' to 'symbol' and keep other keys the same
|
||||||
res = [{'symbol': item['asset'],
|
res = [{'symbol': item['asset'],
|
||||||
'weightPercentage': item['weightPercentage'],
|
'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
|
item['name'] = quote_data.get('name') if quote_data else None
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
last_update = None
|
||||||
res = []
|
res = []
|
||||||
|
|
||||||
# Save results to a file if there's data to write
|
# 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):
|
for rank, item in enumerate(res, 1):
|
||||||
item['rank'] = rank
|
item['rank'] = rank
|
||||||
with open(f"json/etf/holding/{ticker}.json", 'wb') as file:
|
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):
|
async def get_etf_provider(etf_con):
|
||||||
|
|||||||
@ -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:
|
with open(f"json/etf/holding/{ticker}.json", 'rb') as file:
|
||||||
res = orjson.loads(file.read())
|
res = orjson.loads(file.read())
|
||||||
except:
|
except:
|
||||||
res = []
|
res = {}
|
||||||
|
|
||||||
data = orjson.dumps(res)
|
data = orjson.dumps(res)
|
||||||
compressed_data = gzip.compress(data)
|
compressed_data = gzip.compress(data)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user