add hedge fund cron job
This commit is contained in:
parent
cacf53581f
commit
cd29b06cce
@ -62,7 +62,7 @@ crypto_con.close()
|
|||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
api_key = os.getenv('FMP_API_KEY')
|
api_key = os.getenv('FMP_API_KEY')
|
||||||
quarter_date = '2024-03-31'
|
quarter_date = '2024-06-30'
|
||||||
|
|
||||||
|
|
||||||
if os.path.exists("backup_db/institute.db"):
|
if os.path.exists("backup_db/institute.db"):
|
||||||
|
|||||||
@ -46,7 +46,7 @@ def best_hedge_funds(con):
|
|||||||
'performancePercentage3year': row[6]
|
'performancePercentage3year': row[6]
|
||||||
} for row in best_performing_ciks]
|
} for row in best_performing_ciks]
|
||||||
|
|
||||||
with open(f"{frontend_json_url}/best-hedge-funds.json", 'w') as file:
|
with open(f"json/hedge-funds/best-hedge-funds.json", 'w') as file:
|
||||||
json.dump(res_list, file)
|
json.dump(res_list, file)
|
||||||
|
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ def worst_hedge_funds(con):
|
|||||||
'performancePercentage3year': row[6]
|
'performancePercentage3year': row[6]
|
||||||
} for row in worst_performing_ciks]
|
} for row in worst_performing_ciks]
|
||||||
|
|
||||||
with open(f"{frontend_json_url}/worst-hedge-funds.json", 'w') as file:
|
with open(f"json/hedge-funds/worst-hedge-funds.json", 'w') as file:
|
||||||
json.dump(res_list, file)
|
json.dump(res_list, file)
|
||||||
|
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ def all_hedge_funds(con):
|
|||||||
|
|
||||||
sorted_res_list = sorted(res_list, key=lambda x: x['marketValue'], reverse=True)
|
sorted_res_list = sorted(res_list, key=lambda x: x['marketValue'], reverse=True)
|
||||||
|
|
||||||
with open(f"{frontend_json_url}/all-hedge-funds.json", 'w') as file:
|
with open(f"json/hedge-funds/all-hedge-funds.json", 'w') as file:
|
||||||
json.dump(sorted_res_list, file)
|
json.dump(sorted_res_list, file)
|
||||||
|
|
||||||
|
|
||||||
@ -127,7 +127,6 @@ def spy_performance():
|
|||||||
# Get the close price for the found or closest date
|
# Get the close price for the found or closest date
|
||||||
close_price = round(df[df['date'] == target_date]['close'].values[0],2)
|
close_price = round(df[df['date'] == target_date]['close'].values[0],2)
|
||||||
data.append({'date': original_date, 'price': close_price})
|
data.append({'date': original_date, 'price': close_price})
|
||||||
print(data)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -42,7 +42,7 @@ def options_bubble_data(chunk):
|
|||||||
start_date_str = start_date.strftime('%Y-%m-%d')
|
start_date_str = start_date.strftime('%Y-%m-%d')
|
||||||
|
|
||||||
res_list = []
|
res_list = []
|
||||||
for page in range(0, 100):
|
for page in range(0, 500):
|
||||||
try:
|
try:
|
||||||
data = fin.options_activity(company_tickers=company_tickers, page=page, pagesize=500, date_from=start_date_str, date_to=end_date_str)
|
data = fin.options_activity(company_tickers=company_tickers, page=page, pagesize=500, date_from=start_date_str, date_to=end_date_str)
|
||||||
data = ujson.loads(fin.output(data))['option_activity']
|
data = ujson.loads(fin.output(data))['option_activity']
|
||||||
|
|||||||
31
app/main.py
31
app/main.py
@ -1400,6 +1400,7 @@ async def get_hedge_funds_data(data: GetCIKData, api_key: str = Security(get_api
|
|||||||
'summary': orjson.loads(row[11]),
|
'summary': orjson.loads(row[11]),
|
||||||
} for row in cik_data]
|
} for row in cik_data]
|
||||||
|
|
||||||
|
|
||||||
res_json = orjson.dumps(res[0])
|
res_json = orjson.dumps(res[0])
|
||||||
compressed_data = gzip.compress(res_json)
|
compressed_data = gzip.compress(res_json)
|
||||||
|
|
||||||
@ -1413,6 +1414,36 @@ async def get_hedge_funds_data(data: GetCIKData, api_key: str = Security(get_api
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/all-hedge-funds")
|
||||||
|
async def get_all_hedge_funds_data(api_key: str = Security(get_api_key)):
|
||||||
|
|
||||||
|
cache_key = f"all-hedge-funds"
|
||||||
|
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/hedge-funds/all-hedge-funds.json", 'rb') as file:
|
||||||
|
res = orjson.loads(file.read())
|
||||||
|
except:
|
||||||
|
res = []
|
||||||
|
|
||||||
|
res = orjson.dumps(res)
|
||||||
|
compressed_data = gzip.compress(res)
|
||||||
|
|
||||||
|
redis_client.set(cache_key, compressed_data)
|
||||||
|
redis_client.expire(cache_key, 3600 * 3600) # Set cache expiration time to Infinity
|
||||||
|
|
||||||
|
return StreamingResponse(
|
||||||
|
io.BytesIO(compressed_data),
|
||||||
|
media_type="application/json",
|
||||||
|
headers={"Content-Encoding": "gzip"}
|
||||||
|
)
|
||||||
|
|
||||||
@app.get("/searchbar-data")
|
@app.get("/searchbar-data")
|
||||||
async def get_stock(api_key: str = Security(get_api_key)):
|
async def get_stock(api_key: str = Security(get_api_key)):
|
||||||
cache_key = f"searchbar-data"
|
cache_key = f"searchbar-data"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user