bugfixing

This commit is contained in:
MuslemRahimi 2024-12-10 20:19:36 +01:00
parent 6cc5458e89
commit c7003462e4
3 changed files with 7 additions and 12 deletions

View File

@ -81,7 +81,7 @@ async def process_category(cursor, category, condition, category_type='market-ca
async def get_etf_holding(etf_symbols, etf_con): async def get_etf_holding(etf_symbols, etf_con):
for ticker in tqdm(etf_symbols): for ticker in ['SPY']: #tqdm(etf_symbols):
res = [] res = []
df = pd.read_sql_query(query_etf_holding, etf_con, params=(ticker,)) df = pd.read_sql_query(query_etf_holding, etf_con, params=(ticker,))
try: try:
@ -115,6 +115,7 @@ async def get_etf_holding(etf_symbols, etf_con):
except: except:
pass pass
# Assign price and changesPercentage if available, otherwise set to None # Assign price and changesPercentage if available, otherwise set to None
item['weightPercentage'] = round(item.get('weightPercentage'), 2) if item['weightPercentage'] else None item['weightPercentage'] = round(item.get('weightPercentage'), 2) if item['weightPercentage'] else None
@ -131,7 +132,6 @@ async def get_etf_holding(etf_symbols, etf_con):
async def get_etf_provider(etf_con): async def get_etf_provider(etf_con):
cursor = etf_con.cursor() cursor = etf_con.cursor()
@ -209,7 +209,6 @@ async def get_magnificent_seven():
with open(f"json/stocks-list/list/magnificent-seven.json", 'wb') as file: with open(f"json/stocks-list/list/magnificent-seven.json", 'wb') as file:
file.write(orjson.dumps(res_list)) file.write(orjson.dumps(res_list))
print(res_list)
async def get_faang(): async def get_faang():

View File

@ -490,7 +490,6 @@ async def get_stock(data: HistoricalPrice, api_key: str = Security(get_api_key))
async def get_stock(data: HistoricalPrice, api_key: str = Security(get_api_key)): async def get_stock(data: HistoricalPrice, api_key: str = Security(get_api_key)):
ticker = data.ticker.upper() ticker = data.ticker.upper()
time_period = data.timePeriod time_period = data.timePeriod
print(time_period)
cache_key = f"export-price-data-{ticker}-{time_period}" cache_key = f"export-price-data-{ticker}-{time_period}"
cached_result = redis_client.get(cache_key) cached_result = redis_client.get(cache_key)
if cached_result: if cached_result:
@ -1205,7 +1204,6 @@ async def get_analyst_ticke_history(data: TickerData, api_key: str = Security(ge
@app.post("/indicator-data") @app.post("/indicator-data")
async def get_indicator(data: IndicatorListData, api_key: str = Security(get_api_key)): async def get_indicator(data: IndicatorListData, api_key: str = Security(get_api_key)):
rule_of_list = data.ruleOfList or ['volume', 'marketCap', 'changesPercentage', 'price', 'symbol', 'name'] rule_of_list = data.ruleOfList or ['volume', 'marketCap', 'changesPercentage', 'price', 'symbol', 'name']
# Ensure 'symbol' and 'name' are always included in the rule_of_list # Ensure 'symbol' and 'name' are always included in the rule_of_list
if 'symbol' not in rule_of_list: if 'symbol' not in rule_of_list:
rule_of_list.append('symbol') rule_of_list.append('symbol')
@ -1224,15 +1222,14 @@ async def get_indicator(data: IndicatorListData, api_key: str = Security(get_api
for ticker, quote in quote_dict.items(): for ticker, quote in quote_dict.items():
# Determine the ticker type based on the sets # Determine the ticker type based on the sets
ticker_type = ( ticker_type = (
'etf' if ticker in etf_symbols else 'etf' if ticker in etf_set else
'crypto' if ticker in crypto_symbols else 'crypto' if ticker in crypto_set else
'stock' 'stock'
) )
# Filter the quote based on keys in rule_of_list (use data only from quote.json for these) # Filter the quote based on keys in rule_of_list (use data only from quote.json for these)
filtered_quote = {key: quote.get(key) for key in rule_of_list if key in quote} filtered_quote = {key: quote.get(key) for key in rule_of_list if key in quote}
filtered_quote['type'] = ticker_type filtered_quote['type'] = ticker_type
# Add the result to combined_results # Add the result to combined_results
combined_results.append(filtered_quote) combined_results.append(filtered_quote)
@ -1247,7 +1244,6 @@ async def get_indicator(data: IndicatorListData, api_key: str = Security(get_api
result.update(screener_dict[symbol]) result.update(screener_dict[symbol])
# Serialize and compress the response # Serialize and compress the response
res = orjson.dumps(combined_results) res = orjson.dumps(combined_results)
compressed_data = gzip.compress(res) compressed_data = gzip.compress(res)

View File

@ -272,8 +272,8 @@ const sendData = async () => {
try { try {
jsonData = JSON?.parse(fileData); jsonData = JSON?.parse(fileData);
} catch (parseError) { } catch (parseError) {
console.error(`Invalid JSON format for ticker: ${symbol}`, parseError); //console.error(`Invalid JSON format for ticker: ${symbol}`, parseError);
console.error(`File content: ${fileData}`); //console.error(`File content: ${fileData}`);
continue; continue;
} }
@ -338,7 +338,7 @@ const sendData = async () => {
try { try {
// Parse message as JSON to get tickers array // Parse message as JSON to get tickers array
tickers = JSON.parse(message.toString("utf-8")); tickers = JSON.parse(message.toString("utf-8"));
console.log("Received tickers from client:", tickers); //console.log("Received tickers from client:", tickers);
// Reset last sent data for new tickers // Reset last sent data for new tickers
tickers?.forEach((ticker) => { tickers?.forEach((ticker) => {