diff --git a/app/cron_statistics.py b/app/cron_statistics.py index d16f2d0..8d489cb 100644 --- a/app/cron_statistics.py +++ b/app/cron_statistics.py @@ -20,10 +20,16 @@ async def save_json(symbol, data): async def get_data(symbol): """Extract specified columns data for a given symbol.""" columns = ['sharesOutStanding', 'sharesQoQ', 'sharesYoY','institutionalOwnership','floatShares', - 'priceEarningsRatio','forwardPE','priceToSalesRatio','forwardPS','priceToBookRatio','priceToFreeCashFlowsRatio', + 'peg','priceEarningsRatio','forwardPE','priceToSalesRatio','forwardPS','priceToBookRatio','priceToFreeCashFlowsRatio', 'sharesShort','shortOutStandingPercent','shortFloatPercent','shortRatio', 'enterpriseValue','evEarnings','evSales','evEBITDA','evEBIT','evFCF', - 'currentRatio','quickRatio','debtRatio','debtEquityRatio',] + 'currentRatio','quickRatio','debtRatio','debtEquityRatio','interestCoverage','cashFlowToDebtRatio','totalDebtToCapitalization', + 'returnOnEquity','returnOnAssets','returnOnCapital','revenuePerEmployee','profitPerEmployee', + 'employees','assetTurnover','inventoryTurnover','incomeTaxExpense','effectiveTaxRate','beta','returnOnInvestedCapital', + 'change1Y','sma50','sma200','rsi','avgVolume','revenue','netIncome','grossProfit','operatingIncome','ebitda','ebit','eps', + 'cashAndCashEquivalents','totalDebt','retainedEarnings','totalAssets','workingCapital','operatingCashFlow', + 'capitalExpenditure','freeCashFlow','freeCashFlowPerShare','grossProfitMargin','operatingProfitMargin','pretaxProfitMargin', + 'netProfitMargin','ebitdaMargin','ebitMargin','freeCashFlowMargin'] if symbol in stock_screener_data_dict: result = {} @@ -45,7 +51,7 @@ async def run(): con.close() # Process symbols with progress bar - for symbol in tqdm(total_symbols, desc="Extracting dividend data"): + for symbol in tqdm(total_symbols, desc="Extracting data"): data = await get_data(symbol) if data: # Only save if we have data await save_json(symbol, data) diff --git a/app/main.py b/app/main.py index bd24db3..9edfb33 100755 --- a/app/main.py +++ b/app/main.py @@ -4112,6 +4112,35 @@ async def get_insider_tracker(api_key: str = Security(get_api_key)): headers={"Content-Encoding": "gzip"} ) +@app.post("/statistics") +async def get_statistics(data: TickerData, api_key: str = Security(get_api_key)): + ticker = data.ticker + cache_key = f"statistics-{ticker}" + cached_result = redis_client.get(cache_key) + if cached_result: + return StreamingResponse( + io.BytesIO(cached_result), + media_type="application/json", + headers={"Content-Encoding": "gzip"} + ) + try: + with open(f"json/statistics/{ticker}.json", 'rb') as file: + res = orjson.loads(file.read()) + except: + res = {} + + data = orjson.dumps(res) + compressed_data = gzip.compress(data) + + redis_client.set(cache_key, compressed_data) + redis_client.expire(cache_key,60*60) + + return StreamingResponse( + io.BytesIO(compressed_data), + media_type="application/json", + headers={"Content-Encoding": "gzip"} + ) + @app.get("/newsletter") async def get_newsletter():