Add endpoint to get a single trade by ID
This commit is contained in:
parent
04192799ab
commit
0c75583930
2 changed files with 96 additions and 0 deletions
|
|
@ -565,6 +565,29 @@ async def get_my_trades(
|
|||
return [_to_exchange_response(ex, current_user.email) for ex in exchanges]
|
||||
|
||||
|
||||
@trades_router.get("/{exchange_id}", response_model=ExchangeResponse)
|
||||
async def get_my_trade(
|
||||
exchange_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: User = Depends(require_permission(Permission.VIEW_OWN_EXCHANGES)),
|
||||
) -> ExchangeResponse:
|
||||
"""Get a specific trade by ID. User can only access their own trades."""
|
||||
result = await db.execute(
|
||||
select(Exchange).where(
|
||||
and_(Exchange.id == exchange_id, Exchange.user_id == current_user.id)
|
||||
)
|
||||
)
|
||||
exchange = result.scalar_one_or_none()
|
||||
|
||||
if not exchange:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Trade not found or you don't have permission to view it.",
|
||||
)
|
||||
|
||||
return _to_exchange_response(exchange, current_user.email)
|
||||
|
||||
|
||||
@trades_router.post("/{exchange_id}/cancel", response_model=ExchangeResponse)
|
||||
async def cancel_my_trade(
|
||||
exchange_id: int,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue