-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/create-user-endpoint
- Loading branch information
Showing
45 changed files
with
7,501 additions
and
1,644 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" | ||
This module contains the API routes for deposit. | ||
""" | ||
|
||
from fastapi import APIRouter | ||
from uuid import UUID | ||
|
||
from app.crud.deposit import deposit_crud | ||
from app.schemas.deposit import DepositUpdate, DepositResponse | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.post("/update/{deposit_id}", response_model=DepositResponse) | ||
async def update_deposit( | ||
deposit_id: UUID, | ||
deposit_update: DepositUpdate, | ||
): | ||
""" | ||
Update a deposit by ID. | ||
:param deposit_id: str | ||
:param deposit_update: DepositUpdate data | ||
:param db: AsyncSession | ||
:return: Deposit | ||
""" | ||
return await deposit_crud.update_deposit( | ||
deposit_id, deposit_update.model_dump(exclude_none=True) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
""" | ||
This module contains endpoints for managing liquidations. | ||
""" | ||
|
||
from uuid import UUID | ||
from decimal import Decimal | ||
from fastapi import HTTPException | ||
from app.crud.liquidation import liquidation_crud # Using the instance from the specified module | ||
from app.schemas.liquidation import LiquidationResponse | ||
|
||
async def liquidate_position( | ||
margin_position_id: UUID, | ||
bonus_amount: Decimal, | ||
bonus_token: str, | ||
) -> LiquidationResponse: | ||
""" | ||
Liquidates a margin position by creating a liquidation record. | ||
Args: | ||
margin_position_id (UUID): The ID of the margin position. | ||
bonus_amount (Decimal): The bonus amount applied. | ||
bonus_token (str): The token used for the bonus. | ||
Returns: | ||
LiquidationResponse: Details of the liquidation entry. | ||
""" | ||
try: | ||
liquidation_entry = await liquidation_crud.liquidate_position( | ||
margin_position_id, bonus_amount, bonus_token | ||
) | ||
return LiquidationResponse( | ||
margin_position_id=liquidation_entry.margin_position_id, | ||
bonus_amount=liquidation_entry.bonus_amount, | ||
bonus_token=liquidation_entry.bonus_token, | ||
status="success", | ||
) | ||
except Exception as e: | ||
raise HTTPException(status_code=400, detail=str(e)) from e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
This module contains the API routes for margin positions. | ||
""" | ||
|
||
from fastapi import APIRouter, Depends | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
|
||
from app.crud.margin_position import margin_position_crud | ||
from app.schemas.margin_position import MarginPositionCreate, MarginPositionResponse | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.post("/open_margin_position", response_model=MarginPositionResponse) | ||
async def open_margin_position( | ||
position_data: MarginPositionCreate, | ||
db: AsyncSession = Depends(margin_position_crud.session), | ||
): | ||
""" | ||
Opens a margin position by creating an entry record in the database. | ||
:param position_data: MarginPositionCreate | ||
:param db: AsyncSession | ||
:return: MarginPositionResponse | ||
""" | ||
position = await margin_position_crud.open_margin_position( | ||
user_id=position_data.user_id, | ||
borrowed_amount=position_data.borrowed_amount, | ||
multiplier=position_data.multiplier, | ||
transaction_id=position_data.transaction_id, | ||
) | ||
return position |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.