Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binance: Timestamp for this request is outside of the recvWindow #936

Closed
dnld23 opened this issue Dec 22, 2017 · 37 comments
Closed

Binance: Timestamp for this request is outside of the recvWindow #936

dnld23 opened this issue Dec 22, 2017 · 37 comments
Assignees

Comments

@dnld23
Copy link
Contributor

dnld23 commented Dec 22, 2017

I modified returned responses in Exchange.php to get more information. This is what i get:

Error when loading details: binance GET https://api.binance.com/api/v3/account?timestamp=1513948454747&signature=xxxxxxxxxxxx

400 not accessible from this location at the moment

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

@kroitor kroitor changed the title Binance - fetch_balances query returns 400 ERROR Binance Timestamp for this request is outside of the recvWindow Dec 22, 2017
@kroitor kroitor changed the title Binance Timestamp for this request is outside of the recvWindow Binance: Timestamp for this request is outside of the recvWindow Dec 22, 2017
@kroitor kroitor self-assigned this Dec 22, 2017
@kroitor
Copy link
Member

kroitor commented Dec 22, 2017

Hi! Do you have internet time synchronization enabled in your system clock settings?

@paroxysm
Copy link

I'm also seeing this error on my end. I'm running on an ubuntu VM and yes, time sync is enabled.

@shprink
Copy link

shprink commented Dec 23, 2017

MacOS here and I have the same problem. My time is sync as well

@dnld23
Copy link
Contributor Author

dnld23 commented Dec 23, 2017

Yes, my time is sync as well.

@kroitor
Copy link
Member

kroitor commented Dec 23, 2017

Does this work for you, guys:

// JavaScript
;(async () => {
    binance.verbose = true
    balance = await binance.fetchBalance ({'recvWindow': 10000000})
    console.log (balance)
}) ();
# Python
binance.verbose = True
balance = binance.fetch_balance({'recvWindow': 10000000})
print(balance)
// PHP
$binance->verbose = true;
$balance = $binance->fetch_balance ({'recvWindow': 10000000});
var_dump ($balance);

?

@paroxysm
Copy link

Yes this works. It's strange that you need such a huge window for their API. Something's strange going on there...

@kroitor
Copy link
Member

kroitor commented Dec 23, 2017

@paroxysm apparently, they have time synch issues within their system themselves. The ccxt code for Binance hasn't changed recently, so if they stopped working suddenly because of timing issues, it means their service is experiencing trouble.

I notified their team, they usually respond quickly. I guess, they are aware and are working on this already. If you don't mind, I would close this issue for now, because the reason is now mostly obvious.

I will update you here, when we have a followup on this from Binance. For now, we can't workaround this issue, if their own time-synch is unstable. Let me know if I can help with anything else.

@kroitor kroitor closed this as completed Dec 23, 2017
@kroitor
Copy link
Member

kroitor commented Dec 24, 2017

From Binance:

Igor Kroitor, [23.12.17 21:24]
Hi, again! We're receiving reports of multiple timestamp-related errors from users who have time 
synch enabled, and who didn't have this problem with the same code previously. Most of the time 
"timestamp more than 1000ms ahead of server time" and "timestamp outside of recvWindow"... the 
2nd one can probably be tackled by choosing a greater recvWindow, however, the first one is 
making us subtract a thousand from an otherwise-synchronized time... Is there a better way to solve 
these issues?

Ninj0r, [24.12.17 11:59]
Timestamp related issues on are on the users end. Synch your clocks (and keep them in sync) and 
you'll not have issues. Synching your clock is not a one time thing; clocks drift for a host of reasons 
and need to be repeatedly synced. This is why the default on ntpd is to sync clocks at least every 
1024 s (17mins 4 seconds). If the user can't prove they synced their clock within that timeframe, I'm 
not going to investigate it.

Ninj0r, [24.12.17 12:01]
I'll look into this.

Igor Kroitor, [24.12.17 12:07]
they mostly set default time synch in windows 10

Igor Kroitor, [24.12.17 12:08]
(always on)

Ninj0r, [24.12.17 12:08]
Yeah, which typically does something like a time synch once a day if even that.

Guys, from the above, I guess, it follows, that you need to change the frequency of your time synch updates (set smaller intervals for time polling). You can either do this by googling for it or with 3rd party software. Mac/Linux/FreeBSD/*nix users can change their ntpd settings to alter time synch frequency. Hope it helps.

@paroxysm
Copy link

ok

@dnld23
Copy link
Contributor Author

dnld23 commented Dec 26, 2017

This helped me. i set sync to each 12 minutes, it work s now

@dmeffert
Copy link

I added the following to my ntp.conf:
maxpoll 3
minpoll 3

But I still get the same recvWindow error. Is this the right way to increase the syncing frequency on OSX?

@kroitor
Copy link
Member

kroitor commented Feb 14, 2018

@kamov
Copy link

kamov commented Mar 14, 2018

I get the same error.

What can be a correct value for timestamp? I know the format, but not when..

example:

['recvWindow' => 10000000, 'timestamp' => time() + 10000000 ]

right?

@kroitor
Copy link
Member

kroitor commented Mar 15, 2018

What can be a correct value for timestamp?

You don't need to set it by hand at all. All you need is to create a new key and set up proper time synchronization on your machine to sync time once every 10 minutes.

['recvWindow' => 10000000, 'timestamp' => time() + 10000000 ]
right?

Nope. The best solution would be to set up time synch and not override their defaults at all.

// JavaScript
;(async () => {
    binance.verbose = true
    balance = await binance.fetchBalance ({'recvWindow': 10000000}) // no override for timestamp
    console.log (balance)
}) ();

An alternative way would be to enable adjustments for the time difference:

// JavaScript
let binance = new ccxt.binance ({
    'options': {
        'adjustForTimeDifference': true,
        'verbose': true, // if needed, not mandatory
        'recvWindow': 10000000, // not really needed
    },
})
;(async () => {
    balance = await binance.fetchBalance ()
    console.log (balance)
}) ();

Hope it helps.

@vvvladimir758
Copy link

vvvladimir758 commented Aug 14, 2020

working decision is to add parameter
recvWindow=60000 to the http request
(it's easy to edit lines with http request in API code, find them and add parametr recWindow to the request)
https://api.binance.com/api/v3/account?recvWindow=60000&timestamp=1513948454747&signature=xxxxxxxxxxxx

I modified returned responses in Exchange.php to get more information. This is what i get:

Error when loading details: binance GET https://api.binance.com/api/v3/account?timestamp=1513948454747&signature=xxxxxxxxxxxx
400 not accessible from this location at the moment
{"code":-1021,"msg":"Timestamp for this request is outside of the recvWindow."}

@seroberto
Copy link

Hello i buyed a website project from codecanyon but owner of project didnt reply me. I have just 1 problem about binance api. When i put my binance key and binance secret i got this error.

binance {"code":-1021,"msg":"Timestamp for this request is outside of the recvWindow."}

I cant see any balance on my website and I have a meeting 2 hours later about this website. I can give cpanel informations. I cant find where should i put your codes. Please someone help me this is very important meeting for me. Thank you

@kroitor
Copy link
Member

kroitor commented Nov 23, 2020

@seroberto hi! Unfortunately, we can't support the code that we don't write or maintain, especially, without seeing the code itself. CCXT works in that regard and it is free for the users.

@seroberto
Copy link

So just can you tell me which code can fix it and where should i put that code?

binance-server-time.js
php-binance-api.php
etc.

@kroitor
Copy link
Member

kroitor commented Nov 23, 2020

@seroberto we are not the authors of the code you mentioned, so we can't physically guess how to fix it. It's pretty much like asking any random guy how to fix any random code.

@seroberto
Copy link

const binance = new ccxt['binance'] ()
const recvWindow = binance.security.recvWindow
const aheadWindow = 1000


$opt = [
"symbol" => $symbol,
"side" => $side,
"type" => $type,
"quantity" => $quantity,
"recvWindow" => 60000,
];


'recvWindow' => 5 * 1000, // 5 sec, binance default

'timestamp' => $this->nonce (),
'recvWindow' => $this->options['recvWindow'],


Sorry for my questions but its really important for me. Should i fix anything one of the this parts?

@kroitor
Copy link
Member

kroitor commented Nov 23, 2020

@seroberto it's hard to help you without seeing the code, and we are not in charge of it, sorry.

Try changing this line:

const binance = new ccxt['binance'] ()

const binance = new ccxt['binance'] ({ enableRateLimit: true, options: { adjustForTimeDifference: true }})

If that does not help – we won't be able to fix it for you, unfortunately.

@fibo
Copy link

fibo commented Nov 23, 2020

@seroberto it can happen if you used the same key on anither timezone, I read it also in the ccxt docs. For example I have two api keys on binance, one is used on the servers and one is used locally during development, otherwise if you use only one key the nonce could miss its main requirement that is to be an increasing sequence. In particular this happens if the timezones are different.

So probably your code works but the issue is on the api key nonce, you probably should use one key for development and one for production.

good luck!

@seroberto
Copy link

@kroitor

// PHP
$binance->verbose = true;
$balance = $binance->fetch_balance ({'recvWindow': 10000000});
var_dump ($balance);

when i use this code i got this error for this line

$balance = $binance->fetch_balance ({'recvWindow': 10000000});

Syntax error, uxpected '{'

@seroberto
Copy link

@seroberto it can happen if you used the same key on anither timezone, I read it also in the ccxt docs. For example I have two api keys on binance, one is used on the servers and one is used locally during development, otherwise if you use only one key the nonce could miss its main requirement that is to be an increasing sequence. In particular this happens if the timezones are different.

So probably your code works but the issue is on the api key nonce, you probably should use one key for development and one for production.

good luck!

Hello. How did you get 2 api from binance? When i try to create i have only one choose for api on binance.

@kroitor
Copy link
Member

kroitor commented Nov 25, 2020

@seroberto Change it like so:

$balance = $binance->fetch_balance();

However, if you are not familiar with the programming languages, you might run into another problem right away, since using this lib requires programming skills.

@fibo
Copy link

fibo commented Nov 25, 2020

@seroberto it can happen if you used the same key on anither timezone, I read it also in the ccxt docs. For example I have two api keys on binance, one is used on the servers and one is used locally during development, otherwise if you use only one key the nonce could miss its main requirement that is to be an increasing sequence. In particular this happens if the timezones are different.
So probably your code works but the issue is on the api key nonce, you probably should use one key for development and one for production.
good luck!

Hello. How did you get 2 api from binance? When i try to create i have only one choose for api on binance.

Hi,

for example I have two keys now, to add another one I see something like this, I just need to add a label and click create

Screenshot 2020-11-25 at 11 54 25

@absorpheus
Copy link

I had the same problem on the Mac and turns out my firewall was blocking timed which is Apple's "Time Daemon".

I put it into the whitelist and the requests starting working again.

"Time Daemon" is a macOS system process that maintains system clock accuracy by synchronizing the clock with reference clocks via technologies like NTP.

@ilearnio
Copy link

ilearnio commented Jun 24, 2021

Force-syncing time helped (MacOS)

sudo sntp -sS pool.ntp.org

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests