Why isn’t the script running? With the GET requests (balances, account, klines) the signature works, only with the POST requests do I get this error message.
According to the documentation, the signature is also correct and the ORDER is also executed in Postman. Just not on my web server.
Here’s my code, exactly the same as in Postman:
$ClassServerTime = new APIREST($ServerTimeUrl);
$CallServerTime = $ClassServerTime->call(array());
$Time = $DecodeCallTime->serverTime;
$ApiKey = $myapikey; // the Api key provided by binance
$ApiSecret = $myapisecret; // the Secret key provided by binance
$Timestamp = 'timestamp='.$Time; // build timestamp type url get
$Signature = hash_hmac('SHA256',$Timestamp ,$ApiSecret); // build firm with sha256
$curl = curl_init();
$Symbol = 'BNBUSDT';
$Side = 'BUY';
$Type = 'MARKET';
$Quantity = '10';
CURLOPT_URL => 'https://testnet.binance.vision/api/v3/order?symbol='.$Symbol.'&side='.$Side.'&type='.$Type.'&quantity='.$Quantity.'×tamp='.$Time.'&signature='.$Signature,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => array(
$response = curl_exec($curl);
Check the response received to better diagnose the issue.
Sorry, but this is the response: [“code”:-1022,”msg”:”Signature for this request is not valid.”]
Are you using the API Key and Secret Key generated from
Are you sure it is working on Postman? Signature needs to generated from all query params combined, not just timestamp. Also, api/secret key isn’t the same on both testnet and mainnet.
As you can see, it’s exactly the same code as in Postman.
And as already said, the GET queries work on my web server, but not the POST queries because it doesn’t accept the signature here.
Unfortunately we cannot help debug custom code as there are too many factors and causes of errors. I suggest having a look at the official Binance PHP connector on Github.
This code snippet generated from postman is NOT the SAME code that runs the post request.
Since you can make the request in postman, it’s easy to print out the raw HTTP request sent to server, then compare it with your code.
And here you go:
// get orderbook
$response = sendRequest('GET', 'api/v3/depth?symbol=BNBUSDT&limit=5');
// get account information, make sure API key and secret are set
$response = signedRequest('GET', 'api/v3/account');
// place order, make sure API key and secret are set, recommend to test on testnet.
$response = signedRequest('POST', 'api/v3/order', [
'symbol' => 'BNBUSDT',
'side' => 'BUY',
'type' => 'LIMIT',
'timeInForce' => 'GTC',
'quantity' => 1,
'price' => 15,
// 'newClientOrderId' => 'my_order', // optional
'newOrderRespType' => 'FULL' //optional