binance.exceptions.BinanceAPIException: APIError(code=-1022): Signature for this request is not valid.
always...
@includeleec can you give an example of how you're using the API.
from binance.client import Client
class Monitor:
def __init__(self):
self.bac = Client(KEY,SERCRET)
def my_balance(self):
print(self.bac.get_account(recvWindow=RECV_WINDOW))
m = Monitor()
m.my_balance()
sometimes ok,sometimes throw error.
@includeleec can you check the value you're using for recvWindow, the API docs indicate it should be an int for the number of milliseconds the request is valid for.
If I send a string of say "4000" then I also get the Signature invalid error back from the Binance API.
RECV_WINDOW=6000000, this setting i copy from binance example
#!/usr/bin/env python
api_key = 'key_here'
api_secret = 'secret_here'
from binance.client import Client
client = Client(api_key, api_secret)
time_res = client.get_server_time()
RECV_WINDOW=6000000
class Monitor:
def __init__(self):
self.bac = Client(api_key,api_secret)
def my_balance(self):
print(self.bac.get_account(recvWindow=RECV_WINDOW))
m = Monitor()
m.my_balance()
It's working for me, did you set up your API key correctly?
Hi,
same issue with invalid invalid signature.
Thanks
@laurent101 please provide examples to add to the discussion.
There are a range of things that can cause this, some that I'm aware of are listed in the FAQ here https://github.com/sammchardy/python-binance#user-content-faq
I ran the code as posted above by @jmynes and ended up with an invalid signature error message. Both my key and secret (both strings) are correct.
I found the issue which is related to the API version issue I posted. I had added and changed the version of the REST API from 'v1' to 'v3' which is the update on the Binance website. As @sammchardy correctly pointed out this requires an amended signature. Sorry for the inconvenience caused.
Im encountering the same issue on v1 as @includeleec even when I add "recvWindow=6000000" to the parameters. the signature is sometimes valid and sometimes not valid.
same issue. seems to fail randomly
Had this issue, however appending recvWindow=5000 to the request seems to fix it for me.
Very strange especially since the API docs state that
An additional parameter, recvWindow, may be sent to specific the number of milliseconds after timestamp the request is valid for. If recvWindow is not sent, it defaults to 5000 millisecond.
and yet the signature is invalid unless I provide a recvWindow ...
EDIT: Seems like get_account doesn't work even with recvWindow=5000
For anyone still running into this issue, I've been referencing sammchardy's extremely helpful code here as a template for my own project, and I was continually running into this error as well. Here is an example standalone code snippet that I was finally able to get working:
api_key = '' api_secret = ''
request_url = 'https://api.binance.com/api/v3/openOrders?'
timestamp = int(time.time() * 1000) symbol = 'BNBBTC'
querystring = urlencode({'symbol' : symbol, 'timestamp' : timestamp})
signature = hmac.new(api_secret.encode('utf-8'), querystring.encode('utf-8'), hashlib.sha256).hexdigest()
request_url += querystring + '&signature=' + signature
r = requests.get(request_url, headers={"X-MBX-APIKEY": api_key})
Has anyone found a fix for this yet? I am running into it when calling .getAccount(). I've tried setting RECV_WINDOW manually without success.
I'm also running into this intermittently when initiating various sales.
I've updated some dependencies in v0.5.10 including certifi which has resolved this issue for me for the moment. Let me know if it helps.
I just updated everything today but am also still receiving this error when calling the withdraw method. All the signed GET withdraw api functions seem to work fine though (deposithistory, withdrawhistory, depositaddress). I've tried increasing the recvWindow up to 6000000 ms but with no success.
getting this error when placing orders, has anyone been able to find a solution? tried @shammy12's solution but got a similar error >> " {'code': -1022, 'msg': 'Signature for this request is not valid.'}"
@meko0019 Can you give an example function call that produces that error? I'm hitting it all over the place, but one common roadblock I'm seeming to hit is when selling ADA. ADA is only buyable/sellable in whole increments; I'm wondering if the API is expecting a decimal for the purposes of the signature...
(FWIW I have updated and am still seeing this pretty commonly as well)
EDIT: I could not reproduce the bug by making that change (int -> float). Is there some way for an extra parameter to be included in the API response/signature by accident?
I have released v0.5.13 which ensures orders are correct when generating signature and sending to server. This seems to resolve issues in my tests.
Let me know if it's still occurring.