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.

Binance Futures - Change Leverage (Python)

See original GitHub issue

I’m not able to change the leverage with the “fapiPrivate_post_leverage” function. Can someone help me?

  • OS: Windows 10 x64
  • Programming Language version: Python 3.8.2
  • CCXT version: 1.28.3

Code:

import ccxt

binance = ccxt.binance({
    "options": {"defaultType": "future"},
    "timeout": 30000,
    "apiKey":"xxx",
    "secret": "xxx",
    "enableRateLimit": True,
})

binance.fapiPrivate_post_leverage("BTC/USDT", 10)

Error message:

TypeError: inner() takes from 1 to 2 positional arguments but 3 were given

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
kroitorcommented, May 19, 2020

Hi!

Please, see:

  1. how unified ccxt symbols differ from exchange-specific market ids: https://github.com/ccxt/ccxt/wiki/Manual#symbols-and-market-ids
  2. how implicit API endpoints are called: https://github.com/ccxt/ccxt/wiki/Manual#implicit-api-methods

You should pass an object containing the params, instead of supplying the params as arguments:

import ccxt

binance = ccxt.binance({
    "options": {"defaultType": "future"},
    "timeout": 30000,
    "apiKey":"xxx",
    "secret": "xxx",
    "enableRateLimit": True,
})

binance.load_markets()  # load markets to get the market id from a unified symbol
market = binance.markets['BTC/USDT']
binance.fapiPrivate_post_leverage({
    "symbol": market['id'],  # convert a unified CCXT symbol to an exchange-specific market id
    # "symbol": "BTCUSDT",  # same thing, note there's no slash in the exchange-specific id
    "leverage": 10,
})

Let us know if the above does not help.

1reaction
bluesme519commented, Mar 22, 2021

@bluesme519 if one call to set the leverage works, and then the other call fails, then please, post the request+response for both calls:

    binance.enableRateLimit = True

    binance.load_markets()  # load markets to get the market id from a unified symbol
    
    binance.verbose = True
    
    market = binance.markets['BTC/USDT']
    
    binance.fapiPrivate_post_leverage({
        "symbol": market['id'],  # convert a unified CCXT symbol to an exchange-specific market id
        # "symbol": "BTCUSDT",  # same thing, note there's no slash in the exchange-specific id
        "leverage": 3,
    })
    
    binance.fapiPrivate_post_leverage({
        # "symbol": market['id'],  # convert a unified CCXT symbol to an exchange-specific market id
        "symbol": "BTCUSDT",  # same thing, note there's no slash in the exchange-specific id
        "leverage": 3,
    })

If the above works, that means you’re violating this part of the Manual: https://github.com/ccxt/ccxt/wiki/Manual#notes-on-rate-limiter

If every call to set the leverage fails for you, i’d recommend contacting Binance tech support, since it may be that Cloudflare flagged your IP (try from a different location to rule that out) or it could be related to a flag on your account. In both those cases only Binance can really help resolve it.

The code I made was reusing the same instance over and over again. I need to change it to reduce burdens of binance api server. Thank you so much for your guidance for all bunch of stuffs!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can i adjust the leverage with Bianance API
To change leverage with python-binance library you should use futures_change_leverage() method. Code example: new_lvrg = ...
Read more >
Futures Trading with python-binance | Analytics Vidhya
This will ensure that all trades you execute in the terminal session for the specified symbol take on the leverage set above. If...
Read more >
Binance API — python-binance 0.2.0 documentation
Change user's initial leverage of specific symbol market. https://binance-docs.github.io/apidocs/futures/en/#change-initial-leverage-trade.
Read more >
how to get the max leverage for futures using the binance API?
GET /fapi/v1/leverageBracket get the different leverages from here. Thanks for your answer.
Read more >
Change Log – Binance API Documentation - GitHub Pages
New endpoint GET /fapi/v1/income/asyn to get Download Id For Futures ... Previous Leverage Update event ACCOUNT_CONFIG_UPDATE expanded as account ...
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