I'm attempting to short sell with leverage on Kraken via the CCXT API with the following example code:
exchange = ccxt.kraken({
'apiKey': '****',
'secret': '****'
})
amount = ((exchange.fetch_balance()['USD']['total'])-10) / exchange.fetch_ticker('BTC/USD)[
'last']
exchange.create_order('BTC/USD', 'market', 'buy', amount, {'leverage': 2})
But it gives the error
ccxt.base.errors.InsufficientFunds: kraken {"error":["EOrder:Insufficient funds"]}
I assume its because it isn't "borrowing" the funds as I expect it to, but I'm unsure why. I am unable to choose a specific amount each time because I'm actually running the code over 4 coins and it picks the one with the most movement and creates an order accordingly, thus to always ask it to buy/sell 0.001 isn't logical. I have attempted to ask it to buy/sell the maximum available as governed by my current balance as given by the "amount" variable. The -10 term is just a little buffer to account for some slippage.