Update code via agent code generation

This commit is contained in:
Automated Action 2025-06-07 12:44:14 +00:00
parent b7f18dcaec
commit 7cd382f36f
2 changed files with 98 additions and 3 deletions

View File

@ -1,12 +1,17 @@
from datetime import datetime
from typing import Any, Optional
from fastapi import APIRouter, Depends, Query, HTTPException, status
from fastapi import APIRouter, Depends, Query, HTTPException, status, Response
from sqlalchemy.orm import Session
from sqlalchemy import desc
from app.db.session import get_db
from app.models.arbitrage import ArbitrageOpportunity
from app.schemas.arbitrage import OpportunitiesList, ArbitrageOpportunityCreate, ArbitrageOpportunity as ArbitrageOpportunitySchema
from app.schemas.arbitrage import (
OpportunitiesList,
ArbitrageOpportunityCreate,
ArbitrageOpportunityUpdate,
ArbitrageOpportunity as ArbitrageOpportunitySchema
)
router = APIRouter()
@ -95,3 +100,49 @@ async def create_arbitrage_opportunity(
db.commit()
db.refresh(db_opportunity)
return db_opportunity
@router.put("/{opportunity_id}", response_model=ArbitrageOpportunitySchema)
async def update_arbitrage_opportunity(
opportunity_id: int,
opportunity_update: ArbitrageOpportunityUpdate,
db: Session = Depends(get_db)
) -> Any:
"""
Update an existing arbitrage opportunity.
"""
db_opportunity = db.query(ArbitrageOpportunity).filter(ArbitrageOpportunity.id == opportunity_id).first()
if not db_opportunity:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"Arbitrage opportunity with ID {opportunity_id} not found"
)
# Update fields if provided in the request
update_data = opportunity_update.dict(exclude_unset=True)
for field, value in update_data.items():
setattr(db_opportunity, field, value)
db.commit()
db.refresh(db_opportunity)
return db_opportunity
@router.delete("/{opportunity_id}", status_code=status.HTTP_204_NO_CONTENT, response_model=None)
async def delete_arbitrage_opportunity(
opportunity_id: int,
db: Session = Depends(get_db)
) -> None:
"""
Delete an arbitrage opportunity.
"""
db_opportunity = db.query(ArbitrageOpportunity).filter(ArbitrageOpportunity.id == opportunity_id).first()
if not db_opportunity:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"Arbitrage opportunity with ID {opportunity_id} not found"
)
db.delete(db_opportunity)
db.commit()
return None

View File

@ -25,6 +25,25 @@ class ArbitrageOpportunityCreate(ArbitrageOpportunityBase):
pass
class ArbitrageOpportunityUpdate(BaseModel):
token_address: Optional[str] = None
token_symbol: Optional[str] = None
source_dex: Optional[str] = None
target_dex: Optional[str] = None
source_price: Optional[float] = None
target_price: Optional[float] = None
price_difference: Optional[float] = None
price_difference_percent: Optional[float] = None
estimated_profit_usd: Optional[float] = None
estimated_profit_token: Optional[float] = None
max_trade_amount_usd: Optional[float] = None
max_trade_amount_token: Optional[float] = None
slippage_estimate: Optional[float] = None
fees_estimate: Optional[float] = None
is_viable: Optional[bool] = None
was_executed: Optional[bool] = None
class ArbitrageOpportunity(ArbitrageOpportunityBase):
id: int
created_at: datetime
@ -55,6 +74,24 @@ class TradeCreate(TradeBase):
tx_error: Optional[str] = None
class TradeUpdate(BaseModel):
token_address: Optional[str] = None
token_symbol: Optional[str] = None
source_dex: Optional[str] = None
target_dex: Optional[str] = None
input_amount: Optional[float] = None
input_amount_usd: Optional[float] = None
output_amount: Optional[float] = None
output_amount_usd: Optional[float] = None
profit_amount: Optional[float] = None
profit_amount_usd: Optional[float] = None
profit_percent: Optional[float] = None
opportunity_id: Optional[int] = None
tx_signature: Optional[str] = None
tx_status: Optional[str] = None
tx_error: Optional[str] = None
class Trade(TradeBase):
id: int
created_at: datetime
@ -78,6 +115,13 @@ class SystemEventCreate(SystemEventBase):
pass
class SystemEventUpdate(BaseModel):
event_type: Optional[str] = None
component: Optional[str] = None
message: Optional[str] = None
details: Optional[str] = None
class SystemEvent(SystemEventBase):
id: int
timestamp: datetime