LunarCrush FreqTrade External Data Provider
A professional-grade external data provider that integrates LunarCrush sentiment data with FreqTrade for cryptocurrency trading strategies.
Overview
This provider fetches real-time cryptocurrency sentiment and social metrics from the LunarCrush API and makes them available to FreqTrade strategies. It includes advanced features like intelligent caching, timeframe conversion, and robust error handling.
Features
- ✅ 22 Sentiment & Market Data Fields - Complete coverage including social dominance, galaxy scores, and market metrics
- ✅ Intelligent Caching - Efficient data storage with configurable cache management
- ✅ Timeframe Conversion - Automatic conversion between different timeframes (1m to 1M)
- ✅ Robust Error Handling - Graceful degradation and comprehensive logging
- ✅ Professional Testing - 100% test coverage with 32 passing tests
- ✅ Production Ready - Clean architecture with proper separation of concerns
Quick Start
1. Setup
# In your FreqTrade strategy
from lunarcrush import get_lunarcrush_provider
def __init__(self, config: dict):
super().__init__(config)
# Initialize LunarCrush provider
bearer_token = os.environ.get('LUNARCRUSH_BEARER_TOKEN')
if bearer_token:
self.lunarcrush_provider = get_lunarcrush_provider(bearer_token)
2. Environment Variables
export LUNARCRUSH_BEARER_TOKEN="your_api_token_here"
3. Basic Usage
def feature_engineering_expand_all(self, dataframe, period, metadata):
if self.lunarcrush_provider:
# Get sentiment features
sentiment_df = self.lunarcrush_provider.get_sentiment_features(
pair=metadata['pair'],
timeframe=metadata['tf'],
since_ms=int(dataframe['date'].iloc[0].timestamp() * 1000)
)
# Merge with price data
if not sentiment_df.empty:
dataframe = pd.concat([dataframe, sentiment_df], axis=1)
return dataframe
Available Data Fields
Sentiment Metrics
lc_sentiment- Overall sentiment score (-1 to 1)lc_sentiment_absolute- Absolute sentiment strengthlc_sentiment_relative- Relative sentiment vs marketlc_social_dominance- Social media dominance percentagelc_social_volume- Total social media mentionslc_galaxy_score- LunarCrush proprietary score (0-100)
Market Data
lc_circulating_supply- Circulating token supplylc_market_cap- Market capitalizationlc_market_dominance- Market dominance percentagelc_volume_24h- 24-hour trading volume
Community Metrics
lc_contributors_active- Active social contributorslc_interactions- Social media interactionslc_posts_active- Active posts count
Ranking Data
lc_alt_rank- Alternative ranklc_market_cap_rank- Market cap ranklc_correlation_rank- Price correlation rank
Plus additional technical indicators and scores
Configuration
provider = get_lunarcrush_provider(
bearer_token="your_token",
cache_dir="lunarcrush/data", # Cache location
update_interval_hours=1, # Update frequency
max_cache_age_days=30 # Cache retention
)
Supported Timeframes
All standard FreqTrade timeframes:
- Intraday:
1m,3m,5m,15m,30m,1h,4h,12h - Daily+:
1d,3d,1w,2w,1M
Architecture
graph LR
A[FreqTrade Strategy] --> B[LunarCrush Provider]
B --> C[LunarCrush API]
B --> D[Cache System + Converter]
Test Coverage:
- ✅ 32 tests passed (100% success rate)
- ⏭️ 4 tests skipped (external dependencies)
- 🧪 Covers all core functionality, edge cases, and integrations
Test Categories
- Converter Tests - Field extraction, timeframe conversion, NaN handling
- Provider Tests - API integration, caching, datetime compatibility
- Strategy Integration - End-to-end workflow validation
Troubleshooting
Common Issues
-
Empty Data Returns
- Verify
LUNARCRUSH_BEARER_TOKENis set correctly - Check that the cryptocurrency is supported by LunarCrush
- Ensure sufficient API credits remain
- Verify
-
Cache Issues
- Clear cache:
rm -rf data/ - Check disk space and permissions
- Clear cache:
-
Timeframe Errors
- Verify timeframe format (e.g.,
'1h','4h','1d') - Check that requested timeframe is supported
- Verify timeframe format (e.g.,
Debug Mode
Enable verbose logging:
import logging
logging.getLogger('lunarcrush').setLevel(logging.DEBUG)
API Limits
- Rate Limit: 10 requests/minute, 2000 requests/day
- Caching: Automatic to minimize API usage
- Backoff: Smart retry logic for rate limit handling
License
This external data provider is designed for use with FreqTrade and requires a valid LunarCrush API subscription.
Metadata
Release files for lunarcrush-provider 1.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lunarcrush_provider-1.0.6.tar.gz | 26.1 kB | Without provenance | Details for lunarcrush_provider-1.0.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lunarcrush_provider-1.0.6-py3-none-any.whl | Python 3 | none | any | Details for lunarcrush_provider-1.0.6-py3-none-any.whl |
Total release size: 44.9 kB
Release files / lunarcrush_provider-1.0.6.tar.gz
| Download URL | lunarcrush_provider-1.0.6.tar.gz |
|---|---|
| Size | 26.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6cfbc31763211ad86199d9188a36e97fb2514243e14259592c4da4412d0a73c2
|
|
BLAKE2b-256 checksum How to use checksums |
61a1b23b4d814862b039f705ea00c66094d43a15b3856b132441afadf66790a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / lunarcrush_provider-1.0.6-py3-none-any.whl
| Download URL | lunarcrush_provider-1.0.6-py3-none-any.whl |
|---|---|
| Size | 18.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bcfc6e0adec0655861a4cb7beef9e3b69295ecbf043e00645169044aa7e3dd3a
|
|
BLAKE2b-256 checksum How to use checksums |
b45f9e6e5fffd145fa1233e88fe079def46d5c4b2a99b933e3bf7bb39c8b7644
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for lunarcrush-provider 1.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.