我尝试在 python 中使用 phemex API 创建一个杠杆交易机器人。我是这样连接的:
exchange = ccxt.phemex({
'apiKey': API_KEY,
'secret': API_SECRET,
'enableRateLimit': True,
'verbose': True
})
然后我通过这个片段得到了我在 phemex 上的实际杠杆,以及我必须交易多少免费 BTC。
params={"type":"swap","code":"BTC"}
response = exchange.fetch_balance(params=params)
#leverage = response['info']['data']['positions']['leverage']
positions = response['info']['data']['positions']
res = next((sub for sub in positions if sub['leverage']), None)
leverage = res['leverage']
free_BTC = response['BTC']['free']
used_BTC = response['BTC']['used']
直到这里一切都对我有用。现在我找到了一个更改杠杆的代码片段:
exchange.load_markets()
symbol = 'BTC/USD'
market = exchange.market(symbol)
exchange.verbose = Trueparams = {
'symbol': market['id'],
'leverage': 10
}
response = ex.privatePutPositionsLeverage(params)
pprint(response)
但是杠杆仍然保持在旧值。有人可以帮我解决这个问题。太感谢了。
PS:这些是可用的功能:
{'loadMarkets': True, 'cancelAllOrders': True, 'cancelOrder': True, 'cancelOrders': False, 'CORS': False, 'createDepositAddress': False, 'createLimitOrder': True, 'createMarketOrder': True, 'createOrder': True, 'deposit': False, 'editOrder': 'emulated', 'fetchBalance': True, 'fetchClosedOrders': True, 'fetchCurrencies': True, 'fetchDepositAddress': True, 'fetchDeposits': True, 'fetchL2OrderBook': True, 'fetchLedger': False, 'fetchMarkets': True, 'fetchMyTrades': True, 'fetchOHLCV': True, 'fetchOpenOrders': True, 'fetchOrder': True, 'fetchOrderBook': True, 'fetchOrderBooks': False, 'fetchOrders': True, 'fetchOrderTrades': False, 'fetchStatus': 'emulated', 'fetchTicker': True, 'fetchTickers': False, 'fetchTime': False, 'fetchTrades': True, 'fetchTradingFee': False, 'fetchTradingFees': False, 'fetchFundingFee': False, 'fetchFundingFees': False, 'fetchTradingLimits': False, 'fetchTransactions': False, 'fetchWithdrawals': True, 'privateAPI': True, 'publicAPI': True, 'signIn': False, 'withdraw': False}
最好的问候丹尼尔