Git Product home page Git Product logo

Comments (42)

ffigiel avatar ffigiel commented on July 17, 2024 6

I managed to resolve my problem. It seems that the last two query params need to be timestamp and signature, in this order.

from python-binance.

junw3i avatar junw3i commented on July 17, 2024 4

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.

from python-binance.

shammy12 avatar shammy12 commented on July 17, 2024 4

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})

from python-binance.

laurent101 avatar laurent101 commented on July 17, 2024 2

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.

from python-binance.

tevonsb avatar tevonsb commented on July 17, 2024 2

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.

from python-binance.

UsernameGitiHub avatar UsernameGitiHub commented on July 17, 2024 2

I managed to resolve my problem. It seems that the last two query params need to be timestamp and signature, in this order.
pleas help me am geting the same problem
timestamp = int(time.time() * 1000)
params = {

       #'recvWindow': 5000,59999 6000000
       'recvWindow': 6000,
       'timestamp': timestamp
    }

i dont know if anybody still have this problem with wrong nonce in the Request, but i can tell you all the right solution is easy, you just need to send instead of timestemp the timestemp in miliseconds and not in seconds, here is a example:

$nonce=round(microtime(true) * 1000); //time();
$recwindow=5000;
//-- $url='symbol='.$symbol.'&side=SELL&type=MARKET&quantity='.$VolumeCoin.'&recvWindow='.$recwindow.'&timestamp='.$nonce;
//--
$sign=hash_hmac('SHA256',$url,$apisecret);
$url=$url.'&signature='.$sign;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-MBX-APIKEY:'.$apikey));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, "https://api.binance.com/api/v3/order");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$url);
$execResult = curl_exec($ch);
$Auftrag = json_decode($execResult, true);

from python-binance.

approved788 avatar approved788 commented on July 17, 2024 2

May be my case would be helpful to someone. When I submitted wrong API key i got this error, so check once again if you entered your keys correctly.
Then when i tried to trade "BTC USDT" i got the same. If you do not see 'Enable Futures' in api management - first create futures wallet. Than enable it, and PAY ATTENTION that after this step api_key is changed, so don`t forget it! Your api_secret_key will stay the same.
In 2021 max val for this: RECV_WINDOW=60000

Tested on solution given here: thirstygerry commented on 24 Apr 2020
Can confirm that everything works fine.

from python-binance.

junkheadd avatar junkheadd commented on July 17, 2024 1

same issue. seems to fail randomly

from python-binance.

frosty00 avatar frosty00 commented on July 17, 2024 1

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

from python-binance.

meko0019 avatar meko0019 commented on July 17, 2024 1

@5outh all of the order functions including test_order were producing that error. A new API key seems to have solved it for me.

from python-binance.

amirvenus avatar amirvenus commented on July 17, 2024 1

My problem was fixed upon using math.ceil() on the quantity

from python-binance.

thirstygerry avatar thirstygerry commented on July 17, 2024 1

If someone still needs it, I created an example python script that returns your balances.
It includes a valid signature.
https://github.com/thirstygerry/binance-python

from python-binance.

sammchardy avatar sammchardy commented on July 17, 2024

@includeleec can you give an example of how you're using the API.

from python-binance.

includeleec avatar includeleec commented on July 17, 2024
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.

from python-binance.

sammchardy avatar sammchardy commented on July 17, 2024

@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.

from python-binance.

includeleec avatar includeleec commented on July 17, 2024

RECV_WINDOW=6000000,
this setting i copy from binance example

from python-binance.

jmynes avatar jmynes commented on July 17, 2024
#!/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?

from python-binance.

laurent101 avatar laurent101 commented on July 17, 2024

Hi,

same issue with invalid invalid signature.

Thanks

from python-binance.

sammchardy avatar sammchardy commented on July 17, 2024

@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

from python-binance.

laurent101 avatar laurent101 commented on July 17, 2024

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.

from python-binance.

5outh avatar 5outh commented on July 17, 2024

I'm also running into this intermittently when initiating various sales.

from python-binance.

sammchardy avatar sammchardy commented on July 17, 2024

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.

from python-binance.

dafrizzy avatar dafrizzy commented on July 17, 2024

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.

from python-binance.

meko0019 avatar meko0019 commented on July 17, 2024

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.'}"

from python-binance.

5outh avatar 5outh commented on July 17, 2024

@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?

from python-binance.

sammchardy avatar sammchardy commented on July 17, 2024

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.

from python-binance.

5outh avatar 5outh commented on July 17, 2024

Very interesting, I'll have to try that. I was still seeing issues (with a 2-week old key) yesterday, but they seem less frequent. That may be because I'm placing fewer orders though...

Will ping back if changing the API key doesn't fix things. Thanks for your work on this project!

from python-binance.

vazzilly avatar vazzilly commented on July 17, 2024

getting the same message with PHP / CURL


$ch = curl_init();
$timestamp = round(microtime(true) * 1000);
$secret = 'bmrLfulh***************************KladNAcI4qLg';
$querystring = urlencode("'timestamp' : ".$timestamp."}");
$signature = hash_hmac('SHA256', $secret, $querystring);

curl_setopt($ch, CURLOPT_URL, "https://api.binance.com/api/v3/order?symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=50000&timestamp=".$timestamp."&signature=".$signature."");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = "X-Mbx-Apikey: EAXHTI2ZyuWqVdV**********ptYUnl2XYM9f";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
print_r($result);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);

from python-binance.

dafrizzy avatar dafrizzy commented on July 17, 2024

Updated to v0.5.13, made a new api key, received a "Name is empty" exception so I withdrew manually then tried it again and it seems to be working perfectly now. Thanks for the update and I really appreciate your awesome work on this project!

from python-binance.

sammchardy avatar sammchardy commented on July 17, 2024

Going to close this now, v0.5.13.

Adding a note about regenerating API key and secret to FAQs

from python-binance.

Shariffintech avatar Shariffintech commented on July 17, 2024

Can someone explain what the "recv_window" does?

from python-binance.

LiYijin avatar LiYijin commented on July 17, 2024

my version is 0.5.17, but i still met this problem.
Thanks @sammchardy

from python-binance.

Kato-Official avatar Kato-Official commented on July 17, 2024

@LiYijin kindly note now it's at version 0.6. Cheers

from python-binance.

jasonmellone avatar jasonmellone commented on July 17, 2024

@5outh all of the order functions including test_order were producing that error. A new API key seems to have solved it for me.

I re-installed from git
sudo pip install git+git://github.com/sammchardy/python-binance.git

and still received the error. then generated a new api key and reran. this resolved the problem.

from python-binance.

ffigiel avatar ffigiel commented on July 17, 2024

In my case only the /api/v3/order API endpoint returns this error. Other signed APIs, like /api/v3/account, work fine.

(please note that I'm not using this library, but this discussion seems to be directed at binance rather than this library anyway)

from python-binance.

lars71dkk avatar lars71dkk commented on July 17, 2024

I had this problem a lot, then I updated to 0.6.2 and generated a new API key. Havent' had the problem since! :-)

from python-binance.

frosty00 avatar frosty00 commented on July 17, 2024

https://github.com/ccxt/ccxt

from python-binance.

UsernameGitiHub avatar UsernameGitiHub commented on July 17, 2024

Hey There, i did find a solution for me with PHP and wated to share it to you, i was also getting this error amm the time and the following PHP Code did work then:

                  ```

//--API Call
$nonce=time();
//--
$uri='https://api.binance.com/api/v3/account?recvWindow=10000000000000000&timestamp='.$nonce;
$strsign='recvWindow=10000000000000000&timestamp='.$nonce;
//--
$sign=hash_hmac('SHA256',$strsign,$apisecret);
$uri=$uri.'&signature='.$sign;
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-MBX-APIKEY:'.$apikey));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, $uri);
$execResult = curl_exec($ch);
$Balances = json_decode($execResult, true);
var_dump($Balances);



from python-binance.

camaris avatar camaris commented on July 17, 2024

Sorry if this is the wrong place to post my findings, but I struggled a lot with a similar issue on 'Signature for this request is not valid.'. Perhaps this can be added to the FAQ https://github.com/sammchardy/python-binance#user-content-faq.

Take care of having the correct parameters when you call a function:

client.order_market_buy(symbol='BTCUSDT',quantity=('0.001264',1234),timestamp=client.get_server_time())
=> ERROR 'Signature for this request is not valid.'

client.order_market_buy(symbol='BTCUSDT',quantity=('0.001264'),timestamp=client.get_server_time())
=> NO ERROR

client.order_market_buy(symbol='BTCUSDT',quantity='0.001264',1234,timestamp=client.get_server_time())
=> NO ERROR

Off course the parameter quantity=('0.001264',1234) is wrong (had a bug in my code) but the message could be more clear (e.g. wrong amount).

from python-binance.

scottbecker avatar scottbecker commented on July 17, 2024

If it helps anyone, passing None values to create_order will also cause this since the None parameter is used in the query_string used for calculating the signature but not in the query string sent to the server.

e.g. don't use create_order(price = None,.....)

from python-binance.

noahwalugembe avatar noahwalugembe commented on July 17, 2024

I managed to resolve my problem. It seems that the last two query params need to be timestamp and signature, in this order.
pleas help me am geting the same problem
timestamp = int(time.time() * 1000)
params = {

       #'recvWindow': 5000,59999 6000000
       'recvWindow': 6000,
       'timestamp': timestamp
    }

from python-binance.

den4ess avatar den4ess commented on July 17, 2024

Still having "Signature for this request is not valid" on TESTNET async client.futures_account_balance. Tried with parameters and without them. Also tried different recvWindow.
1.0.16

from python-binance.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.