File size: 8,280 Bytes
fc115d5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | # π API Keys Setup Guide - Crypto News Aggregator
## π Required API Keys/Tokens
Here are the **exact environment variables** you need to provide:
```bash
# ββββββββββββββββββββββββββββββββββββββββββββββββββββ
# CRYPTO NEWS API KEYS
# ββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 1. CryptoPanic (OPTIONAL but recommended)
CRYPTOPANIC_TOKEN=
# 2. Reddit API (REQUIRED for social sentiment)
REDDIT_CLIENT_ID=
REDDIT_CLIENT_SECRET=
# 3. CryptoCompare (OPTIONAL but recommended)
CRYPTOCOMPARE_API_KEY=
```
---
## π Step-by-Step Setup Instructions
### **1. CryptoPanic API Token** (β οΈ OPTIONAL - Works without it!)
**Status:** OPTIONAL (public feed works without token)
**Free Tier:** Unlimited
**Cost:** FREE forever
**How to Get:**
1. Go to: https://cryptopanic.com/developers/api/
2. Click "Get Your Free API Token"
3. Sign up with email
4. Copy your token from the dashboard
5. Add to `.env`:
```bash
CRYPTOPANIC_TOKEN=your_token_here
```
**β οΈ NOTE:** The aggregator works WITHOUT this token using the public feed. Token gives you:
- Higher rate limits
- Access to more filters
- Priority support
**Skip this if you want - public feed is fine!**
---
### **2. Reddit API Credentials** (β
REQUIRED)
**Status:** REQUIRED (for social sentiment)
**Free Tier:** Unlimited (60 requests/min)
**Cost:** FREE
**How to Get:**
#### Step 1: Create Reddit App
1. Go to: https://www.reddit.com/prefs/apps
2. Scroll to bottom, click **"create another app..."**
3. Fill in the form:
- **name:** `DRL-Trading-Bot` (or any name)
- **App type:** Select **"script"**
- **description:** `Crypto news sentiment analysis`
- **about url:** (leave blank)
- **redirect uri:** `http://localhost:8080` (required but not used)
4. Click **"create app"**
#### Step 2: Get Credentials
After creating, you'll see:
```
βββββββββββββββββββββββββββββββββββββββ
β DRL-Trading-Bot β
β personal use script β
β β
β abc123def456 β β This is your CLIENT_ID
β β
β secret: xyz789abc123def456... β β This is your CLIENT_SECRET
βββββββββββββββββββββββββββββββββββββββ
```
#### Step 3: Add to .env
```bash
REDDIT_CLIENT_ID=abc123def456
REDDIT_CLIENT_SECRET=xyz789abc123def456
```
**Example:**
```bash
REDDIT_CLIENT_ID=p-jcoLKBynTLew
REDDIT_CLIENT_SECRET=gko_LXELoV07ZBNUXrvWZfzE3aI
```
---
### **3. CryptoCompare API Key** (β οΈ OPTIONAL)
**Status:** OPTIONAL (but recommended for verified news)
**Free Tier:** 100,000 calls/month (3,333/day)
**Cost:** FREE
**How to Get:**
1. Go to: https://min-api.cryptocompare.com/
2. Click **"Get Your Free API Key"**
3. Sign up with email
4. Verify email
5. Go to dashboard: https://www.cryptocompare.com/cryptopian/api-keys
6. Copy your API key
7. Add to `.env`:
```bash
CRYPTOCOMPARE_API_KEY=your_key_here
```
**Example:**
```bash
CRYPTOCOMPARE_API_KEY=a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6
```
---
## β
Final .env File
After getting all keys, your `.env` should have:
```bash
# ... existing keys ...
# Crypto News Aggregator
CRYPTOPANIC_TOKEN=your_cryptopanic_token_here # OPTIONAL
REDDIT_CLIENT_ID=your_reddit_client_id_here # REQUIRED
REDDIT_CLIENT_SECRET=your_reddit_secret_here # REQUIRED
CRYPTOCOMPARE_API_KEY=your_cryptocompare_key # OPTIONAL
```
---
## π― What Works Without API Keys?
### **Minimum Setup (Only Reddit - 1 source):**
```bash
# Only these 2 are REQUIRED:
REDDIT_CLIENT_ID=...
REDDIT_CLIENT_SECRET=...
```
**Result:**
- β
Reddit sentiment (30% weight)
- β οΈ No CryptoPanic (50% weight lost)
- β οΈ No CryptoCompare (20% weight lost)
- **Total coverage: 30%**
---
### **Recommended Setup (All 3 sources):**
```bash
CRYPTOPANIC_TOKEN=... # FREE, unlimited
REDDIT_CLIENT_ID=... # FREE, unlimited
REDDIT_CLIENT_SECRET=... # FREE, unlimited
CRYPTOCOMPARE_API_KEY=... # FREE, 100K/month
```
**Result:**
- β
CryptoPanic sentiment (50% weight)
- β
Reddit sentiment (30% weight)
- β
CryptoCompare sentiment (20% weight)
- **Total coverage: 100%**
---
## π Verification
After adding keys to `.env`, test them:
```bash
# Test the aggregator
python -c "from src.features.crypto_news_aggregator import CryptoNewsAggregator; agg = CryptoNewsAggregator('BTC'); print(agg.get_aggregated_sentiment())"
```
**Expected output:**
```
β
Reddit client initialized
π° CryptoPanic: 20 posts for BTC
π΄ Reddit: 15 posts for Bitcoin
π CryptoCompare: 30 articles for BTC
π° Aggregated sentiment [BTC]: π’ +0.34 (confidence=0.72, sources=3/3, trend=improving)
```
**If you see errors:**
- `Reddit initialization failed` β Check REDDIT_CLIENT_ID and REDDIT_CLIENT_SECRET
- `CryptoPanic error: 403` β Check CRYPTOPANIC_TOKEN (or remove it to use public feed)
- `CryptoCompare error: 401` β Check CRYPTOCOMPARE_API_KEY
---
## π API Limits Summary
| Source | Free Tier Limit | Enough for Trading? | Cost if Exceeded |
|--------|----------------|---------------------|------------------|
| **CryptoPanic** | Unlimited | β
Yes | FREE forever |
| **Reddit** | 60 req/min | β
Yes (we use ~1/hour) | FREE forever |
| **CryptoCompare** | 100K/month (3,333/day) | β
Yes (we use ~24/day) | $17/month for 500K |
**For hourly trading:**
- CryptoPanic: ~24 calls/day (cache: 5 min)
- Reddit: ~24 calls/day (cache: 5 min)
- CryptoCompare: ~24 calls/day (cache: 5 min)
**Total:** ~72 calls/day across all sources
---
## π¨ Troubleshooting
### Error: "praw.exceptions.ResponseException: received 401 HTTP response"
**Cause:** Reddit credentials are wrong
**Solution:**
1. Double-check `REDDIT_CLIENT_ID` and `REDDIT_CLIENT_SECRET`
2. Make sure you created a "script" app (not "web app")
3. Recreate the app if needed
---
### Error: "Reddit client not available"
**Cause:** `praw` library not installed
**Solution:**
```bash
pip install praw
```
---
### Error: "CryptoPanic error: 429"
**Cause:** Rate limit exceeded (unlikely with caching)
**Solution:**
1. Increase `cache_ttl` in `crypto_news_aggregator.py` to 600 (10 min)
2. Get API token to increase limits
---
### Warning: "Reddit credentials not set - using fallback"
**Cause:** Missing `REDDIT_CLIENT_ID` or `REDDIT_CLIENT_SECRET`
**Solution:**
1. Add both variables to `.env`
2. Restart the application
---
## β
Quick Test Checklist
Run these commands to verify everything works:
```bash
# 1. Check .env file
cat .env | grep -E "REDDIT|CRYPTOPANIC|CRYPTOCOMPARE"
# Should output:
# REDDIT_CLIENT_ID=...
# REDDIT_CLIENT_SECRET=...
# CRYPTOPANIC_TOKEN=...
# CRYPTOCOMPARE_API_KEY=...
# 2. Test Reddit
python -c "import praw; r = praw.Reddit(client_id='YOUR_ID', client_secret='YOUR_SECRET', user_agent='test'); print('β
Reddit OK')"
# 3. Test CryptoPanic
curl "https://cryptopanic.com/api/v1/posts/?public=true¤cies=BTC" | head -20
# 4. Test CryptoCompare
curl "https://min-api.cryptocompare.com/data/v2/news/?categories=BTC" | head -20
# 5. Test full aggregator
python test_crypto_news.py
```
---
## π Summary
**Exact variables you need to add to `.env`:**
```bash
# REQUIRED (Reddit)
REDDIT_CLIENT_ID=your_reddit_app_client_id
REDDIT_CLIENT_SECRET=your_reddit_app_client_secret
# OPTIONAL (CryptoPanic - works without it)
CRYPTOPANIC_TOKEN=your_cryptopanic_token
# OPTIONAL (CryptoCompare - recommended)
CRYPTOCOMPARE_API_KEY=your_cryptocompare_key
```
**Next step:** Get these keys and add them to `.env`, then run the test!
---
## π Quick Links
- **Reddit Apps:** https://www.reddit.com/prefs/apps
- **CryptoPanic API:** https://cryptopanic.com/developers/api/
- **CryptoCompare API:** https://min-api.cryptocompare.com/
---
**Questions?** Run the test script and check the output:
```bash
python test_crypto_news.py
```
The script will tell you exactly which keys are missing!
|