跳转到内容

ccxt 接入示例

ccxt 不改代码,只改 URL 即可让现有 Binance 策略驱动 panshi 组合。

  1. app.panshi.io → 目标组合详情页 → API Keys → 新建
  2. 复制 api_key + api_secret(secret 只展示一次)
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 BTC
order = 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());
  • fetchOHLCV / fetchFundingRate 透传上游数据源,行为一致
  • fetchMyTrades 返回的 trade id 是 panshi 独立命名空间,不要跟你真 Binance 账户对齐
  • setLeverage / setMarginMode 在模拟组合生效;绑了实盘子账户的组合会同步到 Binance
  • 不支持:listenKey / User Data Stream(用 panshi WebSocket 代替)、批量单、币本位合约、期权