jaggedsoft / php-binance-api

PHP Binance API is an asynchronous PHP library for the Binance API designed to be easy to use. https://github.com/binance-exchange/php-binance-api
MIT License
606 stars 496 forks source link

code":-1021,"msg":"Timestamp for this request is outside of the recvWindow. #143

Closed LiveRock closed 6 years ago

LiveRock commented 6 years ago

Error 1021

Short Description: Tried the 0.example with valid credentials with the following errors: signedRequest error: {"code":-1021,"msg":"Timestamp for this request is outside of the recvWindow."} balanceData error: Please make sure your system time is synchronized, or pass the useServerTime option.

Platform: CentOS

php version:

Long descrption Tried the 0.example with valid credentials with the following errors: signedRequest error: {"code":-1021,"msg":"Timestamp for this request is outside of the recvWindow."} balanceData error: Please make sure your system time is synchronized, or pass the useServerTime option.

code

require 'vendor/autoload.php';
$api = new Binance\API("<api key>","<secret>");
$ticker = $api->prices();
print_r($ticker); // List prices of all symbols
echo "Price of BNB: {$ticker['BNBBTC']} BTC";

result Price of BNB: BTC. signedRequest error: {"code":-1021,"msg":"Timestamp for this request is outside of the recvWindow."} balanceData error: Please make sure your system time is synchronized, or pass the useServerTime option. BTC owned: ETH owned: Estimated Value: 0 BTC

thank you

dmzoneill commented 6 years ago

Please see the following page

https://github.com/jaggedsoft/php-binance-api/wiki/4.-Troubleshooting

LiveRock commented 6 years ago

Added the line just before the api call with key and secret:

<<?php require 'vendor/autoload.php'; $api = new Binance\API("key","secret");

// PHP // Fix signedRequest error: {"code":-1022,"msg":"Signature for this request is not valid." $api->useServerTime(); .....

Still having the same error

LiveRock commented 6 years ago

Error now is 1022 instead of 1021

dmzoneill commented 6 years ago

On your console, can you post the result of the following

curl -vvv https://api.binance.com
LiveRock commented 6 years ago

This from my OSX machine, not my server:

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

dmzoneill commented 6 years ago

Hey, the output from your osx machine is no value here.

In order to find the source of the issue, there are a number of things you need to validate/fix.

By running the above command you knock 4 of the items of the list.

dmzoneill commented 6 years ago

If you have no console access you could try somethibg like


<?php

print "<pre>";
print shell_exec ("curl -vvv https://api.binance.com 2>&1");
print "</pre>";
LiveRock commented 6 years ago

You are right. I copied and paste Binance API credentials again and now it works. Many thanks!

LiveRock commented 6 years ago

Another question not related to the issue. Is it possible for me to extract the following information at a given date/time? Cryptocurrency: for example, BTC Exchange currency: for example, USDT Volumne % change 24 hour High Low

dmzoneill commented 6 years ago

i don't think there is a function for that or specifically exposed by the binance API.

might be a nice feature here if you want to create a full request, if i understand you correctly

psuedo code

function getPErcentageChangeBetweenDates( older, newer )
{
   // get average on these dates from candle information
   // minus the 2 averages
   $diff = ( $older-avg/ $newer-avg ) * 100;
   return $diff;
}