整合指南
搭配CCXT使用Smart Money API
透過CCXT讀取即時市場數據,詢問Smart Money API鯨魚資金流向與衍生品持倉是否支持您的交易方向,再透過指定交易所下單。
適用對象
使用Python開發跨交易所通用機器人的開發者 CCXT 希望在每次下單前進行獨立市場情境驗證。Smart Money API僅提供決策支援——不會代為下單;CCXT始終掌握執行權。
必要條件
- Python 3.9+ 環境
pip install ccxt requests. - 已配置CCXT交易所API金鑰(測試時唯讀權限即可)。
- 一組Smart Money API金鑰(免費方案支援BTC)。
取得API金鑰
設定步驟
- 1安裝函式庫:
pip install ccxt requests. - 2匯出您的金鑰:
export SMA_API_KEY="sm_your_key_here". - 3讓策略根據CCXT市場數據決定初步方向後,呼叫
/v1/confirm作為最終情境驗證關卡。 - 4僅當行動標記為「
CONFIRM」時才透過CCXT下單,並依據size_mult.
實例演示
此腳本使用 CCXT 讀取交易對,推導出潛在方向,然後調用 GET /v1/confirm?symbol=BTC&direction=long 在決定是否下單之前。
ccxt_confirm.py
import os
import ccxt
import requests
API_KEY = os.environ["SMA_API_KEY"] # never hard-code
SMA_BASE = "https://api.smartmoneyapi.com"
exchange = ccxt.binance() # any CCXT exchange
def confirm(symbol: str, direction: str) -> dict:
"""Ask Smart Money API for market-context confirmation."""
r = requests.get(
f"{SMA_BASE}/v1/confirm",
params={"symbol": symbol, "direction": direction, "source": "ccxt-bot"},
headers={"X-API-Key": API_KEY},
timeout=10,
)
r.raise_for_status()
return r.json()
# 1. Read market data with CCXT and pick a candidate direction
ticker = exchange.fetch_ticker("BTC/USDT")
direction = "long" if ticker["percentage"] and ticker["percentage"] > 0 else "short"
# 2. Confirm with Smart Money API before acting
sig = confirm("BTC", direction)
print(sig["action"], sig["confidence"], "size_mult", sig["size_mult"])
# 3. Act on the recommendation (CCXT executes; the API only advises)
if sig["action"] == "CONFIRM":
base_qty = 0.01
qty = base_qty * sig["size_mult"] # scale by suggested multiplier
# exchange.create_order("BTC/USDT", "market", direction, qty)
print(f"Would place {direction} {qty} BTC/USDT")
elif sig["action"] == "REDUCE":
print("Context is mixed -> trade smaller or wait for a cleaner setup")
else: # SKIP
print("Context does not support this trade -> stand aside")
預期回應
成功調用 /v1/confirm 返回如下 JSON:
200 OK · application/json
{
"ts": 1710940821,
"symbol": "BTC",
"direction": "long",
"composite": 0.74,
"confidence": "HIGH",
"action": "CONFIRM",
"size_mult": 1.5,
"deriv_score": 0.81,
"onchain_score": 0.68,
"whale_score": 0.73,
"reasons": [
"Funding rate positive across all venues",
"LSR favors longs: 1.42",
"Whales: 67% long consensus",
"MVRV above 1.0 — on-chain bullish"
]
}
composite 範圍從 -1.0(強烈反對)到 +1.0(強烈確認), confidence 為 HIGH 或 MEDIUM,且 size_mult 是 0.0–1.5 的建議大小乘數。請參閱完整字段參考於 API 文檔.
如何根據回應行動
確認
市場背景支持您的方向。按照自己的進場和風險規則進行,可選擇根據 size_mult.
減少
信號混雜。考慮縮小倉位、設置更緊的止損,或等待更清晰的時機。
跳過
市場背景不支持此交易。暫時觀望,並在下一個機會時重新檢查。
準備好開始了嗎?
獲取免費密鑰,並在一分鐘內進行首次確認調用。
非財務建議。加密貨幣交易存在風險。