A real-time data storage solution for Bitcoin price tracking using Redis TimeSeries, optimized for low-latency access and rolling data retention. The system supports multiple time resolutions and captures both price points and volatility metrics.
- Real-time price data storage at multiple resolutions (1min, 5min, 15min, 1hour)
- Automated data aggregation and retention policies
- Min/max price tracking for volatility analysis
- Efficient data storage with automatic cleanup
- Frequency: 1 entry per minute
- Retention: 60 entries (1 hour)
- Fields: price (latest BTC price)
- Frequency: 1 entry every 5 minutes
- Retention: 12 entries (1 hour)
- Fields: price (closing), min, max
- Frequency: 1 entry every 15 minutes
- Retention: 4 entries (1 hour)
- Fields: price (closing), min, max
- Frequency: 1 entry every hour
- Retention: 24 entries (1 day)
- Fields: price (closing), min, max
main.py: Entry point for the applicationsrc/: Source codeprice_service.py: Price data collection serviceredis_timeseries.py: Redis TimeSeries implementation
tests/: Test coderequirements.txt: Project dependenciesdocker-compose.yml: Docker configuration for Redisredis.conf: Redis configuration
- Python 3.x
- Redis with RedisTimeSeries module
- Docker (for running Redis)
- Docker and Docker Compose installed on your system
- A CoinMarketCap API key (set in .env file)
- Create a
.envfile in the project root with the following content:
API_KEY=your_coinmarketcap_api_key
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_PASSWORD=mypassword
Build and start the services:
docker compose up --build -dView the logs:
docker compose logs -fStop the services:
docker compose downRestart services:
docker compose restartRebuild a specific service (after code changes):
docker compose up -d --build price_tracker- Redis is accessible at
localhost:6379 - Redis password is set in the .env file
- The price tracker service will automatically start collecting data
To view the stored data, you can use:
- Redis CLI:
docker compose exec redis redis-cli -a mypassword - The included table viewer:
python table_viewer.py
- If the services fail to start, check the logs using
docker compose logs - Ensure all required environment variables are set in the .env file
- Verify your CoinMarketCap API key is valid