Skip to content

Commit

Permalink
apply change requests
Browse files Browse the repository at this point in the history
  • Loading branch information
No-bodyq committed Nov 25, 2024
1 parent 6d17549 commit 6628ce3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
32 changes: 32 additions & 0 deletions web_app/api/serializers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This module defines the serializers for the user data.
"""
from decimal import Decimal
from datetime import datetime
from pydantic import BaseModel, Field


Expand Down Expand Up @@ -53,6 +54,37 @@ class GetStatsResponse(BaseModel):
description="Number of unique users in the database.",
)

class PositionHistoryItem(BaseModel):
"""
Represents a single user position in the trading history.
### Attributes:
- **status** (str): The current status of the position (e.g., "OPENED", "CLOSED", "LIQUIDATED").
- **created_at** (datetime): The timestamp when the position was created.
- **start_price** (float): The price of the asset when the position was opened.
- **amount** (str): The quantity of the asset involved in the position.
- **multiplier** (int): The leverage multiplier applied to the position.
"""
status: str
created_at: datetime
start_price: float
amount: str
multiplier: int


class UserHistoryResponse(BaseModel):
"""
Represents the response containing the history of positions for a user.
### Attributes:
- **positions** (List[PositionHistoryItem]): A list of positions that include details such as:
- `status`: The status of the position.
- `created_at`: When the position was created.
- `start_price`: The initial price of the asset.
- `amount`: The quantity of the asset involved.
- `multiplier`: The leverage multiplier applied to the position.
"""
positions: list[PositionHistoryItem]

class SubscribeToNotificationResponse(BaseModel):
"""
Expand Down
2 changes: 2 additions & 0 deletions web_app/api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
GetUserContractAddressResponse,
SubscribeToNotificationResponse,
UpdateUserContractResponse,
UserHistoryResponse
)
from web_app.contract_tools.mixins.dashboard import DashboardMixin
from web_app.db.crud import (
Expand Down Expand Up @@ -247,6 +248,7 @@ async def get_stats() -> GetStatsResponse:
"/api/get-user-history",
tags=["User Operations"],
summary="Get user position history",
response_model=UserHistoryResponse,
response_description="List of user positions including status,created_at, \
start_price, amount, and multiplier.",
)
Expand Down
2 changes: 1 addition & 1 deletion web_app/db/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def fetch_user_history(self, user_id: int) -> List[dict]:
)
.filter(Position.user_id == user_id)
.all()
)
).scalar()

# Transform the query result into a list of dictionaries
return [
Expand Down

0 comments on commit 6628ce3

Please sign in to comment.