A FastAPI-based service for collecting and serving stablecoin circulating supply data from DeFiLlama.
- Collects stablecoin supply data from DeFiLlama
- Stores data in PostgreSQL database with UTC timestamps
- Provides REST API endpoints for accessing the data
- Supports filtering by stablecoin symbol and chain
- Tracks supply changes over 24h, 7d, and 30d periods
- Python 3.8 or higher
- PostgreSQL 12 or higher
psql
command-line tool
# Create PostgreSQL database
createdb stables
# Create virtual environment
python -m venv venv
# Activate virtual environment
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
Create a .env
file in the backend directory:
# Default configuration
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/stables
# Initialize database schema
alembic upgrade head
# Development mode with auto-reload
uvicorn app.main:app --reload
# Production mode
uvicorn app.main:app --host 0.0.0.0 --port 8000
id
: Primary key (from DeFiLlama)name
: Stablecoin namesymbol
: Token symbol (indexed)gecko_id
: CoinGecko ID (indexed)peg_type
: Type of peg (e.g., USD, EUR)peg_mechanism
: Peg mechanism typetotal_circulating
: Total supply across all chainstime_utc
: Timestamp with minute precision
- Composite primary key: (
stable_id
,chain
,time_utc
) stable_id
: Foreign key to stablecoin tablechain
: Blockchain namecirculating
: Circulating supply on this chaintime_utc
: Timestamp with minute precision
GET /
: Root endpoint with API informationGET /supply
: Get circulating supply data- Query parameters:
symbol
: Filter by stablecoin symbolchain
: Filter by chainlimit
: Maximum number of records (default: 100)
- Query parameters:
POST /collect
: Trigger data collection from DeFiLlama
# Create a new migration
alembic revision --autogenerate -m "description"
# Apply migrations
alembic upgrade head
# Rollback one version
alembic downgrade -1
The project follows PEP 8 guidelines. Before committing:
# Install development dependencies
pip install black isort
# Format code
black .
isort .