新增内容: - 数据源接入验证报告_141个.md:完整验证报告含真实响应数据 - 5个批次验证脚本(verify_batch1-5.py) - 合并验证结果(all_verified_results.json) 数据源覆盖: - CEX: 42个(Binance/OKX/Bybit/Kraken/Gate.io/KuCoin/HTX/Bitfinex/Crypto.com/MEXC) - DEX: 7个(DexScreener/Hyperliquid/Raydium/1inch) - 链上: 12个(Blockchain.info/Mempool.space/Blockchair/Etherscan) - DeFi: 15个(DeFiLlama 12端点/Aave/Lido/L2排名) - 衍生品: 9个(Deribit 7端点/CoinGecko衍生品) - 社交: 10个(Reddit 8子版块/Nitter RSS/恐惧贪婪) - 宏观: 28个(Yahoo Finance 22端点/世界银行 6端点) - 综合: 18个(CoinGecko 8端点/CoinPaprika 7端点/CoinGlass/The Graph) 全部141个数据源100%免费,139个无需API Key
307 行
15 KiB
Python
307 行
15 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
数据源验证脚本 - 第五批(修复失败项 + 新增编号 116-145)
|
||
修复之前失败的 + 新增更多不重复数据源
|
||
"""
|
||
import requests, json, time
|
||
|
||
TIMEOUT = 12
|
||
results = {}
|
||
|
||
def test(name, fn):
|
||
try:
|
||
start = time.time()
|
||
data = fn()
|
||
elapsed = round((time.time() - start) * 1000)
|
||
results[name] = {"status": "✅", "latency_ms": elapsed, "sample": data}
|
||
print(f"✅ {name} ({elapsed}ms)")
|
||
except Exception as e:
|
||
results[name] = {"status": "❌", "error": str(e)[:200]}
|
||
print(f"❌ {name}: {str(e)[:120]}")
|
||
|
||
# ─── 修复之前失败的 ────────────────────────────────────────────────────────
|
||
|
||
# 修复 MEXC(interval 格式不同)
|
||
def fix_mexc():
|
||
r = requests.get("https://api.mexc.com/api/v3/klines", params={"symbol":"BTCUSDT","interval":"60m","limit":"3"}, timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json(); k=d[-1]
|
||
return {"open":k[1],"high":k[2],"low":k[3],"close":k[4],"volume":k[5]}
|
||
test("MEXC BTC/USDT K线(修复)", fix_mexc)
|
||
|
||
# 修复 Blockchair BTC
|
||
def fix_blockchair():
|
||
r = requests.get("https://api.blockchair.com/bitcoin/stats", timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()["data"]
|
||
return {"blocks":d["blocks"],"transactions":d["transactions"],"market_price_usd":d["market_price_usd"],"difficulty":d["difficulty"]}
|
||
test("Blockchair BTC链统计(修复)", fix_blockchair)
|
||
|
||
# 修复 Mempool 矿池
|
||
def fix_mempool_pools():
|
||
r = requests.get("https://mempool.space/api/v1/mining/pools/1w", timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()
|
||
pools = d["pools"][:5]
|
||
return {"total_pools":len(d["pools"]),"top5":[{"name":p["name"],"blockCount":p["blockCount"],"hashrate":p.get("avgHashrate",0)} for p in pools]}
|
||
test("Mempool.space 矿池排名(修复)", fix_mempool_pools)
|
||
|
||
# 修复 Blockchain.info 区块奖励
|
||
def fix_block_reward():
|
||
r = requests.get("https://blockchain.info/q/bcperblock", timeout=TIMEOUT)
|
||
r.raise_for_status()
|
||
return {"btc_per_block":float(r.text),"note":"当前区块奖励"}
|
||
test("Blockchain.info 区块奖励(修复)", fix_block_reward)
|
||
|
||
# 修复 Aave V3
|
||
def fix_aave():
|
||
r = requests.get("https://api.llama.fi/protocol/aave-v3", timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()
|
||
tvl = d.get("tvl",0)
|
||
if isinstance(tvl, list):
|
||
tvl = tvl[-1].get("totalLiquidityUSD",0) if tvl else 0
|
||
return {"name":d["name"],"category":d.get("category"),"chains":d.get("chains",[])}
|
||
test("Aave V3 协议信息(修复)", fix_aave)
|
||
|
||
# 修复 Lido
|
||
def fix_lido():
|
||
r = requests.get("https://api.llama.fi/protocol/lido", timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()
|
||
tvl = d.get("tvl",0)
|
||
if isinstance(tvl, list):
|
||
tvl = tvl[-1].get("totalLiquidityUSD",0) if tvl else 0
|
||
return {"name":d["name"],"category":d.get("category"),"chains":d.get("chains",[])}
|
||
test("Lido Staking 协议信息(修复)", fix_lido)
|
||
|
||
# ─── 新增数据源(编号 116-145)──────────────────────────────────────────────
|
||
|
||
# 116. Binance SOL合约
|
||
def t116():
|
||
r = requests.get("https://fapi.binance.com/fapi/v1/premiumIndex", params={"symbol":"SOLUSDT"}, timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()
|
||
return {"symbol":d["symbol"],"markPrice":d["markPrice"],"lastFundingRate":d["lastFundingRate"]}
|
||
test("Binance SOL合约资金费率", t116)
|
||
|
||
# 117. Binance DOGE合约
|
||
def t117():
|
||
r = requests.get("https://fapi.binance.com/fapi/v1/premiumIndex", params={"symbol":"DOGEUSDT"}, timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()
|
||
return {"symbol":d["symbol"],"markPrice":d["markPrice"],"lastFundingRate":d["lastFundingRate"]}
|
||
test("Binance DOGE合约资金费率", t117)
|
||
|
||
# 118. Binance XRP合约
|
||
def t118():
|
||
r = requests.get("https://fapi.binance.com/fapi/v1/premiumIndex", params={"symbol":"XRPUSDT"}, timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()
|
||
return {"symbol":d["symbol"],"markPrice":d["markPrice"],"lastFundingRate":d["lastFundingRate"]}
|
||
test("Binance XRP合约资金费率", t118)
|
||
|
||
# 119. Binance 全市场合约Ticker
|
||
def t119():
|
||
r = requests.get("https://fapi.binance.com/fapi/v1/ticker/24hr", timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()
|
||
top3 = sorted(d, key=lambda x:float(x.get("quoteVolume","0")), reverse=True)[:3]
|
||
return {"total_pairs":len(d),"top3_by_volume":[{"symbol":x["symbol"],"volume":f"${float(x['quoteVolume'])/1e9:.1f}B","change":f"{x['priceChangePercent']}%"} for x in top3]}
|
||
test("Binance 全市场合约Ticker", t119)
|
||
|
||
# 120. OKX 全市场Ticker
|
||
def t120():
|
||
r = requests.get("https://www.okx.com/api/v5/market/tickers", params={"instType":"SWAP"}, timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()["data"]
|
||
return {"total_swaps":len(d),"sample":[{"instId":x["instId"],"last":x["last"],"vol24h":x["vol24h"]} for x in d[:3]]}
|
||
test("OKX 全市场永续合约Ticker", t120)
|
||
|
||
# 121. Bybit 全市场合约Ticker
|
||
def t121():
|
||
r = requests.get("https://api.bybit.com/v5/market/tickers", params={"category":"linear"}, timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()["result"]["list"]
|
||
top3 = sorted(d, key=lambda x:float(x.get("turnover24h","0")), reverse=True)[:3]
|
||
return {"total_pairs":len(d),"top3":[{"symbol":x["symbol"],"turnover24h":f"${float(x['turnover24h'])/1e9:.1f}B"} for x in top3]}
|
||
test("Bybit 全市场合约Ticker", t121)
|
||
|
||
# 122. Gate.io 全市场合约
|
||
def t122():
|
||
r = requests.get("https://api.gateio.ws/api/v4/futures/usdt/tickers", timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()
|
||
return {"total_contracts":len(d),"sample":[{"contract":x["contract"],"last":x["last"],"volume_24h":x["volume_24h"]} for x in d[:3]]}
|
||
test("Gate.io 全市场合约Ticker", t122)
|
||
|
||
# 123. Kraken 资产对列表
|
||
def t123():
|
||
r = requests.get("https://api.kraken.com/0/public/AssetPairs", timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()["result"]
|
||
return {"total_pairs":len(d),"sample":list(d.keys())[:5]}
|
||
test("Kraken 交易对列表", t123)
|
||
|
||
# 124. CoinGecko 衍生品交易所
|
||
def t124():
|
||
r = requests.get("https://api.coingecko.com/api/v3/derivatives/exchanges", params={"per_page":"5"}, timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()
|
||
return {"total":len(d),"top3":[{"name":x["name"],"open_interest_btc":x.get("open_interest_btc"),"trade_volume_24h_btc":f"{x.get('trade_volume_24h_btc','0')}"} for x in d[:3]]}
|
||
test("CoinGecko 衍生品交易所排名", t124)
|
||
|
||
# 125. CoinGecko 衍生品合约
|
||
def t125():
|
||
r = requests.get("https://api.coingecko.com/api/v3/derivatives", timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()
|
||
return {"total":len(d),"sample":[{"market":x["market"],"symbol":x["symbol"],"price":x["price"],"funding_rate":x.get("funding_rate")} for x in d[:3]]}
|
||
test("CoinGecko 衍生品合约列表", t125)
|
||
|
||
# 126. CoinPaprika SOL行情
|
||
def t126():
|
||
r = requests.get("https://api.coinpaprika.com/v1/tickers/sol-solana", timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()
|
||
q = d["quotes"]["USD"]
|
||
return {"name":d["name"],"rank":d["rank"],"price":f"${q['price']:.2f}","market_cap":f"${q['market_cap']/1e9:.0f}B"}
|
||
test("CoinPaprika SOL行情", t126)
|
||
|
||
# 127. CoinPaprika BNB行情
|
||
def t127():
|
||
r = requests.get("https://api.coinpaprika.com/v1/tickers/bnb-binance-coin", timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()
|
||
q = d["quotes"]["USD"]
|
||
return {"name":d["name"],"rank":d["rank"],"price":f"${q['price']:.2f}"}
|
||
test("CoinPaprika BNB行情", t127)
|
||
|
||
# 128. CoinPaprika XRP行情
|
||
def t128():
|
||
r = requests.get("https://api.coinpaprika.com/v1/tickers/xrp-xrp", timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()
|
||
q = d["quotes"]["USD"]
|
||
return {"name":d["name"],"rank":d["rank"],"price":f"${q['price']:.2f}"}
|
||
test("CoinPaprika XRP行情", t128)
|
||
|
||
# 129. CoinPaprika DOGE行情
|
||
def t129():
|
||
r = requests.get("https://api.coinpaprika.com/v1/tickers/doge-dogecoin", timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()
|
||
q = d["quotes"]["USD"]
|
||
return {"name":d["name"],"rank":d["rank"],"price":f"${q['price']:.4f}"}
|
||
test("CoinPaprika DOGE行情", t129)
|
||
|
||
# 130. DeFiLlama 借贷协议
|
||
def t130():
|
||
r = requests.get("https://api.llama.fi/protocols", timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()
|
||
lending = [x for x in d if x.get("category")=="Lending"][:3]
|
||
return {"total_protocols":len(d),"top_lending":[{"name":x["name"],"tvl":f"${x.get('tvl',0)/1e9:.2f}B"} for x in lending]}
|
||
test("DeFiLlama 借贷协议排名", t130)
|
||
|
||
# 131. DeFiLlama DEX协议
|
||
def t131():
|
||
r = requests.get("https://api.llama.fi/protocols", timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()
|
||
dex = [x for x in d if x.get("category")=="Dexes"][:3]
|
||
return {"top_dex":[{"name":x["name"],"tvl":f"${x.get('tvl',0)/1e9:.2f}B"} for x in dex]}
|
||
test("DeFiLlama DEX协议排名", t131)
|
||
|
||
# 132. Yahoo Finance MSTR(MicroStrategy)
|
||
def t132():
|
||
r = requests.get("https://query1.finance.yahoo.com/v8/finance/chart/MSTR", params={"interval":"1d","range":"5d"}, headers={"User-Agent":"Mozilla/5.0"}, timeout=TIMEOUT)
|
||
r.raise_for_status(); meta=r.json()["chart"]["result"][0]["meta"]
|
||
return {"symbol":meta["symbol"],"price":meta["regularMarketPrice"],"currency":meta["currency"]}
|
||
test("Yahoo Finance MicroStrategy(MSTR)", t132)
|
||
|
||
# 133. Yahoo Finance COIN(Coinbase)
|
||
def t133():
|
||
r = requests.get("https://query1.finance.yahoo.com/v8/finance/chart/COIN", params={"interval":"1d","range":"5d"}, headers={"User-Agent":"Mozilla/5.0"}, timeout=TIMEOUT)
|
||
r.raise_for_status(); meta=r.json()["chart"]["result"][0]["meta"]
|
||
return {"symbol":meta["symbol"],"price":meta["regularMarketPrice"]}
|
||
test("Yahoo Finance Coinbase(COIN)", t133)
|
||
|
||
# 134. Yahoo Finance MARA(Marathon Digital)
|
||
def t134():
|
||
r = requests.get("https://query1.finance.yahoo.com/v8/finance/chart/MARA", params={"interval":"1d","range":"5d"}, headers={"User-Agent":"Mozilla/5.0"}, timeout=TIMEOUT)
|
||
r.raise_for_status(); meta=r.json()["chart"]["result"][0]["meta"]
|
||
return {"symbol":meta["symbol"],"price":meta["regularMarketPrice"]}
|
||
test("Yahoo Finance Marathon Digital(MARA)", t134)
|
||
|
||
# 135. Yahoo Finance FBTC(Fidelity BTC ETF)
|
||
def t135():
|
||
r = requests.get("https://query1.finance.yahoo.com/v8/finance/chart/FBTC", params={"interval":"1d","range":"5d"}, headers={"User-Agent":"Mozilla/5.0"}, timeout=TIMEOUT)
|
||
r.raise_for_status(); meta=r.json()["chart"]["result"][0]["meta"]
|
||
return {"symbol":meta["symbol"],"price":meta["regularMarketPrice"]}
|
||
test("Yahoo Finance Fidelity BTC ETF(FBTC)", t135)
|
||
|
||
# 136. Yahoo Finance ETHE(Grayscale ETH ETF)
|
||
def t136():
|
||
r = requests.get("https://query1.finance.yahoo.com/v8/finance/chart/ETHE", params={"interval":"1d","range":"5d"}, headers={"User-Agent":"Mozilla/5.0"}, timeout=TIMEOUT)
|
||
r.raise_for_status(); meta=r.json()["chart"]["result"][0]["meta"]
|
||
return {"symbol":meta["symbol"],"price":meta["regularMarketPrice"]}
|
||
test("Yahoo Finance Grayscale ETH(ETHE)", t136)
|
||
|
||
# 137. Deribit ETH 期权
|
||
def t137():
|
||
r = requests.get("https://www.deribit.com/api/v2/public/get_book_summary_by_currency", params={"currency":"ETH","kind":"option"}, timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()["result"]
|
||
total_oi = sum(x.get("open_interest",0) for x in d)
|
||
return {"total_eth_options":len(d),"total_open_interest":f"{total_oi:.0f} ETH"}
|
||
test("Deribit ETH期权汇总", t137)
|
||
|
||
# 138. Deribit ETH DVOL
|
||
def t138():
|
||
end_ts = int(time.time()*1000)
|
||
start_ts = end_ts - 3600*1000*24
|
||
r = requests.get("https://www.deribit.com/api/v2/public/get_volatility_index_data", params={"currency":"ETH","resolution":"3600","start_timestamp":start_ts,"end_timestamp":end_ts}, timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()["result"]["data"]
|
||
return {"latest_dvol":d[-1][1],"data_points":len(d)}
|
||
test("Deribit ETH DVOL波动率", t138)
|
||
|
||
# 139. Hyperliquid 资金费率
|
||
def t139():
|
||
r = requests.post("https://api.hyperliquid.xyz/info", json={"type":"metaAndAssetCtxs"}, timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()
|
||
btc_ctx = d[1][0]
|
||
return {"funding":btc_ctx.get("funding"),"openInterest":btc_ctx.get("openInterest"),"markPx":btc_ctx.get("markPx")}
|
||
test("Hyperliquid BTC资金费率", t139)
|
||
|
||
# 140. DexScreener 最新交易对
|
||
def t140():
|
||
r = requests.get("https://api.dexscreener.com/latest/dex/pairs/ethereum/0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640", timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()
|
||
pair = d.get("pair") or d.get("pairs",[{}])[0]
|
||
return {"dex":pair.get("dexId"),"baseToken":pair.get("baseToken",{}).get("symbol"),"quoteToken":pair.get("quoteToken",{}).get("symbol"),"priceUsd":pair.get("priceUsd")}
|
||
test("DexScreener Uniswap ETH/USDC", t140)
|
||
|
||
# 141. 世界银行 全球GDP
|
||
def t141():
|
||
r = requests.get("https://api.worldbank.org/v2/country/WLD/indicator/NY.GDP.MKTP.CD", params={"format":"json","per_page":"3","mrv":"3"}, timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()[1]
|
||
return [{"year":x["date"],"global_gdp":f"${x['value']/1e12:.1f}T" if x["value"] else "N/A"} for x in d]
|
||
test("世界银行 全球GDP", t141)
|
||
|
||
# 142. 世界银行 日本GDP
|
||
def t142():
|
||
r = requests.get("https://api.worldbank.org/v2/country/JP/indicator/NY.GDP.MKTP.CD", params={"format":"json","per_page":"3","mrv":"3"}, timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()[1]
|
||
return [{"year":x["date"],"japan_gdp":f"${x['value']/1e12:.1f}T" if x["value"] else "N/A"} for x in d]
|
||
test("世界银行 日本GDP", t142)
|
||
|
||
# 143. Binance 合约交易规则
|
||
def t143():
|
||
r = requests.get("https://fapi.binance.com/fapi/v1/exchangeInfo", timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()
|
||
symbols = d["symbols"]
|
||
btc = next((x for x in symbols if x["symbol"]=="BTCUSDT"), None)
|
||
return {"total_symbols":len(symbols),"btc_tick_size":btc["filters"][0].get("tickSize") if btc else None,"btc_min_qty":btc["filters"][1].get("minQty") if btc else None}
|
||
test("Binance 合约交易规则", t143)
|
||
|
||
# 144. OKX 交易规则
|
||
def t144():
|
||
r = requests.get("https://www.okx.com/api/v5/public/instruments", params={"instType":"SWAP","instId":"BTC-USDT-SWAP"}, timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()["data"][0]
|
||
return {"instId":d["instId"],"tickSz":d["tickSz"],"lotSz":d["lotSz"],"minSz":d["minSz"],"ctVal":d["ctVal"]}
|
||
test("OKX BTC合约交易规则", t144)
|
||
|
||
# 145. Bybit 交易规则
|
||
def t145():
|
||
r = requests.get("https://api.bybit.com/v5/market/instruments-info", params={"category":"linear","symbol":"BTCUSDT"}, timeout=TIMEOUT)
|
||
r.raise_for_status(); d=r.json()["result"]["list"][0]
|
||
return {"symbol":d["symbol"],"tickSize":d["priceFilter"]["tickSize"],"minOrderQty":d["lotSizeFilter"]["minOrderQty"]}
|
||
test("Bybit BTC合约交易规则", t145)
|
||
|
||
# ─── 保存 ──────────────────────────────────────────────────────────────────
|
||
print(f"\n=== 批次5汇总 ===")
|
||
p = sum(1 for v in results.values() if v["status"]=="✅")
|
||
f = sum(1 for v in results.values() if v["status"]=="❌")
|
||
print(f"通过: {p}/{len(results)}, 失败: {f}/{len(results)}")
|
||
with open("/home/ubuntu/quantKnowledge/20_Go迭代系统/scripts/verify_batch5_results.json","w") as fp:
|
||
json.dump(results, fp, ensure_ascii=False, indent=2, default=str)
|