question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to use all my funds on FTX futures

See original GitHub issue

I’m unable to place a leveraged trade on FTX. I’m trying to change the leverage and then open a limit order. When I try this I get an InsufficientFunds Error. But when I try to open the same amount at the same price on FTX itself it goes through. Maybe my max leverage didn’t change?

Code:

import ccxt
import pandas as pd

connection = ccxt.ftx({'apiKey': 'xxx', 'secret': 'xxx', 'enableRateLimit': True, 'options' : {'defaultType': 'future'}})

market = 'AAVE/USD'
baseCurrency = 'USD'
reduceAmount = 0.295 # Only use 70.5% of capital
leverage = 3
limitPrice = 300

balance = connection.fetch_balance()['total'][baseCurrency]

connection.private_post_account_leverage({'leverage': leverage})
amount = float(connection.amount_to_precision(market, balance * (1 - reduceAmount) * leverage / limitPrice))

print(amount)

limitOrder = connection.create_order(market, 'limit', 'buy', amount, limitPrice, {'PostOnly': True})

Traceback:

0.14
Traceback (most recent call last):
  File "C:\Users\Gladi\AppData\Local\Programs\Python\Python39\lib\site-packages\ccxt\base\exchange.py", line 592, in fetch        
    response.raise_for_status()
  File "C:\Users\Gladi\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: BAD REQUEST for url: https://ftx.com/api/orders

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\trabro2\test\fetchBalance.py", line 19, in <module>
    limitOrder = connection.create_order(market, 'limit', 'buy', amount, limitPrice, {'PostOnly': True})
  File "C:\Users\Gladi\AppData\Local\Programs\Python\Python39\lib\site-packages\ccxt\ftx.py", line 1084, in create_order
    response = getattr(self, method)(self.extend(request, params))
  File "C:\Users\Gladi\AppData\Local\Programs\Python\Python39\lib\site-packages\ccxt\base\exchange.py", line 466, in inner
    return entry(_self, **inner_kwargs)
  File "C:\Users\Gladi\AppData\Local\Programs\Python\Python39\lib\site-packages\ccxt\base\exchange.py", line 491, in request
    return self.fetch2(path, api, method, params, headers, body)
  File "C:\Users\Gladi\AppData\Local\Programs\Python\Python39\lib\site-packages\ccxt\base\exchange.py", line 487, in fetch2
    return self.fetch(request['url'], request['method'], request['headers'], request['body'])
  File "C:\Users\Gladi\AppData\Local\Programs\Python\Python39\lib\site-packages\ccxt\base\exchange.py", line 608, in fetch
    self.handle_errors(http_status_code, http_status_text, url, method, headers, http_response, json_response, request_headers, request_body)
  File "C:\Users\Gladi\AppData\Local\Programs\Python\Python39\lib\site-packages\ccxt\ftx.py", line 1741, in handle_errors
    self.throw_exactly_matched_exception(self.exceptions['exact'], error, feedback)
  File "C:\Users\Gladi\AppData\Local\Programs\Python\Python39\lib\site-packages\ccxt\base\exchange.py", line 505, in throw_exactly_matched_exception
    raise exact[string](message)
ccxt.base.errors.InsufficientFunds: ftx {"error":"Not enough balances","success":false}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
AlgoQcommented, Mar 1, 2021

Yeah thanks, it works for me. I tried AAVE/PERP before which gave me a KeyError, but AAVE-PERP works. It was pretty confusing because most markets in ccxt uses a slash instead of a dash.

0reactions
kroitorcommented, Mar 1, 2021

@Gladi-iwnl as far as I see, the above should also answer your question as well.

Closing this for now. Feel free to reopen it or just ask further questions if any.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Negative Balances on FTX - FTX Exchange
If you don't have enough credit or funds in your debit account to cover, there's an immediate rejection. If, for some reason your...
Read more >
SEC Charges Samuel Bankman-Fried with Defrauding ...
Defendant concealed his diversion of FTX customers' funds to crypto trading firm Alameda Research while raising more than $1.8 billion from ...
Read more >
FTX says it's removing trading and withdrawals, moving digital ...
The new FTX CEO says the bankrupt crypto exchange is “in the process of removing trading and withdrawal functionality” and it is “moving...
Read more >
At least $1 billion of client funds missing at failed crypto firm FTX
While it is known that FTX moved customer funds to Sam Bankman-Fried's Alameda trading desk, the missing funds are reported here for the...
Read more >
At least $1 billion of client funds missing at failed crypto firm ...
One source put the missing amount at about $1.7 billion. ... While it is known that FTX moved customer funds to Alameda, the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found