From 3b01312e2742b7dd0d48e3a9e14f0261312d03c7 Mon Sep 17 00:00:00 2001 From: sina <20732540+SinaKhalili@users.noreply.github.com> Date: Wed, 6 Nov 2024 11:18:38 -0800 Subject: [PATCH] Update backend snapshot retaking --- backend/api/price_shock.py | 3 --- backend/app.py | 4 ++-- backend/utils/matrix.py | 8 ++++---- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/backend/api/price_shock.py b/backend/api/price_shock.py index 7275818..ef32a54 100644 --- a/backend/api/price_shock.py +++ b/backend/api/price_shock.py @@ -12,9 +12,7 @@ router = APIRouter() -@functools.lru_cache() async def _get_price_shock( - snapshot_path: str, vat: Vat, drift_client: DriftClient, oracle_distortion: float = 0.1, @@ -38,7 +36,6 @@ async def get_price_shock( n_scenarios: int = 5, ): return await _get_price_shock( - request.state.backend_state.current_pickle_path, request.state.backend_state.vat, request.state.backend_state.dc, oracle_distortion, diff --git a/backend/app.py b/backend/app.py index 3df3796..ae75869 100644 --- a/backend/app.py +++ b/backend/app.py @@ -105,13 +105,13 @@ async def lifespan(app: FastAPI): print("Loading cached vat") await state.load_pickle_snapshot(cached_vat_path[-1]) # await repeatedly_clean_cache(state) - # await repeatedly_retake_snapshot(state) + await repeatedly_retake_snapshot(state) else: print("No cached vat found, bootstrapping") await state.bootstrap() await state.take_pickle_snapshot() # await repeatedly_clean_cache(state) - # await repeatedly_retake_snapshot(state) + await repeatedly_retake_snapshot(state) state.ready = True # print("Checking price shock") # await price_shock._get_price_shock( diff --git a/backend/utils/matrix.py b/backend/utils/matrix.py index 9a4bf6e..275ec1e 100644 --- a/backend/utils/matrix.py +++ b/backend/utils/matrix.py @@ -61,16 +61,16 @@ def get_rattt(row): ( f"perp_{perp_market_index}_long", lambda v: ( - v / row["spot_asset"] * row["net_p"][perp_market_index] - if v > 0 and row["net_p"][0] > 0 + v / row["spot_asset"] * float(row["net_p"][perp_market_index]) + if v > 0 and float(row["net_p"][perp_market_index]) > 0 else 0 ), ), ( f"perp_{perp_market_index}_short", lambda v: ( - v / row["spot_asset"] * row["net_p"][perp_market_index] - if v > 0 and row["net_p"][perp_market_index] < 0 + v / row["spot_asset"] * float(row["net_p"][perp_market_index]) + if v > 0 and float(row["net_p"][perp_market_index]) < 0 else 0 ), ),