diff --git a/app/cron_similar_stocks.py b/app/cron_similar_stocks.py index 631a5a7..b8fb3f9 100755 --- a/app/cron_similar_stocks.py +++ b/app/cron_similar_stocks.py @@ -26,7 +26,7 @@ query_template = """ async def get_data(symbol): """Extract specified columns data for a given symbol.""" - columns = ['dividendYield', 'employees', 'marketCap'] + columns = ['dividendYield', 'employees', 'marketCap','relativeFTD'] if symbol in stock_screener_data_dict: result = {} diff --git a/app/main.py b/app/main.py index 1536826..de5f792 100755 --- a/app/main.py +++ b/app/main.py @@ -2631,23 +2631,7 @@ async def get_pre_post_quote(data:TickerData, api_key: str = Security(get_api_ke return res -@app.post("/options-net-flow-ticker") -async def get_options_net_flow(data:TickerData, api_key: str = Security(get_api_key)): - ticker = data.ticker.upper() - cache_key = f"options-net-flow-ticker-{ticker}" - cached_result = redis_client.get(cache_key) - if cached_result: - return orjson.loads(cached_result) - try: - with open(f"json/options-net-flow/companies/{ticker}.json", 'rb') as file: - res = orjson.loads(file.read()) - except: - res = [] - - redis_client.set(cache_key, orjson.dumps(res)) - redis_client.expire(cache_key, caching_time) - return res @app.post("/options-stats-ticker") async def get_options_stats_ticker(data:TickerData, api_key: str = Security(get_api_key)): @@ -3499,7 +3483,12 @@ async def get_fail_to_deliver(data:TickerData, api_key: str = Security(get_api_k cache_key = f"fail-to-deliver-{ticker}" cached_result = redis_client.get(cache_key) if cached_result: - return orjson.loads(cached_result) + return StreamingResponse( + io.BytesIO(cached_result), + media_type="application/json", + headers={"Content-Encoding": "gzip"} + ) + try: with open(f"json/fail-to-deliver/companies/{ticker}.json", 'rb') as file: res = orjson.loads(file.read()) @@ -3508,7 +3497,17 @@ async def get_fail_to_deliver(data:TickerData, api_key: str = Security(get_api_k redis_client.set(cache_key, orjson.dumps(res)) redis_client.expire(cache_key, 3600*3600) # Set cache expiration time to 1 day - return res + data = orjson.dumps(res) + compressed_data = gzip.compress(data) + + redis_client.set(cache_key, compressed_data) + redis_client.expire(cache_key, 3600*3600) # Set cache expiration time to 1 day + + return StreamingResponse( + io.BytesIO(compressed_data), + media_type="application/json", + headers={"Content-Encoding": "gzip"} + ) @app.post("/borrowed-share") async def get_borrowed_share(data:TickerData, api_key: str = Security(get_api_key)):