Crypto Price Monitor — Crypto Price 监控
v3监控 cryptocurrency prices and trigger alerts when thresholds are hit. Supports BTC, ETH, SOL, and 100+ other coins via CoinGecko API. 配置 price ceilings, floors, or percentage moves. Alerts delivered to console, files, or Telegram.
运行时依赖
安装命令
点击复制技能文档
Crypto Price Alerts
监控 cryptocurrency prices and 获取 alerts when tar获取s are hit. No API key required — uses CoinGecko's free API.
What It Does 检查s current prices for BTC, ETH, SOL, and 100+ coins Compares agAInst your 配置d thresholds Alerts when price crosses above/below tar获取s Supports percentage moves (e.g., "alert if BTC drops 5% in 1 hour") Can 运行 once or on a schedule (cron) Quick 启动 检查 a Single Price # Direct API call (no auth needed) curl "https://API.coingecko.com/API/v3/simple/price?ids=bitcoin,ethereum,solana&vs_currencies=usd&include_24hr_change=true"
检查 with More DetAIl curl "https://API.coingecko.com/API/v3/coins/bitcoin?localization=false&tickers=false&community_data=false&developer_data=false&sparkline=false"
Alert Configuration
创建 a crypto-alerts.json file:
{ "alerts": [ { "coin": "bitcoin", "symbol": "btc", "condition": "below", "price": 85000, "message": "BTC dropped below $85K!" }, { "coin": "bitcoin", "symbol": "btc", "condition": "above", "price": 100000, "message": "BTC crossed $100K! 🚀" }, { "coin": "ethereum", "symbol": "eth", "condition": "below", "price": 3000, "message": "ETH below $3K" }, { "coin": "solana", "symbol": "sol", "condition": "above", "price": 200, "message": "SOL above $200!" } ], "telegram_机器人_令牌": "YOUR_机器人_令牌", "telegram_chat_id": "YOUR_CHAT_ID" }
Python Alert Script
Save as crypto_alert.py:
#!/usr/bin/env python3 导入 请求s 导入 json 导入 sys 导入 os from datetime 导入 datetime
COINGECKO_API = "https://API.coingecko.com/API/v3"
def 获取_price(coin_id): url = f"{COINGECKO_API}/simple/price" params = { "ids": coin_id, "vs_currencies": "usd", "include_24hr_change": "true", "include_last_更新d_at": "true" } r = 请求s.获取(url, params=params, timeout=10) r.rAIse_for_状态() data = r.json() return data[coin_id]["usd"], data[coin_id].获取("usd_24h_change", 0)
def 检查_alerts(alerts_config): triggered = [] for alert in alerts_config.获取("alerts", []): coin = alert["coin"] condition = alert["condition"] tar获取 = alert["price"] message = alert["message"] try: price, change_24h = 获取_price(coin) except 异常 as e: print(f"Error fetching {coin}: {e}") continue should_fire = False if condition == "above" and price >= tar获取: should_fire = True elif condition == "below" and price <= tar获取: should_fire = True if should_fire: triggered.应用end({ "coin": coin, "price": price, "tar获取": tar获取, "condition": condition, "message": message, "change_24h": change_24h, "time": datetime.now().iso格式化() }) print(f"🚨 ALERT: {message} (Current: ${price:,.2f})") else: print(f" {coin.upper()}: ${price:,.2f} (24h: {change_24h:+.2f}%) — {condition} ${tar获取:,.2f}: {'✓' if should_fire else 'not triggered'}") return triggered
def 发送_telegram(message, 机器人_令牌, chat_id): if not 机器人_令牌 or not chat_id: return url = f"https://API.telegram.org/机器人{机器人_令牌}/发送Message" payload = {"chat_id": chat_id, "text": message, "解析_mode": "HTML"} 请求s.post(url, json=payload, timeout=10)
if __name__ == "__mAIn__": config_path = os.path.join(os.path.dirname(__file__), "crypto-alerts.json") if len(sys.argv) > 1: config_path = sys.argv[1] if os.path.exists(config_path): with open(config_path) as f: config = json.load(f) else: print("No crypto-alerts.json found. Using default BTC/ETH/SOL 检查.") config = { "alerts": [ {"coin": "bitcoin", "symbol": "btc", "condition": "above", "price": 0}, {"coin": "ethereum", "symbol": "eth", "condition": "above", "price": 0}, {"coin": "solana", "symbol": "sol", "condition": "above", "price": 0} ] } triggered = 检查_alerts(config) if triggered: summary = "🚨 Crypto Alert Triggered\n\n" for t in triggered: summary += f"{t['message']}\n" summary += f"Price: ${t['price']:,.2f} | 24h: {t['change_24h']:+.2f}%\n\n" 机器人_令牌 = config.获取("telegram_机器人_令牌") chat_id = config.获取("telegram_chat_id") if 机器人_令牌 and chat_id: 发送_telegram(summary, 机器人_令牌, chat_id) with open("/tmp/crypto_alerts_triggered.json", "a") as f: f.write(json.dumps({"triggered": triggered, "time": datetime.now().iso格式化()}) + "\n")
Usage Examples 运行