Monitor cryptocurrency prices and trigger alerts when thresholds are hit. Supports BTC, ETH, SOL, and 100+ other coins via CoinGecko API. Configure price ceilings, floors, or percentage moves. Alerts delivered to console, files, or Telegram.
监控加密货币价格,并在达到目标时获取提醒。无需API密钥——使用CoinGecko的免费API。
bash
bash
curl https://api.coingecko.com/api/v3/coins/bitcoin?localization=false&tickers=false&communitydata=false&developerdata=false&sparkline=false
创建crypto-alerts.json文件:
json
{
alerts: [
{
coin: bitcoin,
symbol: btc,
condition: below,
price: 85000,
message: BTC跌破$85K!
},
{
coin: bitcoin,
symbol: btc,
condition: above,
price: 100000,
message: BTC突破$100K!🚀
},
{
coin: ethereum,
symbol: eth,
condition: below,
price: 3000,
message: ETH低于$3K
},
{
coin: solana,
symbol: sol,
condition: above,
price: 200,
message: SOL突破$200!
}
],
telegrambottoken: YOURBOTTOKEN,
telegramchatid: YOURCHATID
}
保存为crypto_alert.py:
python
#!/usr/bin/env python3
import requests
import json
import sys
import os
from datetime import datetime
COINGECKO_API = https://api.coingecko.com/api/v3
def getprice(coinid):
url = f{COINGECKO_API}/simple/price
params = {
ids: coin_id,
vs_currencies: usd,
include24hrchange: true,
includelastupdated_at: true
}
r = requests.get(url, params=params, timeout=10)
r.raiseforstatus()
data = r.json()
return data[coinid][usd], data[coinid].get(usd24hchange, 0)
def checkalerts(alertsconfig):
triggered = []
for alert in alerts_config.get(alerts, []):
coin = alert[coin]
condition = alert[condition]
target = alert[price]
message = alert[message]
try:
price, change24h = getprice(coin)
except Exception as e:
print(f获取{coin}数据出错:{e})
continue
should_fire = False
if condition == above and price >= target:
should_fire = True
elif condition == below and price <= target:
should_fire = True
if should_fire:
triggered.append({
coin: coin,
price: price,
target: target,
condition: condition,
message: message,
change24h: change24h,
time: datetime.now().isoformat()
})
print(f🚨 提醒:{message}(当前价:${price:,.2f}))
else:
print(f {coin.upper()}:${price:,.2f}(24小时:{change24h:+.2f}%)— {condition} ${target:,.2f}:{✓ if shouldfire else 未触发})
return triggered
def sendtelegram(message, bottoken, chat_id):
if not bottoken or not chatid:
return
url = fhttps://api.telegram.org/bot{bot_token}/sendMessage
payload = {chatid: chatid, text: message, parse_mode: HTML}
requests.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(未找到crypto-alerts.json。使用默认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 = check_alerts(config)
if triggered:
summary = 🚨 加密货币提醒已触发\n\n
for t in triggered:
summary += f{t[message]}\n
summary += f价格:${t[price]:,.2f} | 24小时:{t[change_24h]:+.2f}%\n\n
bottoken = config.get(telegrambot_token)
chatid = config.get(telegramchat_id)
if bottoken and chatid:
sendtelegram(summary, bottoken, chat_id)
with open(/tmp/cryptoalertstriggered.json, a) as f:
f.write(json.dumps({triggered: triggered, time: datetime.now().isoformat()}) + \n)
| 符号 | CoinGecko ID |
|---|---|
| BTC | bitcoin |
| ETH |
完整列表:curl https://api.coingecko.com/api/v3/coins/list?per_page=250
CoinGecko免费API:
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 crypto-price-monitor-1775974561 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 crypto-price-monitor-1775974561 技能
skillhub install crypto-price-monitor-1775974561
文件大小: 4.88 KB | 发布时间: 2026-4-13 09:56