A highly optimized, asynchronous FastAPI engine for tracking cryptocurrency asset holdings, transaction history, and real-time profits and losses (P&L).
To ensure high-throughput capabilities and profile latency under execution stress, the REST API engine was benchmarked under two distinct profiles using an in-memory SQLite database and a mocked CoinGecko pricing handler to isolate core framework overhead.
Below is the latency profile representing request processing time under a standard single load sequence:
- Database reads (live pricing check and portfolio aggregates) average under 1.5ms.
- Write actions (adding a holding with DCA computation) process in 2.6ms.
The chart below illustrates how performance profiles scale across varying transaction request loads:
- Read Operations: Query operations such as
GET Live PriceandGET Portfolio Summaryscale flatly and complete in under ~1.5ms even under high loads. - Write Operations: Holdings updates (
POST Buy Holding) process in ~2.6ms with full validation. - Security Checkpoints: Auth routines (
POST RegisterandPOST Login) are subject to Bcrypt CPU-bound operations (designed for security) taking ~220ms per cycle, while the surrounding HTTP routing adds zero noticeable overhead.
Below is the high-level architecture diagram of the REST API engine:
graph LR
Client[Client Request] --> AuthRouter[Auth Router]
Client --> HoldingsRouter[Holdings Router]
Client --> PortfolioRouter[Portfolio Router]
Client --> PricesRouter[Prices Router]
AuthRouter --> AuthValidator[JWT Sign/Verify]
HoldingsRouter --> DCAEngine[DCA Engine]
PortfolioRouter --> ValEngine[Valuation & P&L Engine]
AuthValidator --> DB[(PostgreSQL DB)]
DCAEngine --> DB
ValEngine --> CoingeckoClient[CoinGecko Service]
PricesRouter --> CoingeckoClient
Ensure a local PostgreSQL instance is running with a database named crypto_tracker:
CREATE DATABASE crypto_tracker;Set up a Python 3.12 virtual environment and install requirements:
python3.12 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txtCopy .env.example to .env and verify the settings:
cp .env.example .envApply database migrations:
alembic upgrade headStart the live development server:
uvicorn app.main:app --reloadRun the automated test suite:
PYTHONPATH=. pytest -vPOST /api/v1/auth/register- Registers a new user.POST /api/v1/auth/login- Authenticates and issues a JWT token.
POST /api/v1/holdings- Adds or updates token holdings (triggers the DCA recalculator).GET /api/v1/holdings- Fetches the current user's holding list.DELETE /api/v1/holdings/{holding_id}- Sells/deletes a holding.
GET /api/v1/portfolio/summary- Aggregates holding quantities, cost, and live P&L.GET /api/v1/portfolio/history- Returns the complete audit list of buy and sell transactions.
GET /api/v1/prices/{coin_id}- Queries live USD pricing from CoinGecko (features tenacious retries and caching policies).

