新增文件: - 数据源与交易品种完整手册_325个.md (100+加密品种 + 50+传统金融品种) - Go数据源集成方案.md (三级速率限制器 + 指数退避 + 自动降级) - 社交媒体实时情绪分析Go实现.md (VADER词典 + LLM增强) - scripts/verify_batch6_crypto_varieties.py (加密品种验证) - scripts/verify_batch7_fix.py (修复+新增验证) 验证统计: 325个端点通过, 19个平台, 100%免费
324 行
12 KiB
Python
324 行
12 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
批次7:修复失败项 + 新增更多品种
|
||
- Binance 451 → 使用 Binance 合约 fapi(部分品种需要 1000PEPEUSDT 等格式)
|
||
- CoinGecko 429 → 使用 CoinGecko 批量接口(一次查多币)+ CoinPaprika 替代
|
||
- Bybit 403 → 使用 OKX/Gate.io 替代
|
||
- 新增:更多 Yahoo Finance 品种、更多 DeFiLlama 协议
|
||
"""
|
||
import requests
|
||
import json
|
||
import time
|
||
|
||
results = {}
|
||
|
||
def test(name, url, params=None, headers=None, method="GET", body=None, timeout=15):
|
||
try:
|
||
h = {"User-Agent": "QuantKnowledge/2.0"}
|
||
if headers:
|
||
h.update(headers)
|
||
start = time.time()
|
||
if method == "POST":
|
||
r = requests.post(url, json=body, headers=h, timeout=timeout)
|
||
else:
|
||
r = requests.get(url, params=params, headers=h, timeout=timeout)
|
||
elapsed = round((time.time() - start) * 1000)
|
||
if r.status_code == 200:
|
||
data = r.json() if 'json' in r.headers.get('content-type','') else r.text[:200]
|
||
results[name] = {"status": "✅ PASS", "latency": f"{elapsed}ms", "sample": data if isinstance(data, dict) else str(data)[:300]}
|
||
print(f"✅ {name} ({elapsed}ms)")
|
||
return data
|
||
else:
|
||
results[name] = {"status": f"❌ HTTP {r.status_code}", "latency": f"{elapsed}ms"}
|
||
print(f"❌ {name} HTTP {r.status_code}")
|
||
return None
|
||
except Exception as e:
|
||
results[name] = {"status": f"❌ {str(e)[:80]}", "latency": "timeout"}
|
||
print(f"❌ {name}: {str(e)[:60]}")
|
||
return None
|
||
|
||
print("=" * 60)
|
||
print("第7批:修复失败项 + 新增品种")
|
||
print("=" * 60)
|
||
|
||
# ─── 一、CoinGecko 批量查询(一次查多币,节省配额)─────────────────
|
||
print("\n--- CoinGecko 批量查询 ---")
|
||
|
||
# 批量1:DeFi + L2 代币
|
||
test(
|
||
"CoinGecko 批量(UNI/AAVE/OP/ARB/APT/SUI)",
|
||
"https://api.coingecko.com/api/v3/simple/price",
|
||
params={
|
||
"ids": "uniswap,aave,optimism,arbitrum,aptos,sui",
|
||
"vs_currencies": "usd",
|
||
"include_market_cap": "true",
|
||
"include_24hr_vol": "true",
|
||
"include_24hr_change": "true"
|
||
}
|
||
)
|
||
time.sleep(3)
|
||
|
||
# 批量2:Meme 代币
|
||
test(
|
||
"CoinGecko 批量(PEPE/SHIB/WIF/BONK/FLOKI/DOGE)",
|
||
"https://api.coingecko.com/api/v3/simple/price",
|
||
params={
|
||
"ids": "pepe,shiba-inu,dogwifcoin,bonk,floki,dogecoin",
|
||
"vs_currencies": "usd",
|
||
"include_market_cap": "true",
|
||
"include_24hr_vol": "true",
|
||
"include_24hr_change": "true"
|
||
}
|
||
)
|
||
time.sleep(3)
|
||
|
||
# 批量3:AI 代币
|
||
test(
|
||
"CoinGecko 批量(FET/RNDR/TAO/AKT/OCEAN/AGIX)",
|
||
"https://api.coingecko.com/api/v3/simple/price",
|
||
params={
|
||
"ids": "fetch-ai,render-token,bittensor,akash-network,ocean-protocol,singularitynet",
|
||
"vs_currencies": "usd",
|
||
"include_market_cap": "true",
|
||
"include_24hr_vol": "true",
|
||
"include_24hr_change": "true"
|
||
}
|
||
)
|
||
time.sleep(3)
|
||
|
||
# 批量4:RWA 代币
|
||
test(
|
||
"CoinGecko 批量(ONDO/MKR/CFG/MPL/GFI/PENDLE)",
|
||
"https://api.coingecko.com/api/v3/simple/price",
|
||
params={
|
||
"ids": "ondo-finance,maker,centrifuge,maple-finance,goldfinch,pendle",
|
||
"vs_currencies": "usd",
|
||
"include_market_cap": "true",
|
||
"include_24hr_vol": "true",
|
||
"include_24hr_change": "true"
|
||
}
|
||
)
|
||
time.sleep(3)
|
||
|
||
# 批量5:链上基础设施
|
||
test(
|
||
"CoinGecko 批量(NEAR/FIL/STX/INJ/TIA/SEI)",
|
||
"https://api.coingecko.com/api/v3/simple/price",
|
||
params={
|
||
"ids": "near,filecoin,blockstack,injective-protocol,celestia,sei-network",
|
||
"vs_currencies": "usd",
|
||
"include_market_cap": "true",
|
||
"include_24hr_vol": "true",
|
||
"include_24hr_change": "true"
|
||
}
|
||
)
|
||
time.sleep(3)
|
||
|
||
# 批量6:Wrapped/LST 代币
|
||
test(
|
||
"CoinGecko 批量(WBTC/stETH/rETH/cbETH/wstETH)",
|
||
"https://api.coingecko.com/api/v3/simple/price",
|
||
params={
|
||
"ids": "wrapped-bitcoin,staked-ether,rocket-pool-eth,coinbase-wrapped-staked-eth,wrapped-steth",
|
||
"vs_currencies": "usd",
|
||
"include_market_cap": "true",
|
||
"include_24hr_vol": "true"
|
||
}
|
||
)
|
||
time.sleep(3)
|
||
|
||
# 批量7:稳定币
|
||
test(
|
||
"CoinGecko 批量(USDT/USDC/DAI/FRAX/LUSD/crvUSD)",
|
||
"https://api.coingecko.com/api/v3/simple/price",
|
||
params={
|
||
"ids": "tether,usd-coin,dai,frax,liquity-usd,crvusd",
|
||
"vs_currencies": "usd",
|
||
"include_market_cap": "true",
|
||
"include_24hr_vol": "true"
|
||
}
|
||
)
|
||
time.sleep(3)
|
||
|
||
# 批量8:GameFi + Metaverse
|
||
test(
|
||
"CoinGecko 批量(AXS/SAND/MANA/IMX/GALA/ILV)",
|
||
"https://api.coingecko.com/api/v3/simple/price",
|
||
params={
|
||
"ids": "axie-infinity,the-sandbox,decentraland,immutable-x,gala,illuvium",
|
||
"vs_currencies": "usd",
|
||
"include_market_cap": "true",
|
||
"include_24hr_vol": "true"
|
||
}
|
||
)
|
||
time.sleep(3)
|
||
|
||
# 批量9:Privacy + Storage
|
||
test(
|
||
"CoinGecko 批量(XMR/ZEC/AR/FIL/STORJ/SC)",
|
||
"https://api.coingecko.com/api/v3/simple/price",
|
||
params={
|
||
"ids": "monero,zcash,arweave,filecoin,storj,siacoin",
|
||
"vs_currencies": "usd",
|
||
"include_market_cap": "true"
|
||
}
|
||
)
|
||
time.sleep(3)
|
||
|
||
# 批量10:交易所代币
|
||
test(
|
||
"CoinGecko 批量(BNB/OKB/CRO/GT/KCS/MX)",
|
||
"https://api.coingecko.com/api/v3/simple/price",
|
||
params={
|
||
"ids": "binancecoin,okb,crypto-com-chain,gatechain-token,kucoin-shares,mx-token",
|
||
"vs_currencies": "usd",
|
||
"include_market_cap": "true"
|
||
}
|
||
)
|
||
time.sleep(3)
|
||
|
||
# ─── 二、Binance 修复(使用正确的合约代码)─────────────────────────
|
||
print("\n--- Binance 修复(合约代码修正)---")
|
||
# 451 是地区限制,尝试用 fapi 的不同端点
|
||
binance_fix = [
|
||
("1000PEPE", "1000PEPEUSDT"), ("1000SHIB", "1000SHIBUSDT"),
|
||
("1000FLOKI", "1000FLOKIUSDT"), ("1000BONK", "1000BONKUSDT"),
|
||
]
|
||
for coin_name, symbol in binance_fix:
|
||
test(
|
||
f"Binance {coin_name} 资金费率(修复)",
|
||
f"https://fapi.binance.com/fapi/v1/premiumIndex",
|
||
params={"symbol": symbol}
|
||
)
|
||
time.sleep(0.1)
|
||
|
||
# ─── 三、OKX 更多品种(替代 Bybit 失败项)─────────────────────────
|
||
print("\n--- OKX 更多品种 ---")
|
||
okx_extra = [
|
||
("SUI", "SUI-USDT-SWAP"), ("APT", "APT-USDT-SWAP"),
|
||
("TIA", "TIA-USDT-SWAP"), ("INJ", "INJ-USDT-SWAP"),
|
||
("FET", "FET-USDT-SWAP"), ("WLD", "WLD-USDT-SWAP"),
|
||
("ORDI", "ORDI-USDT-SWAP"), ("STX", "STX-USDT-SWAP"),
|
||
("FIL", "FIL-USDT-SWAP"), ("LTC", "LTC-USDT-SWAP"),
|
||
("BCH", "BCH-USDT-SWAP"), ("ETC", "ETC-USDT-SWAP"),
|
||
("ATOM", "ATOM-USDT-SWAP"), ("MKR", "MKR-USDT-SWAP"),
|
||
("AAVE", "AAVE-USDT-SWAP"), ("UNI", "UNI-USDT-SWAP"),
|
||
("DOGE", "DOGE-USDT-SWAP"), ("SHIB", "SHIB-USDT-SWAP"),
|
||
("AVAX", "AVAX-USDT-SWAP"), ("DOT", "DOT-USDT-SWAP"),
|
||
]
|
||
for coin_name, inst_id in okx_extra:
|
||
test(
|
||
f"OKX {coin_name} K线",
|
||
f"https://www.okx.com/api/v5/market/candles",
|
||
params={"instId": inst_id, "bar": "1H", "limit": "2"}
|
||
)
|
||
time.sleep(0.15)
|
||
|
||
# ─── 四、Gate.io 多品种 ─────────────────────────────────────────
|
||
print("\n--- Gate.io 多品种 ---")
|
||
gateio_symbols = [
|
||
("ADA", "ADA_USDT"), ("AVAX", "AVAX_USDT"), ("DOT", "DOT_USDT"),
|
||
("LINK", "LINK_USDT"), ("OP", "OP_USDT"), ("ARB", "ARB_USDT"),
|
||
("PEPE", "PEPE_USDT"), ("NEAR", "NEAR_USDT"), ("ATOM", "ATOM_USDT"),
|
||
("DOGE", "DOGE_USDT"), ("SHIB", "SHIB_USDT"),
|
||
]
|
||
for coin_name, contract in gateio_symbols:
|
||
test(
|
||
f"Gate.io {coin_name} 合约K线",
|
||
f"https://api.gateio.ws/api/v4/futures/usdt/candlesticks",
|
||
params={"contract": contract, "interval": "1h", "limit": "2"}
|
||
)
|
||
time.sleep(0.1)
|
||
|
||
# ─── 五、DeFiLlama 更多协议和数据 ─────────────────────────────────
|
||
print("\n--- DeFiLlama 更多协议 ---")
|
||
llama_extra = [
|
||
"maker", "sky", "ethena", "pendle", "convex-finance",
|
||
"instadapp", "spark", "venus", "benqi-lending",
|
||
"trader-joe", "camelot", "aerodrome", "velodrome",
|
||
"stargate", "layerzero", "wormhole",
|
||
]
|
||
for proto in llama_extra:
|
||
test(
|
||
f"DeFiLlama {proto} 协议",
|
||
f"https://api.llama.fi/protocol/{proto}"
|
||
)
|
||
time.sleep(0.3)
|
||
|
||
# DeFiLlama 更多聚合数据
|
||
test("DeFiLlama 永续DEX交易量", "https://api.llama.fi/overview/derivatives")
|
||
time.sleep(0.3)
|
||
test("DeFiLlama 聚合器交易量", "https://api.llama.fi/overview/aggregators")
|
||
time.sleep(0.3)
|
||
test("DeFiLlama 清算数据", "https://api.llama.fi/overview/liquidations")
|
||
time.sleep(0.3)
|
||
|
||
# ─── 六、Yahoo Finance 更多传统金融品种 ─────────────────────────────
|
||
print("\n--- Yahoo Finance 更多品种 ---")
|
||
yahoo_more = [
|
||
("^STOXX50E", "欧洲STOXX50"), ("^AXJO", "澳洲ASX200"),
|
||
("^NSEI", "印度NIFTY50"), ("^GSPTSE", "加拿大TSX"),
|
||
("AAPL", "苹果"), ("MSFT", "微软"), ("NVDA", "英伟达"),
|
||
("TSLA", "特斯拉"), ("AMZN", "亚马逊"), ("GOOGL", "谷歌"),
|
||
("META", "Meta"), ("AMD", "AMD"),
|
||
("GLD", "黄金ETF"), ("SLV", "白银ETF"), ("USO", "原油ETF"),
|
||
("UNG", "天然气ETF"), ("DBA", "农产品ETF"),
|
||
("EEM", "新兴市场ETF"), ("FXI", "中国大盘ETF"),
|
||
("KWEB", "中国互联网ETF"), ("ARKK", "ARK创新ETF"),
|
||
("XLF", "金融板块ETF"), ("XLE", "能源板块ETF"),
|
||
("XLK", "科技板块ETF"), ("XLV", "医疗板块ETF"),
|
||
("SPY", "标普500ETF"), ("QQQ", "纳斯达克ETF"),
|
||
("IWM", "罗素2000ETF"), ("DIA", "道琼斯ETF"),
|
||
("BRK-B", "伯克希尔"), ("JPM", "摩根大通"),
|
||
("V", "Visa"), ("MA", "万事达"),
|
||
("^IRX", "3月期美债"), ("^FVX", "5年期美债"),
|
||
("^TYX", "30年期美债"),
|
||
("CNY=X", "USD/CNY"), ("GBP=X", "GBP/USD"),
|
||
("AUD=X", "AUD/USD"), ("CHF=X", "USD/CHF"),
|
||
("BTC-USD", "BTC/USD Yahoo"), ("ETH-USD", "ETH/USD Yahoo"),
|
||
("BNB-USD", "BNB/USD Yahoo"), ("SOL-USD", "SOL/USD Yahoo"),
|
||
("XRP-USD", "XRP/USD Yahoo"), ("ADA-USD", "ADA/USD Yahoo"),
|
||
("DOGE-USD", "DOGE/USD Yahoo"), ("DOT-USD", "DOT/USD Yahoo"),
|
||
("AVAX-USD", "AVAX/USD Yahoo"), ("LINK-USD", "LINK/USD Yahoo"),
|
||
]
|
||
for symbol, name in yahoo_more:
|
||
test(
|
||
f"Yahoo {name} ({symbol})",
|
||
f"https://query1.finance.yahoo.com/v8/finance/chart/{symbol}",
|
||
params={"interval": "1d", "range": "5d"},
|
||
headers={"User-Agent": "Mozilla/5.0"}
|
||
)
|
||
time.sleep(0.15)
|
||
|
||
# ─── 七、Deribit SOL 指数修复 ─────────────────────────────────────
|
||
print("\n--- Deribit 修复 ---")
|
||
test(
|
||
"Deribit SOL 指数价格(修复)",
|
||
"https://www.deribit.com/api/v2/public/get_index_price",
|
||
params={"index_name": "sol_usd"}
|
||
)
|
||
|
||
# ─── 八、Reddit 更多子版块 ─────────────────────────────────────────
|
||
print("\n--- Reddit 更多子版块 ---")
|
||
reddit_extra = [
|
||
"CryptoMarkets", "binance", "Bybit", "options",
|
||
"StockMarket", "investing", "economy", "Forex",
|
||
]
|
||
for sub in reddit_extra:
|
||
test(
|
||
f"Reddit r/{sub} 热帖",
|
||
f"https://www.reddit.com/r/{sub}/hot.json",
|
||
params={"limit": 3}
|
||
)
|
||
time.sleep(6.5) # 10/min 限制
|
||
|
||
# ─── 保存结果 ─────────────────────────────────────────────────────
|
||
with open("verify_batch7_results.json", "w") as f:
|
||
json.dump(results, f, ensure_ascii=False, indent=2, default=str)
|
||
|
||
passed = sum(1 for v in results.values() if "✅" in v["status"])
|
||
failed = sum(1 for v in results.values() if "❌" in v["status"])
|
||
print(f"\n{'='*60}")
|
||
print(f"第7批验证完成: {passed} 通过 / {failed} 失败 / 总计 {len(results)}")
|
||
print(f"{'='*60}")
|