This commit is contained in:
MuslemRahimi 2024-10-26 18:38:33 +02:00
parent 9de702534f
commit 286f88ab78
2 changed files with 38 additions and 3 deletions

View File

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

View File

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