监控加密货币价格并在达到阈值时触发警报。支持 BTC、ETH、SOL 及 100 多种其他币种,使用 CoinGecko API。可配置价格上限和下限阈值。
加密价格警报 : 监控加密货币价格, 并在目标被击中时获得警告
功能概述
加密价格警报 : 监控加密货币价格, 并在目标被击中时获得警告是一项面向实际任务的技能,主要用于不需要 API 键, 使用 CoinGecko 的 API;检查 BTC 、 EH 、 SOL 和 SOL 的当前价格。
核心要点
- 它将相关步骤、工具调用和结果整理方式集中到统一流程中,帮助使用者更快完成目标并减少重复操作。
- 使用时应结合输入条件选择合适的执行方式,核对必要参数、依赖环境与输出内容,并按原始要求处理异常情况。
- 该技能适合需要稳定复用相关能力的场景,可作为自动化工作流的一部分,也便于后续检查、调整和扩展。
使用与执行
从功能定位来看,该技能强调把分散的操作要求整理成清晰、可复用的处理流程,使用户能够围绕既定目标快速准备输入、选择执行方式并获得结构化结果。实际使用前应先确认任务范围、数据来源、运行环境、必要权限和关键参数,再依据技能说明逐步执行;
结果检查与注意事项
若输入条件不完整,应先补齐信息或采用保守配置,避免因错误假设导致结果偏离需求。执行过程中需要关注工具调用是否成功、接口或依赖是否可用、输出格式是否符合预期,并对异常提示、缺失字段和边界情况进行处理;涉及批量任务时,还应保存进度,避免中断后重复操作。
加密货币价格提醒
监控加密货币价格,并在达到设定目标时接收提醒。无需 API 密钥 —— 使用 CoinGecko 的免费 API。
功能说明
- 查询 BTC、ETH、SOL 及 100+ 种代币的当前价格
- 与您配置的阈值进行比对
- 当价格上穿/下破目标值时触发提醒
- 支持百分比变动检测(例如:“若 BTC 在 1 小时内下跌 5%,则发出提醒”)
- 可单次运行,也可按计划(cron)定时执行
快速开始
查询单个价格
# 直接调用 API(无需认证) curl "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum,solana&vs_currencies=usd&include_24hr_change=true"
获取更详细信息
curl "https://api.coingecko.com/api/v3/coins/bitcoin?localization=false&tickers=false&community_data=false&developer_data=false&sparkline=false"
提醒配置
创建一个 crypto-alerts.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!"
}
],
"telegram_bot_token": "YOUR_BOT_TOKEN",
"telegram_chat_id": "YOUR_CHAT_ID"
}
Python 提醒脚本
保存为 crypto_alert.py:
#!/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 get_price(coin_id):
url = f"{COINGECKO_API}/simple/price"
params = {
"ids": coin_id,
"vs_currencies": "usd",
"include_24hr_change": "true",
"include_last_updated_at": "true"
}
r = requests.get(url, params=params, timeout=10)
r.raise_for_status()
data = r.json()
return data[coin_id]["usd"], data[coin_id].get("usd_24h_change", 0)
def check_alerts(alerts_config):
triggered = []
for alert in alerts_config.get("alerts", []):
coin = alert["coin"]
condition = alert["condition"]
target = alert["price"]
message = alert["message"]
try:
price, change_24h = get_price(coin)
except Exception as e:
print(f"Error fetching {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,
"change_24h": change_24h,
"time": datetime.now().isoformat()
})
print(f"🚨 ALERT: {message} (Current: ${price:,.2f})")
else:
print(f" {coin.upper()}: ${price:,.2f} (24h: {change_24h:+.2f}%) — {condition} ${target:,.2f}: {'✓' if should_fire else 'not triggered'}")
return triggered
def send_telegram(message, bot_token, chat_id):
if not bot_token or not chat_id:
return
url = f"https://api.telegram.org/bot{bot_token}/sendMessage"
payload = {"chat_id": chat_id, "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("No crypto-alerts.json found. Using default BTC/ETH/SOL check.")
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 = "🚨 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"
bot_token = config.get("telegram_bot_token")
chat_id = config.get("telegram_chat_id")
if bot_token and chat_id:
send_telegram(summary, bot_token, chat_id)
with open("/tmp/crypto_alerts_triggered.json", "a") as f:
f.write(json.dumps({"triggered": triggered, "time": datetime.now().isoformat()}) + "\n")
使用示例
单次运行
python3 crypto_alert.py
定时运行(Cron)
# 每 15 分钟执行一次 */15 * * * * cd /path/to/skill && python3 crypto_alert.py >> /tmp/crypto_alerts.log 2>&1 # 每小时第 0 分钟执行一次 0 * * * * cd /path/to/skill && python3 crypto_alert.py >> /tmp/crypto_alerts.log 2>&1
查询特定代币
# Bitcoin curl "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd&include_24hr_change=true" # 多个代币 curl "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum,solana,cardano,polkadot,avalanche-2,chainlink&vs_currencies=usd&include_24hr_change=true"
支持的代币(常用 ID)
| 符号 | CoinGecko ID |
|---|---|
| BTC | bitcoin |
| ETH | ethereum |
| SOL | solana |
| ADA | cardano |
| DOT | polkadot |
| AVAX | avalanche-2 |
| LINK | chainlink |
| XRP | ripple |
| DOGE | dogecoin |
| MATIC | polygon |
| ARB | arbitrum |
| OP | optimism |
完整列表请访问:curl https://api.coingecko.com/api/v3/coins/list?per_page=250
提醒条件
above— 当价格 >= 目标值时触发below— 当价格 <= 目标值时触发percent_up— 当 24 小时涨跌幅 > X% 时触发(需添加percent_threshold字段)percent_down— 当 24 小时涨跌幅 < -X% 时触发(需添加percent_threshold字段)
速率限制
CoinGecko 免费 API 限制:
- 约 10–30 次请求/分钟
- 每月 10,000–50,000 次请求
- 如需高频检查,请启用缓存
- 为确保安全,可在请求之间添加
sleep(1.2)
依赖要求
requestsPython 库(pip install requests)- CoinGecko API(免费,无需密钥)
- 可选:Telegram Bot 用于推送通知
- 可选:cron 实现定时监控
使用建议
- 避免频繁轮询 —— 对大多数场景而言,15 分钟间隔已足够
- 缓存价格数据 —— 保存上次检查结果,避免重复调用 API
- 支持多重条件 —— 同一代币可同时配置多个提醒(例如“上穿”和“下破”)
- 记录日志 —— 务必写入日志文件,便于后续回溯触发事件
基于真实加密货币监控实践构建。CoinGecko API 免费开放,但请合理、尊重地使用。
热门AI工具
相关专题
本专题介绍Gradle插件开发的基本流程,涵盖插件类编写、自定义任务注册、扩展参数设计和插件应用方法,帮助你理解插件如何组织构建逻辑,减少多个项目之间的重复配置。
0
2026.10.22
本专题介绍Gradle Wrapper的基本作用,涵盖文件组成、生成方法、版本配置和任务调用,帮助你理解项目如何使用指定的Gradle版本,减少不同开发环境带来的构建差异。
0
2026.10.22
本专题整理Golangci-lint常用Linters的用途与配置方法,覆盖错误处理、无效代码、安全、复杂度、命名和依赖检查,帮助项目合理选规则。
0
2026.10.22
本专题介绍Gradle Java项目构建方法,涵盖Java插件配置、依赖声明、源码编译、测试执行和打包检查,帮助你理解各阶段的任务关系,逐步完成项目构建。
0
2026.10.22
本专题汇总PHP常见时间戳漏洞,包括2038年溢出、时区漂移、时间戳伪造、重放攻击、时间盲注与日志审计失效等,并给出升级64位环境、使用 DateTimeImmutable、统一UTC、严格超时校验、预处理绑定、hash_equals 比对等修复方案,帮助开发者快速排查和加固时间相关代码。
0
2026.10.22
本专题聚焦Golangci-lint YAML配置文件,讲清运行参数、规则启停、目录排除、问题过滤及严重级别设置,便于团队统一检查标准。
0
2026.10.22
本专题讲解Golangci-lint的安装、初始化、基础命令和首次代码检查,覆盖本地环境、Docker及多平台用法,帮助Go开发者快速上手。
0
2026.10.22
PHP2Shell漏洞是什么,哪些PHP版本和运行环境会受到影响,服务器应该如何检测与修复?本专题提供版本自查脚本、Linux与Docker升级命令、PHP-FPM和Apache排查步骤,以及修复验证、临时缓解和应急响应方案。
0
2026.10.22
热门下载
相关下载
精品课程
共6课时 | 12.1万人学习
共79课时 | 161.5万人学习
共6课时 | 54.7万人学习
