Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ venv
**/__pycache__/
.env
.venv
.venv-risk
pickles/*
cache
ignore
ucache
matrix_response.json
logs/*
.DS_Store
27 changes: 27 additions & 0 deletions .repo_ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Package manager caches
**/node_modules/
**/.npm/
**/__pycache__/
**/.pytest_cache/
**/.mypy_cache/

# Build caches
**/.gradle/
**/.nuget/
**/.cargo/
**/.stack-work/
**/.ccache/

# IDE and Editor caches
**/.idea/
**/.vscode/
**/*.swp
**/*~

# Temp files
**/*.tmp
**/*.temp
**/*.bak

**/*.meta
**/package-lock.json
3 changes: 3 additions & 0 deletions .streamlit/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ gatherUsageStats = false

[client]
toolbarMode = "minimal"
showCallbackWarning = false
showCachedResourceWarning = false
showStatusIndicator = false
4 changes: 3 additions & 1 deletion Dockerfile-backend
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ COPY . /app

RUN apt-get update && apt-get install -y gcc python3-dev
RUN pip install --trusted-host pypi.python.org -r requirements.txt
RUN mkdir -p /logs && chmod 777 /logs

EXPOSE 8000

CMD ["uvicorn", "backend.app:app", "--host", "0.0.0.0", "--port", "8000"]
CMD ["gunicorn", "backend.app:app", "-c", "gunicorn_config.py"]
Binary file added backend/.DS_Store
Binary file not shown.
12 changes: 10 additions & 2 deletions backend/api/asset_liability.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from driftpy.pickle.vat import Vat
from fastapi import APIRouter
import logging

from backend.state import BackendRequest
from backend.utils.matrix import get_matrix

router = APIRouter()
logger = logging.getLogger(__name__)


async def _get_asset_liability_matrix(
Expand All @@ -13,10 +15,16 @@ async def _get_asset_liability_matrix(
mode: int,
perp_market_index: int,
) -> dict:
print("==> Getting asset liability matrix...")
logger.info("==> Starting asset liability matrix calculation...")
logger.info(f"Mode: {mode}, Perp Market Index: {perp_market_index}")

logger.info("==> Processing user data and calculating metrics...")
df = await get_matrix(vat, mode, perp_market_index)

logger.info("==> Converting DataFrame to dictionary...")
df_dict = df.to_dict()
print("==> Asset liability matrix fetched")

logger.info("==> Asset liability matrix calculation complete")

return {
"slot": slot,
Expand Down
123 changes: 123 additions & 0 deletions backend/api/debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
from fastapi import APIRouter
from backend.state import BackendRequest
import logging
from typing import Dict, Any

router = APIRouter()
logger = logging.getLogger(__name__)


@router.get("/debug")
async def debug_state(request: BackendRequest) -> Dict[str, Any]:
"""
Debug endpoint to check state details.
"""
state = request.backend_state

if not state:
return {
"status": "error",
"error": "no_state",
"details": "No backend state found in request"
}

components = {
"ready": state.ready,
"vat_exists": state.vat is not None,
"dc_exists": state.dc is not None,
"connection_exists": state.connection is not None,
"spot_map_exists": state.spot_markets is not None,
"perp_map_exists": state.perp_markets is not None,
"user_map_exists": state.user_map is not None,
"stats_map_exists": state.stats_map is not None
}

try:
if not state.is_ready:
components["state_error"] = "State is not ready"
return {
"status": "error",
"components": components,
"is_ready": False
}

if state.vat:
vat = state.vat

# Check spot markets
if hasattr(vat, "spot_markets"):
spot_markets = vat.spot_markets
if hasattr(spot_markets, 'market_map'):
market_map = spot_markets.market_map
elif hasattr(spot_markets, 'markets'):
market_map = spot_markets.markets

if market_map:
try:
# Get market keys safely
market_keys = []
for key in market_map:
market_keys.append(key)
components["spot_markets_count"] = len(market_keys)
components["spot_markets_indices"] = market_keys[:5]
except Exception as e:
logger.error(f"Error getting spot markets count: {str(e)}")
components["spot_markets_error"] = str(e)
else:
components["spot_markets_error"] = "No market map found"

# Check perp markets
if hasattr(vat, "perp_markets"):
perp_markets = vat.perp_markets
if hasattr(perp_markets, 'market_map'):
market_map = perp_markets.market_map
elif hasattr(perp_markets, 'markets'):
market_map = perp_markets.markets

if market_map:
try:
# Get market keys safely
market_keys = []
for key in market_map:
market_keys.append(key)
components["perp_markets_count"] = len(market_keys)
components["perp_markets_indices"] = market_keys[:5]
except Exception as e:
logger.error(f"Error getting perp markets count: {str(e)}")
components["perp_markets_error"] = str(e)
else:
components["perp_markets_error"] = "No market map found"

# Check users
if hasattr(vat, "users"):
users = vat.users
if hasattr(users, 'users'):
user_map = users.users
elif hasattr(users, 'user_map'):
user_map = users.user_map

if user_map:
try:
# Get user keys safely
user_keys = []
for key in user_map:
user_keys.append(key)
components["users_count"] = len(user_keys)
components["sample_users"] = [str(key) for key in user_keys[:5]]
except Exception as e:
logger.error(f"Error getting users count: {str(e)}")
components["users_error"] = str(e)
else:
components["users_error"] = "No users found"
else:
components["vat_error"] = "VAT is not initialized"

except Exception as e:
logger.error(f"Error in debug endpoint: {str(e)}")
components["error"] = str(e)

return {
"status": "success",
"components": components,
"is_ready": state.is_ready
}
Loading