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.

futures fetch_balance returns balances=0.0

See original GitHub issue

Hi, I’m working with ccxt version 1.62.29 in python. I have a testnet futures account in binance, which has 100000 USDT as margin balance. I can see it at testnet.binancefuture.com plataform. But I would like to get that data with my python script, using ccxt. Mi code is:

import sys
import numpy as np
import ccxt


from sandapi01 import *  #Sandbox futures
#from config_01 import *  #real futures

print('ccxt version:',ccxt.__version__ )

# from variable id
exchange_id = 'binance'
exchange_class = getattr(ccxt, exchange_id)
exchange = exchange_class({
   "apiKey": API[exchange_id],
    "secret": SECRET[exchange_id],
    "adjustForTimeDifference": True,
    "enableRateLimit": True,
    "options": {
        'defaultType': 'future',
    },
})

print('nombre:', exchange.name)
markets = exchange.load_markets()
print(exchange.requiredCredentials)  

balances= exchange.fetch_balance()
print(balances['USDT'])

And what I get is:

ccxt version: 1.62.29
nombre: Binance
{'apiKey': True, 'secret': True, 'uid': False, 'login': False, 'password': False, 'twofa': False, 'privateKey': False, 'walletAddress': False, 'token': False}
{'free': 0.0, 'used': 0.0, 'total': 0.0}

As you can see, the values are all zeros, and I don’t know how to get the actual USDT balance.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
pedruntucommented, Jan 29, 2022

Thank you Kroitor, that code works. I will do later what you say. Thanks again and best regards

0reactions
kroitorcommented, Jan 29, 2022

@pedruntu does this snippet work for you (with my testnet keys):

import ccxt

print('CCXT Version:', ccxt.__version__)

exchange = ccxt.binanceusdm({
        "apiKey": "16db8b4176457d63fdc0fd8b2c9418f669237cc9620c8c04c3b8973c7e0c39b3",
        "secret": "a0d07130b34f3debfcfe29d9faf5d2fcf6bdc3b83566d03a0a973a6bc4ab90a4"
})

exchange.set_sandbox_mode(True)
markets = exchange.load_markets()

# exchange.verbose = True  # uncomment for debugging purposes

balances= exchange.fetch_balance()
print(balances['USDT'])

If it works with my keypair, then replace it with your keys. If it doesn’t work with your keys, check your keys (make sure they’re correct and you’ve set proper permissions on them, if necessary, recreate your keypair and try a fresh new keypair, see: https://github.com/ccxt/ccxt/wiki/Manual#troubleshooting )

Read more comments on GitHub >

github_iconTop Results From Across the Web

ccxt fetchbalances() returns SPOT balance by default #13382
How can i get the futures balance with fetchBalance() now ? My regular fetchBalances() call without parameters is now translated to
Read more >
Exchanges — ccxt 2.4.71 documentation
Many exchanges do not return balances for your empty or unused accounts. In that case some currencies may be missing in returned balance...
Read more >
python - fetch_balance method in ccxt won't return all assets
It seems like fetchBalance only returns one currency at a time. To get USDT as the asset to ... import ccxt exchange =...
Read more >
Group And Resources – Bybit API Docs - GitHub Pages
Deprecated Fields of self_ratio and platform_ratio, it is returned as 0 currently ... Returns all wallet balances if no parameters are passed.
Read more >
CCXT – CryptoCurrency eXchange Trading Library - npm
The CCXT library is used to connect and trade with cryptocurrency exchanges and payment processing services worldwide. It provides quick access to market...
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