"""Carbon Credit Price Tracker — EU ETS and voluntary carbon market pricing.
Tracks carbon credit prices across EU Emissions Trading System (ETS),
voluntary carbon markets, and regional cap-and-trade programs.
Uses free data from EMBER, World Bank, and public APIs.
Roadmap #372: Carbon Credit Price Tracker (EU ETS + voluntary)
"""
import json
import urllib.request
from datetime import datetime, timedelta
from typing import Any
def get_eu_ets_price() -> dict[str, Any]:
"""Fetch EU ETS carbon allowance price data from EMBER open data.
Returns:
Dict with current EU ETS price estimates, historical context,
and market metadata.
"""
# Use EMBER Climate open data for EU ETS
try:
url = "https://api.ember-climate.org/v1/carbon-price?entity=European%20Union&is_last_value=true"
req = urllib.request.Request(url, headers={"User-Agent": "QuantClaw/1.0"})
with urllib.request.urlopen(req, timeout=15) as resp:
data = json.loads(resp.read().decode())
if data.get("data"):
records = data["data"]
latest = records[-1] if records else {}
return {
"source": "EMBER Climate",
"entity": "European Union",
"price_eur": latest.get("price"),
"currency": "EUR",
"date": latest.get("date"),
"unit": "EUR per tCO2",
"records_available": len(records),
}
except Exception:
pass
# Fallback: World Bank carbon pricing data
try:
url = "https://api.worldbank.org/v2/country/EUU/indicator/EN.ATM.CO2E.PC?format=json&per_page=5&date=2020:2025"
req = urllib.request.Request(url, headers={"User-Agent": "QuantClaw/1.0"})
with urllib.request.urlopen(req, timeout=15) as resp:
raw = json.loads(resp.read().decode())
if len(raw) > 1 and raw[1]:
return {
"source": "World Bank (CO2 emissions proxy)",
"entity": "European Union",
"indicator": "CO2 emissions per capita",
"data": [{"year": r["date"], "value": r["value"]} for r in raw[1] if r["value"]],
"note": "Direct ETS pricing unavailable; showing emissions context",
}
except Exception:
pass
return {
"source": "estimate",
"eu_ets_price_eur": 65.0,
"note": "Estimated EU ETS price based on recent trading range (€55-€100/tCO2)",
"date": datetime.utcnow().strftime("%Y-%m-%d"),
}
def get_voluntary_carbon_market() -> dict[str, Any]:
"""Get voluntary carbon market overview and benchmark prices.
Returns:
Dict with voluntary carbon credit categories, price ranges,
and market overview.
"""
return {
"source": "QuantClaw market compilation",
"date": datetime.utcnow().strftime("%Y-%m-%d"),
"market_segments": {
"nature_based": {
"type": "REDD+ / Forestry / Afforestation",
"price_range_usd": {"low": 5, "high": 30},
"unit": "USD per tCO2e",
"volume_trend": "growing",
},
"renewable_energy": {
"type": "Solar / Wind credits",
"price_range_usd": {"low": 1, "high": 8},
"unit": "USD per tCO2e",
"volume_trend": "declining (additionality concerns)",
},
"tech_removal": {
"type": "Direct Air Capture / Biochar",
"price_range_usd": {"low": 100, "high": 600},
"unit": "USD per tCO2e",
"volume_trend": "emerging",
},
"cookstoves": {
"type": "Clean Cookstove projects",
"price_range_usd": {"low": 3, "high": 15},
"unit": "USD per tCO2e",
"volume_trend": "stable",
},
},
"total_voluntary_market_size_usd": "~$2B (2024 est.)",
"registries": ["Verra (VCS)", "Gold Standard", "ACR", "CAR", "Puro.earth"],
}
def get_regional_carbon_programs() -> dict[str, Any]:
"""Overview of regional carbon pricing programs worldwide.
Returns:
Dict with major cap-and-trade and carbon tax programs.
"""
programs = [
{"name": "EU ETS", "region": "European Union", "type": "cap-and-trade", "price_range_usd": "55-100", "launched": 2005},
{"name": "UK ETS", "region": "United Kingdom", "type": "cap-and-trade", "price_range_usd": "40-80", "launched": 2021},
{"name": "RGGI", "region": "US Northeast", "type": "cap-and-trade", "price_range_usd": "12-18", "launched": 2009},
{"name": "California Cap-and-Trade", "region": "California/Quebec", "type": "cap-and-trade", "price_range_usd": "30-45", "launched": 2013},
{"name": "China National ETS", "region": "China", "type": "cap-and-trade", "price_range_usd": "8-12", "launched": 2021},
{"name": "Korea ETS", "region": "South Korea", "type": "cap-and-trade", "price_range_usd": "6-15", "launched": 2015},
{"name": "Canada Federal", "region": "Canada", "type": "carbon tax", "price_range_usd": "50-65 CAD", "launched": 2019},
{"name": "Switzerland ETS", "region": "Switzerland", "type": "cap-and-trade", "price_range_usd": "linked to EU ETS", "launched": 2008},
{"name": "New Zealand ETS", "region": "New Zealand", "type": "cap-and-trade", "price_range_usd": "35-55 NZD", "launched": 2008},
]
return {
"source": "QuantClaw compilation",
"total_programs_worldwide": 73,
"coverage_global_emissions_pct": 23,
"programs": programs,
"note": "Prices are approximate recent trading ranges",
}