Copy #!/usr/bin/env python3
"""
Mining Profitability Calculator for Clore.ai GPU Rental.
Usage:
python mining_calculator.py --api-key YOUR_API_KEY [--gpu RTX 4090] [--coin KAS]
"""
import argparse
import requests
from typing import Dict, List, Optional
from dataclasses import dataclass
# === GPU Hashrates Database ===
GPU_HASHRATES = {
"RTX 4090": {"kawpow": 75, "kheavyhash": 1100, "blake3": 3500, "etchash": 130, "power": 350},
"RTX 4080": {"kawpow": 55, "kheavyhash": 800, "blake3": 2800, "etchash": 100, "power": 280},
"RTX 3090": {"kawpow": 60, "kheavyhash": 900, "blake3": 2500, "etchash": 120, "power": 300},
"RTX 3080": {"kawpow": 50, "kheavyhash": 750, "blake3": 2000, "etchash": 100, "power": 250},
"RTX 3070": {"kawpow": 32, "kheavyhash": 500, "blake3": 1500, "etchash": 62, "power": 180},
"A100": {"kawpow": 80, "kheavyhash": 1300, "blake3": 4000, "etchash": 150, "power": 400},
"A6000": {"kawpow": 52, "kheavyhash": 850, "blake3": 2600, "etchash": 100, "power": 300},
}
# === Coin Configurations ===
COINS = {
"KAS": {"algo": "kheavyhash", "name": "Kaspa", "block_reward": 200, "block_time": 1},
"RVN": {"algo": "kawpow", "name": "Ravencoin", "block_reward": 2500, "block_time": 60},
"ETC": {"algo": "etchash", "name": "Ethereum Classic", "block_reward": 2.56, "block_time": 13},
"ALPH": {"algo": "blake3", "name": "Alephium", "block_reward": 1.8, "block_time": 16},
}
@dataclass
class ProfitResult:
gpu: str
coin: str
hashrate: float
revenue_day: float
rental_cost_day: float
profit_day: float
profit_percent: float
class MiningCalculator:
"""Mining profitability calculator."""
CLORE_URL = "https://api.clore.ai"
def __init__(self, api_key: str):
self.api_key = api_key
def get_clore_prices(self) -> Dict[str, float]:
"""Get cheapest spot prices from Clore.ai."""
try:
response = requests.get(
f"{self.CLORE_URL}/v1/marketplace",
headers={"auth": self.api_key},
timeout=30
)
data = response.json()
if data.get("code") != 0:
return {}
prices = {}
for server in data.get("servers", []):
if server.get("rented"):
continue
gpu_array = server.get("gpu_array", [])
if not gpu_array:
continue
gpu = self._normalize_gpu(gpu_array[0])
spot_price = server.get("price", {}).get("usd", {}).get("spot")
if gpu and spot_price:
if gpu not in prices or spot_price < prices[gpu]:
prices[gpu] = spot_price
return prices
except Exception as e:
print(f"Error fetching Clore prices: {e}")
return {}
def _normalize_gpu(self, name: str) -> Optional[str]:
"""Normalize GPU name."""
name_lower = name.lower()
for gpu in GPU_HASHRATES:
if gpu.lower().replace(" ", "") in name_lower.replace(" ", ""):
return gpu
return None
def get_crypto_prices(self) -> Dict[str, float]:
"""Get crypto prices from CoinGecko."""
try:
ids = "kaspa,ravencoin,ethereum-classic,alephium"
response = requests.get(
f"https://api.coingecko.com/api/v3/simple/price?ids={ids}&vs_currencies=usd",
timeout=10
)
data = response.json()
return {
"KAS": data.get("kaspa", {}).get("usd", 0),
"RVN": data.get("ravencoin", {}).get("usd", 0),
"ETC": data.get("ethereum-classic", {}).get("usd", 0),
"ALPH": data.get("alephium", {}).get("usd", 0),
}
except Exception as e:
print(f"Error fetching crypto prices: {e}")
return {}
def estimate_daily_revenue(self, gpu: str, coin: str, crypto_price: float) -> float:
"""Estimate daily mining revenue."""
if gpu not in GPU_HASHRATES or coin not in COINS:
return 0
coin_config = COINS[coin]
algo = coin_config["algo"]
hashrate = GPU_HASHRATES[gpu].get(algo, 0)
if hashrate == 0:
return 0
# Simplified revenue estimation
# In reality, this depends on network difficulty
estimated_network_shares = {
"KAS": 0.000001, # Very rough estimates
"RVN": 0.00001,
"ETC": 0.000005,
"ALPH": 0.00001,
}
share = estimated_network_shares.get(coin, 0.00001)
blocks_per_day = 86400 / coin_config["block_time"]
# Coins per day (very simplified)
coins_day = share * hashrate * blocks_per_day * coin_config["block_reward"]
return coins_day * crypto_price
def calculate(self, gpu: str = None, coin: str = None) -> List[ProfitResult]:
"""Calculate profitability for all or specific combinations."""
clore_prices = self.get_clore_prices()
crypto_prices = self.get_crypto_prices()
if not clore_prices or not crypto_prices:
print("Failed to fetch prices")
return []
results = []
gpus = [gpu] if gpu else list(GPU_HASHRATES.keys())
coins = [coin] if coin else list(COINS.keys())
for g in gpus:
if g not in clore_prices:
continue
rental_hour = clore_prices[g]
rental_day = rental_hour * 24
for c in coins:
if c not in crypto_prices or crypto_prices[c] == 0:
continue
revenue = self.estimate_daily_revenue(g, c, crypto_prices[c])
if revenue == 0:
continue
profit = revenue - rental_day
profit_pct = (profit / rental_day * 100) if rental_day > 0 else 0
hashrate = GPU_HASHRATES[g].get(COINS[c]["algo"], 0)
results.append(ProfitResult(
gpu=g,
coin=c,
hashrate=hashrate,
revenue_day=revenue,
rental_cost_day=rental_day,
profit_day=profit,
profit_percent=profit_pct
))
# Sort by profit
results.sort(key=lambda x: x.profit_day, reverse=True)
return results
def print_report(self, results: List[ProfitResult]):
"""Print profitability report."""
print("\n" + "=" * 75)
print("π MINING PROFITABILITY CALCULATOR - Clore.ai GPU Rental")
print("=" * 75 + "\n")
profitable = [r for r in results if r.profit_day > 0]
unprofitable = [r for r in results if r.profit_day <= 0]
if profitable:
print("β
PROFITABLE COMBINATIONS (Daily):")
print("-" * 75)
print(f"{'GPU':<15} {'Coin':<6} {'Revenue':<12} {'Rental':<12} {'Profit':<12} {'ROI'}")
print("-" * 75)
for r in profitable:
emoji = "π’" if r.profit_percent > 20 else "π‘"
print(f"{emoji} {r.gpu:<13} {r.coin:<6} ${r.revenue_day:<10.2f} ${r.rental_cost_day:<10.2f} ${r.profit_day:<+10.2f} {r.profit_percent:+.1f}%")
else:
print("β No profitable combinations found at current prices.\n")
if unprofitable:
print(f"\nβ οΈ {len(unprofitable)} unprofitable combinations omitted.")
print("\n" + "=" * 75)
print("Note: These are estimates. Actual profits depend on network difficulty,")
print("pool fees, and market conditions. Always do your own research.")
print("=" * 75 + "\n")
def main():
parser = argparse.ArgumentParser(description="Mining Profitability Calculator")
parser.add_argument("--api-key", required=True, help="Clore.ai API key")
parser.add_argument("--gpu", help="Specific GPU model (e.g., 'RTX 4090')")
parser.add_argument("--coin", help="Specific coin (e.g., 'KAS')")
args = parser.parse_args()
calc = MiningCalculator(args.api_key)
results = calc.calculate(args.gpu, args.coin)
calc.print_report(results)
if __name__ == "__main__":
main()