
- Create project structure with FastAPI - Add database models for blocks, transactions, arbitrages, pools, and DEXes - Implement Solana RPC client for fetching blockchain data - Create arbitrage detection algorithm - Implement comprehensive API endpoints for analytics - Set up database migrations with Alembic - Add detailed project documentation generated with BackendIM... (backend.im) Co-Authored-By: Claude <noreply@anthropic.com>
115 lines
2.8 KiB
Python
115 lines
2.8 KiB
Python
from datetime import datetime
|
|
from typing import List, Optional, Dict, Any, Union
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class ArbitrageBase(BaseModel):
|
|
transaction_id: int
|
|
initiator_address: str
|
|
start_token_address: str
|
|
start_token_symbol: Optional[str] = None
|
|
start_amount: float
|
|
end_amount: float
|
|
profit_amount: float
|
|
profit_percentage: float
|
|
success: bool = False
|
|
failure_reason: Optional[str] = None
|
|
gas_cost: Optional[float] = None
|
|
net_profit: Optional[float] = None
|
|
legs_count: int = 0
|
|
route_description: Optional[str] = None
|
|
|
|
|
|
class ArbitrageCreate(ArbitrageBase):
|
|
included_dexes: Optional[List[str]] = None
|
|
|
|
|
|
class ArbitrageUpdate(BaseModel):
|
|
start_token_symbol: Optional[str] = None
|
|
end_amount: Optional[float] = None
|
|
profit_amount: Optional[float] = None
|
|
profit_percentage: Optional[float] = None
|
|
success: Optional[bool] = None
|
|
failure_reason: Optional[str] = None
|
|
gas_cost: Optional[float] = None
|
|
net_profit: Optional[float] = None
|
|
legs_count: Optional[int] = None
|
|
route_description: Optional[str] = None
|
|
included_dexes: Optional[List[str]] = None
|
|
|
|
|
|
class ArbitrageInDBBase(ArbitrageBase):
|
|
id: int
|
|
included_dexes: Optional[List[str]] = None
|
|
created_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class Arbitrage(ArbitrageInDBBase):
|
|
pass
|
|
|
|
|
|
class ArbitrageLegBase(BaseModel):
|
|
arbitrage_id: int
|
|
leg_index: int
|
|
pool_id: int
|
|
token_in_address: str
|
|
token_in_symbol: Optional[str] = None
|
|
token_in_amount: float
|
|
token_out_address: str
|
|
token_out_symbol: Optional[str] = None
|
|
token_out_amount: float
|
|
price_impact: Optional[float] = None
|
|
|
|
|
|
class ArbitrageLegCreate(ArbitrageLegBase):
|
|
pass
|
|
|
|
|
|
class ArbitrageLegUpdate(BaseModel):
|
|
token_in_symbol: Optional[str] = None
|
|
token_in_amount: Optional[float] = None
|
|
token_out_symbol: Optional[str] = None
|
|
token_out_amount: Optional[float] = None
|
|
price_impact: Optional[float] = None
|
|
|
|
|
|
class ArbitrageLegInDBBase(ArbitrageLegBase):
|
|
id: int
|
|
created_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class ArbitrageLeg(ArbitrageLegInDBBase):
|
|
pass
|
|
|
|
|
|
class ArbitrageLegWithPool(ArbitrageLeg):
|
|
pool_address: str
|
|
dex_name: str
|
|
|
|
|
|
class ArbitrageWithLegs(Arbitrage):
|
|
legs: List[ArbitrageLegWithPool]
|
|
block_height: int
|
|
block_time: Optional[datetime] = None
|
|
|
|
|
|
class ArbitrageList(BaseModel):
|
|
arbitrages: List[Arbitrage]
|
|
total: int
|
|
|
|
|
|
class ArbitrageStats(BaseModel):
|
|
total_arbitrages: int
|
|
successful_arbitrages: int
|
|
failed_arbitrages: int
|
|
total_profit: float
|
|
avg_profit_percentage: float
|
|
max_profit_percentage: float
|
|
most_used_dexes: List[Dict[str, Union[str, int]]]
|
|
most_arbitraged_tokens: List[Dict[str, Union[str, int]]] |