
* Created FastAPI application structure * Added database models for assets, exchanges, markets, and rates * Integrated with CoinCap API * Implemented REST API endpoints * Setup SQLite persistence with Alembic migrations * Added comprehensive documentation Generated with BackendIM... (backend.im)
64 lines
1.4 KiB
Python
64 lines
1.4 KiB
Python
from pydantic import BaseModel, Field
|
|
from typing import List, Optional
|
|
from datetime import datetime
|
|
|
|
|
|
class AssetBase(BaseModel):
|
|
id: str
|
|
rank: str
|
|
symbol: str
|
|
name: str
|
|
supply: str
|
|
max_supply: Optional[str] = None
|
|
market_cap_usd: str
|
|
volume_usd_24hr: str
|
|
price_usd: str
|
|
change_percent_24hr: Optional[str] = None
|
|
vwap_24hr: Optional[str] = None
|
|
explorer: Optional[str] = None
|
|
|
|
|
|
class Asset(AssetBase):
|
|
"""Data model for retrieving assets"""
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class AssetCreate(AssetBase):
|
|
"""Data model for creating assets"""
|
|
pass
|
|
|
|
|
|
class AssetPriceHistoryBase(BaseModel):
|
|
price_usd: str
|
|
time: int
|
|
date: str
|
|
|
|
|
|
class AssetPriceHistory(AssetPriceHistoryBase):
|
|
"""Data model for retrieving asset price history"""
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class AssetPriceHistoryCreate(AssetPriceHistoryBase):
|
|
"""Data model for creating asset price history"""
|
|
asset_id: str
|
|
|
|
|
|
class AssetResponse(BaseModel):
|
|
"""Response model for asset endpoints"""
|
|
timestamp: int
|
|
data: Asset
|
|
|
|
|
|
class AssetsResponse(BaseModel):
|
|
"""Response model for multiple assets"""
|
|
timestamp: int
|
|
data: List[Asset]
|
|
|
|
|
|
class AssetHistoryResponse(BaseModel):
|
|
"""Response model for asset history endpoint"""
|
|
timestamp: int
|
|
data: List[AssetPriceHistory] |