ccxt 接入示例
ccxt 不改代码,只改 URL 即可让现有 Binance 策略驱动 panshi 组合。
先在 panshi 生成组合级 API Key
Section titled “先在 panshi 生成组合级 API Key”- app.panshi.io → 目标组合详情页 → API Keys → 新建
- 复制
api_key+api_secret(secret 只展示一次)
Python
Section titled “Python”import ccxt
ex = ccxt.binance({ 'apiKey': '<panshi_api_key>', 'secret': '<panshi_api_secret>', 'options': {'defaultType': 'future'}, 'urls': { 'api': { 'fapiPublic': 'https://api.panshi.io/fapi/v1', 'fapiPrivate': 'https://api.panshi.io/fapi/v1', 'fapiPrivateV2': 'https://api.panshi.io/fapi/v2', }, },})
# 账户 / 余额print(ex.fetch_balance())
# 市价开仓 0.01 BTCorder = ex.create_order('BTC/USDT:USDT', 'market', 'buy', 0.01)print(order)
# 查持仓print(ex.fetch_positions(['BTC/USDT:USDT']))
# 限价单ex.create_order('BTC/USDT:USDT', 'limit', 'sell', 0.01, 70000)
# 撤单 / 平仓ex.cancel_order(order['id'], 'BTC/USDT:USDT')ex.create_order('BTC/USDT:USDT', 'market', 'sell', 0.01, None, {'reduceOnly': True})端到端走通了如下完整链路:
exchangeInfo → fetch_balance → market BUY → fetch_positions → fetch_my_trades → market SELL reduceOnly → limit create → fetch_open_orders → cancel_order。
import ccxt from 'ccxt';
const ex = new ccxt.binance({ apiKey: '<panshi_api_key>', secret: '<panshi_api_secret>', options: { defaultType: 'future' }, urls: { api: { fapiPublic: 'https://api.panshi.io/fapi/v1', fapiPrivate: 'https://api.panshi.io/fapi/v1', fapiPrivateV2: 'https://api.panshi.io/fapi/v2', }, },});
console.log(await ex.fetchBalance());与真 Binance 的差异
Section titled “与真 Binance 的差异”fetchOHLCV/fetchFundingRate透传上游数据源,行为一致fetchMyTrades返回的 trade id 是 panshi 独立命名空间,不要跟你真 Binance 账户对齐setLeverage/setMarginMode在模拟组合生效;绑了实盘子账户的组合会同步到 Binance- 不支持:
listenKey/ User Data Stream(用 panshi WebSocket 代替)、批量单、币本位合约、期权
- Python 原生示例 — 不走 ccxt,直接
/v1/* - Binance-compatible API — endpoint 清单
- 速率限制