From 4b8d3d52ef326d4258050f5618b66749f9775245 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Mon, 2 Dec 2024 20:20:40 +0100 Subject: [PATCH] update cron list --- app/cron_list.py | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/app/cron_list.py b/app/cron_list.py index d1a76c3..053a743 100644 --- a/app/cron_list.py +++ b/app/cron_list.py @@ -81,8 +81,6 @@ async def process_category(cursor, category, condition, category_type='market-ca async def get_etf_holding(etf_symbols, etf_con): - etf_symbols = ['AGG'] - for ticker in tqdm(etf_symbols): res = [] df = pd.read_sql_query(query_etf_holding, etf_con, params=(ticker,)) @@ -99,30 +97,26 @@ async def get_etf_holding(etf_symbols, etf_con): 'sharesNumber': item.get('marketValue', None) if not item.get('asset') and item.get('sharesNumber') == 0 else item.get('sharesNumber', None) } for item in data - if item.get('marketValue', 0) >= 0 # Exclude items with a negative marketValue + if item.get('marketValue', 0) >= 0 and item.get('weightPercentage', 0) > 0 # Exclude items with negative marketValue or non-positive weightPercentage ] for item in res: try: symbol = item['symbol'] - - # Check if the symbol data is already in the cache - if symbol in quote_cache: - quote_data = quote_cache[symbol] - else: - # Load the quote data from file if not in cache - try: - with open(f"json/quote/{symbol}.json") as file: - quote_data = orjson.loads(file.read()) - quote_cache[symbol] = quote_data # Cache the loaded data - item['price'] = round(quote_data.get('price'), 2) if quote_data else None - item['changesPercentage'] = round(quote_data.get('changesPercentage'), 2) if quote_data else None - item['name'] = quote_data.get('name') if quote_data else None - except: - quote_data = None + + # Adjustments for ticker = 'IBIT' + if ticker == 'IBIT' and symbol == 'BTC': + item['symbol'] = 'BTCUSD' + item['name'] = 'Bitcoin' + + quote_data = await get_quote_data(item['symbol']) + item['price'] = round(quote_data.get('price'), 2) if quote_data else None + item['changesPercentage'] = round(quote_data.get('changesPercentage'), 2) if quote_data else None + item['name'] = quote_data.get('name') if quote_data else item['name'] + except: pass - + # Assign price and changesPercentage if available, otherwise set to None item['weightPercentage'] = round(item.get('weightPercentage'), 2) if item['weightPercentage'] else None @@ -138,6 +132,8 @@ async def get_etf_holding(etf_symbols, etf_con): file.write(orjson.dumps(final_res)) + + async def get_etf_provider(etf_con): cursor = etf_con.cursor()