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.py fetch_positions_risk() - Missing arguments?

See original GitHub issue

https://github.com/ccxt/ccxt/blob/b459dd73c99c744e7f623ed56aa93e646b1f59f8/python/ccxt/binance.py#L5109

I’m getting an error here using the default binance exchange object and calling fetchPositions() with:

binance.fetchPositions(params={'type': 'future'})

From what I see in the code, fetch_positions_risk() is calling load_leverage_brackets() but not passing params. The error below shouldn’t be happening imo if I’m passing params to fetch_positions_risk (i.e., it should be passed through so L5109 should be self.load_leverage_brackets(params=params). Am I completely off here?

    def load_leverage_brackets(self, reload=False, params={}):
        self.load_markets()
        # by default cache the leverage bracket
        # it contains useful stuff like the maintenance margin and initial margin for positions
        leverageBrackets = self.safe_value(self.options, 'leverageBrackets')
        if (leverageBrackets is None) or (reload):
            method = None
            defaultType = self.safe_string(self.options, 'defaultType', 'future')
            type = self.safe_string(params, 'type', defaultType)
            query = self.omit(params, 'type')
            if type == 'future':
                method = 'fapiPrivateGetLeverageBracket'
            elif type == 'delivery':
                method = 'dapiPrivateV2GetLeverageBracket'
            else:
>               raise NotSupported(self.id + ' loadLeverageBrackets() supports linear and inverse contracts only')
E               ccxt.base.errors.NotSupported: binance loadLeverageBrackets() supports linear and inverse contracts only

venv/lib/python3.8/site-packages/ccxt/binance.py:4943: NotSupported

Happy to open a PR to update this if need be…I’ve just started using ccxt though so may not be on the right track.

Edit: Seems the defaultType is set to 'spot' so that’s why this is failing:

if (leverageBrackets is None) or (reload):
            method = None
            defaultType = self.safe_string(self.options, 'defaultType', 'future')
            type = self.safe_string(params, 'type', defaultType)
            query = self.omit(params, 'type')
            if type == 'future':
                method = 'fapiPrivateGetLeverageBracket'
            elif type == 'delivery':
                method = 'dapiPrivateV2GetLeverageBracket'
            else:
                raise NotSupported(self.id + ' loadLeverageBrackets() supports linear and inverse contracts only')

Definitely think params should get passed through here…simple fix

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
hedeer-showkcommented, Aug 3, 2022

@ttodua thanks and makes sense. I had the js fix in without issue and checked it transpiled properly into php and python by reading the code. Next time I’ll PR it there but I would like to get the whole test suite working anyway.

1reaction
carlosmieicommented, Jul 27, 2022

Hello @hedeer-showk, you’re right params should be propagated to load_leverage_brackets. However, to avoid conflicts, if you’re handling ‘futures’ it is advisable to instantiate binanceusdm instead

exchange = ccxt.binanceusdm({
    'apiKey': 'YOUR_API_KEY',
    'secret': 'YOUR_SECRET_KEY',
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Exchanges — ccxt 2.4.71 documentation
The ccxt library is a collection of available crypto exchanges or exchange classes. Each class implements the public and private API for a...
Read more >
Inputting parameters for Binance API in Python - Stack Overflow
I'm trying to get information for a coin pairing called ADAETH for an example. this is the line, but I can't figure the...
Read more >
python-binance Documentation - Read the Docs
The Binance API documentation references a timestamp parameter, this is generated for ... added missing dateparser dependency to setup.py.
Read more >
Welcome to python-binance v1.0.16 — python-binance 0.2.0 ...
This is an unofficial Python wrapper for the Binance exchange REST API v3. ... quantity=100) # get all symbol prices prices = client.get_all_tickers()...
Read more >
binance-connector-python - Python package - Snyk
Looks like binance-connector-python is missing a security policy. ... from binance.spot import Spot client = Spot() print(client.time()) client ...
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