binance AuthenticationError

See original GitHub issue
  • OS: mac
  • Programming Language version: python
  • CCXT version: latest
from pprint import pprint
import ccxt

API_KEY = "***"
SECRET = "****"

class BinanceApi:
    def __init__(self):
        self.binance_api = ccxt.binance(
            {
                "apiKey": API_KEY,
                "secret": SECRET,
                "options": {"defaultType": "future"},
                "enableRateLimit": True,
            }
        )

    def get_position(self, symbol):
         self.binance_api.fapiPrivateGetPositionRisk()

When I run get_position especially fapiPrivateGetPositionRisk(), I got the error shown below. When I run different functions such as load_markets(), it succeeded. I’m pretty sure that the API is correct and I checked the options of “Enable Margin Loan, Repay & Transfer” in binance website.

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/ccxt/base/exchange.py", line 656, in fetch
    response.raise_for_status()
  File "/usr/local/lib/python3.10/site-packages/requests/models.py", line 960, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://fapi.binance.com/fapi/v1/leverageBracket?timestamp=1652001719852&recvWindow=5000&signature=a245519531ad724b13876b70b00e616de7ab9bdfd5f5f2e96b09c5eb158ea759

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/opt/start.py", line 77, in <module>
    position = binance.get_position(symbol)
  File "/root/opt/bi_api.py", line 21, in get_position
    balance = self.binance_api.fetchPositionsRisk()
  File "/usr/local/lib/python3.10/site-packages/ccxt/binance.py", line 4733, in fetch_positions_risk
    self.load_leverage_brackets()
  File "/usr/local/lib/python3.10/site-packages/ccxt/binance.py", line 4592, in load_leverage_brackets
    response = getattr(self, method)(query)
  File "/usr/local/lib/python3.10/site-packages/ccxt/base/exchange.py", line 496, in inner
    return entry(_self, **inner_kwargs)
  File "/usr/local/lib/python3.10/site-packages/ccxt/binance.py", line 5064, in request
    response = self.fetch2(path, api, method, params, headers, body, config, context)
  File "/usr/local/lib/python3.10/site-packages/ccxt/base/exchange.py", line 543, in fetch2
    return self.fetch(request['url'], request['method'], request['headers'], request['body'])
  File "/usr/local/lib/python3.10/site-packages/ccxt/base/exchange.py", line 672, in fetch
    skip_further_error_handling = self.handle_errors(http_status_code, http_status_text, url, method, headers, http_response, json_response, request_headers, request_body)
  File "/usr/local/lib/python3.10/site-packages/ccxt/binance.py", line 5042, in handle_errors
    self.throw_exactly_matched_exception(self.exceptions['exact'], error, feedback)
  File "/usr/local/lib/python3.10/site-packages/ccxt/base/exchange.py", line 561, in throw_exactly_matched_exception
    raise exact[string](message)
ccxt.base.errors.AuthenticationError: binance {"code":-2015,"msg":"Invalid API-key, IP, or permissions for action, request ip: "my IP address"}```

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
kroitorcommented, May 13, 2022

@uioiuioi have you checked the API key permissions on the Binance website in your API account settings? Does it have the necessary futures-trading permissions ?

1reaction
kroitorcommented, May 13, 2022

@uioiuioi yep, it’s a known common problem, recreating the API keypair usually helps. Thanks for the feedback!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Apikey is not authorize - Futures API
Hi I can not connect to the binance's testnet. OS: Ubuntu 20.04 country Brazil I ... checkRequiredCredentials() // throw AuthenticationError
Read more >
ccxt-dev/ccxt - Gitter
AuthenticationError : binance userDataStream endpoint requires apiKey credential. if I'm trying to do the same auth as on regular cctx.
Read more >
CCXT testnet AuthenticationError: binance {"code":-2015,"msg":"
I'm new on ccxt and binance API, I used the python code of documentation of ccxt to create a BUY order but I...
Read more >
ACH: Multifactor Authentication Error - Binance.US
Our ACH integration process through Plaid may not support the multifactor authentication that you have set up with your banking institution.
Read more >
Change Log – Binance API Documentation - GitHub Pages
GET /fapi/v1/aggTrades. 2020-12-08. WEBSOCKET. New field e for event type in payload of streams <symbol>@bookTicker ...
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