Daten-Harvester
Das Krypto-Modul verwendet 3 Daten-Harvester, um Echtzeit-Informationen von externen APIs zu sammeln.
🏗️ Architektur
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ CoinGecko │ │ GitHub │ │ DefiLlama │
│ Harvester │ │ Harvester │ │ Harvester │
└──────┬───────┘ └──────┬───────┘ └──────┬───────┘
│ │ │
▼ ▼ ▼
┌─────────────────────────────────────────────────────────┐
│ Redis Cache │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ coingecko: │ │ github: │ │ defillama: │ │
│ │ SLUG │ │ REPO │ │ PROTOCOL │ │
│ │ TTL: 24h │ │ TTL: 24h │ │ TTL: 6h │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────┘
1. CoinGecko Harvester
Datei: coingecko.py
Zweck: Ruft Preis, Marktdaten und Metadaten ab.
Gesammelte Daten
| Feld | Beschreibung | Beispiel |
|---|---|---|
price_usd | Aktueller Preis in USD | 245.50 |
market_cap | Gesamte Marktkapitalisierung | 3,650,000,000 |
fdv | Vollständig verwässerte Bewertung | 4,100,000,000 |
price_change_24h | %-Änderung in 24 Stunden | -2.5 |
github_url | Haupt-Repository-URL | github.com/aave |
homepage | Projekt-Website | aave.com |
API Details
- Endpoint:
https://api.coingecko.com/api/v3/coins/ID - Rate Limit: 50 Anfragen/Minute (kostenlose Stufe)
- Cache TTL: 24 Stunden
- Kosten: Kostenlos
Verwendung
from harvesters.coingecko import CoinGeckoHarvester
harvester = CoinGeckoHarvester()
data = await harvester.fetch("aave")
# Returns:
{
"price_usd": 245.50,
"market_cap": 3650000000,
"fdv": 4100000000,
"github_url": "https://github.com/aave"
}
Bekannte Probleme
Veraltete GitHub URLs: CoinGecko gibt manchmal alte Repository-URLs zurück. Wir pflegen ein Überschreibungs-Mapping:
GITHUB_OVERRIDES = {
"aave": "https://github.com/aave/aave-v3-core",
"compound": "https://github.com/compound-finance/compound-v2",
}
2. GitHub Harvester
Datei: github.py
Zweck: Ruft Metriken zur Entwickleraktivität ab.
Gesammelte Daten
| Feld | Beschreibung | Beispiel |
|---|---|---|
commits_30d | Commits in den letzten 30 Tagen | 45 |
active_devs | Einzigartige Mitwirkende (30d) | 12 |
last_commit_date | Aktuellster Commit | 2025-12-25 |
total_stars | Repository-Sterne | 2,500 |
open_issues | Anzahl offener Issues | 48 |
API Details
- Endpoint:
https://api.github.com/repos/OWNER/REPO - Stats Endpoint:
https://api.github.com/repos/OWNER/REPO/stats/participation - Rate Limit: 5.000 Anfragen/Stunde (authentifiziert)
- Cache TTL: 24 Stunden
- Kosten: Kostenlos
Asynchrone Statistik-Verarbeitung
Große Repositories geben anfänglich 202 NO CONTENT zurück – Statistiken werden asynchron berechnet:
async def fetch_stats(self, repo):
response = await self.client.get(f"/repos/REPO/stats/participation")
if response.status_code == 202:
# GitHub is computing stats, retry after delay
await asyncio.sleep(2)
return await self.fetch_stats(repo)
return response.json()
Fallback für fehlende Repos
if not github_url or github_url == "":
return {
"commits_30d": 0,
"active_devs": 0,
"error": "No public repository found"
}
3. DefiLlama Harvester
Datei: defillama.py
Zweck: Ruft DeFi-spezifische Metriken (TVL, Treasury) ab.
Gesammelte Daten
| Feld | Beschreibung | Beispiel |
|---|---|---|
tvl | Total Value Locked (USD) | 32,400,000,000 |
chain_tvls | TVL breakdown by chain | ethereum: 25B, polygon: 5B |
category | DeFi category | "Lending" |
mcap_to_tvl_ratio | Market Cap / TVL | 0.09 |
API Details
- Endpoint:
https://api.llama.fi/protocol/SLUG - TVL History:
https://api.llama.fi/protocol/SLUG/tvl - Rate Limit: Unbegrenzt (kein Key erforderlich)
- Cache TTL: 6 Stunden (TVL ändert sich schneller)
- Kosten: Kostenlos ✅
Slug Mapping
DefiLlama verwendet andere Slugs als CoinGecko. Wir pflegen ein Mapping:
DEFILLAMA_SLUGS = {
"aave": "aave",
"uniswap": "uniswap",
"compound-governance-token": "compound",
}
Beispiel-Antwort
{
"tvl": 32451269361,
"chainTvls": {
"Ethereum": 25000000000,
"Polygon": 5000000000,
"Avalanche": 2451269361
},
"category": "Lending",
"mcap": 2900000000
}
🔄 Harvesting-Pipeline
Wenn ein Projekt angefragt wird, orchestriert der CryptoService alle Harvester:
async def fetch_project(self, slug: str):
# 1. Check cache first
cached = await self.cache.get(f"project:{slug}")
if cached:
return cached
# 2. Fetch from all sources in parallel
coingecko_data, github_data, defillama_data = await asyncio.gather(
self.coingecko.fetch(slug),
self.github.fetch(slug),
self.defillama.fetch(slug)
)
# 3. Merge data
project = self.merge_data(coingecko_data, github_data, defillama_data)
# 4. Calculate Trust Score
project["trust_score"] = self.risk_engine.calculate(project)
project["risk_level"] = self.risk_engine.get_risk_level(project["trust_score"])
# 5. Save to database
await self.db.upsert(project)
# 6. Cache for next request
await self.cache.set(f"project:{slug}", project, ttl=3600)
return project
⚡ Leistung
| Metrik | Neuer Abruf | Gecached |
|---|---|---|
| Gesamtzeit | 2-3 Sekunden | unter 50ms |
| CoinGecko | ~800ms | - |
| GitHub | ~1.2s | - |
| DefiLlama | ~500ms | - |
Cache Hit Rates
- CoinGecko: ~90%
- GitHub: ~85%
- DefiLlama: ~75%
🚀 Zukünftige Harvester (Geplant)
CryptoRank Harvester
- Data: Fundraising-Runden, VC-Investoren, Token-Freigaben
- Method: Web Scraping (keine kostenlose API)
- Purpose: Säule Tokenomics
TwitterScore Harvester
- Data: Follower-Qualität, Bot-Erkennung, Engagement
- Purpose: Säule Community
Discord/Telegram Harvester
- Data: Mitgliederzahl, Aktivität, Stimmung
- Purpose: Säule Community
Alle Harvester sind für den kostenlosen Betrieb unter Verwendung von kostenlosen API-Stufen konzipiert.