Backend service that calculates hourly portfolio value in USDT, stores historical snapshots, and exposes chart-ready history API.
- PHP 8.4+
- Composer 2+
- Docker + Docker Compose
- Symfony CLI (optional, recommended)
- Install dependencies:
composer install- Start PostgreSQL container:
docker compose up -d database- Create database schema:
php bin/console doctrine:database:create
php bin/console doctrine:migrations:migrate --no-interaction- (Optional) Start local Symfony server:
symfony server:startphp bin/console app:portfolio:snapshotCron example:
0 * * * * php /path/to/project/bin/console app:portfolio:snapshot --env=prodReturns historical portfolio valuation, sorted chronologically (ASC).
Supported query parameters:
hours(example:?hours=24)fromandtoin ISO-8601 format (example:?from=2026-02-26T10:00:00Z&to=2026-02-26T12:00:00Z)
Do not combine hours with from/to in one request.
Example response:
[
{ "time": "2026-02-26T10:00:00Z", "amount_usdt": 123456.78 },
{ "time": "2026-02-26T11:00:00Z", "amount_usdt": 123789.12 }
]- Swagger UI:
GET /api/doc - OpenAPI JSON:
GET /api/doc.json
BinancePriceServiceencapsulates external HTTP calls and error handling for Binance avgPrice endpoint.PortfolioValuationServicecontains business logic for valuation formula and configured portfolio holdings.PortfolioSnapshotCommandis the scheduled entrypoint (app:portfolio:snapshot) that calculates and persists one snapshot per hour (UTC hour granularity).PortfolioValuationSnapshotDoctrine entity stores historical values inportfolio_valuation_snapshots.PortfolioHistoryControllerexposes chart-friendly API response and parameter validation.- Monolog is used for operational visibility in price fetching, valuation, and snapshot persistence flow.
- @todo Add health/readiness endpoint for deployment probes and upstream dependency visibility.
- @todo Add structured metrics (e.g. snapshot success/failure counters, Binance latency) for observability dashboards.
Run tests:
php bin/phpunitIncluded:
- Unit test for
PortfolioValuationServicetotal calculation logic.