python-binance icon indicating copy to clipboard operation
python-binance copied to clipboard

APIError(code=-1021): Timestamp for this request was 1000ms ahead of the server's time.

Open Astrantia opened this issue 8 years ago • 13 comments

CLIENT.get_my_trades(symbol="BNBETH", recvWindow=100000)
CLIENT.get_my_trades(symbol="BNBETH")

Both give the same error. The strange thing is that I don't get this error with get_aggregate_trades function, only with get_my_trades.

I made sure my internet time is synced.

Astrantia avatar Dec 31 '17 22:12 Astrantia

I get the same error sometimes with get_account()

ksya avatar Jan 05 '18 15:01 ksya

I see the same error. Has anyone solved it?

santoshkalakonda avatar Jan 09 '18 06:01 santoshkalakonda

I found that my computer time is not synced with a proper NTP server therefore I ran into this issue too.

If you are using OSX, can try this tutorial: https://grok.lsu.edu/article.aspx?articleid=8102 and set the NTP server to the correct NTP server on http://www.pool.ntp.org/zone/us (US for example).

Otherwise, a dirty hack is to "minus" the calculate timestamp int(time.time() * 1000) - ) but that is not pretty nor accurate to do...

Unfortunately Binance is strict with the timestamp differences in their API constraints.

stevenvo avatar Jan 13 '18 20:01 stevenvo

This is my solution for timestamps issue. The code made equal windows time to binance server time.

from binance.client import Client client = Client('api_key', 'api_secret') import time import win32api gt = client.get_server_time() aa = str(gt) bb = aa.replace("{'serverTime': ","") aa = bb.replace("}","") gg=int(aa) ff=gg-10799260 uu=ff/1000 yy=int(uu) tt=time.localtime(yy) win32api.SetSystemTime(tt[0],tt[1],0,tt[2],tt[3],tt[4],tt[5],0)

"The integer 10799260 for adjusting time zone and fine tuning for miliseconds."

nadirdogan avatar Feb 28 '18 22:02 nadirdogan

The solution from nadirdogan works for me too. I improved/condensed his code a bit

from binance.client import Client client = Client('api_key', 'api_secret') import time import win32api gt = client.get_server_time() tt=time.gmtime(int((gt["serverTime"])/1000)) win32api.SetSystemTime(tt[0],tt[1],0,tt[2],tt[3],tt[4],tt[5],0)

MarcelBeining avatar Mar 21 '18 12:03 MarcelBeining

Hi @MarcelBeining, I'm glad to see you like my solution :)

nadirdogan avatar Mar 22 '18 03:03 nadirdogan

from control panel > date and time > internet time change the server to >>>> time.nist.gov it worked with me

MrRobotXX avatar May 31 '19 21:05 MrRobotXX

nbjkl;

from control panel > date and time > internet time change the server to >>>> time.nist.gov it worked with me

This works for me on win10, make sure you set control panel icons to small or you may have a hard time finding the internet time setting.

BisquitSoftware avatar Aug 08 '20 15:08 BisquitSoftware

from control panel > date and time > internet time change the server to >>>> time.nist.gov it worked with me You can go to date and time settings(Change the date and time). Then press sync now.
(default) time.windows.com is working for me.

eklekmek07 avatar Mar 17 '21 13:03 eklekmek07

Solution for me on:

APIError(code=-1021): Timestamp for this request was 1000ms ahead of the server's time.

After searching for days and trying so many things, this webpage blog helped me out to get my laptop in sync... thank god.

All the other usual solutions didn't work at all for but this, Its in german but i guess one can easily translate it in their language ;).

First link is part 1 and the second link is part 2.

https://www.borncity.com/blog/2019/02/25/windows-10-probleme-mit-der-zeitsynchronisation/ https://www.borncity.com/blog/2019/02/26/windows-10-probleme-mit-der-zeitsynchronisation-teil-2/

Eydrian90 avatar Aug 25 '21 07:08 Eydrian90

you need to synchronize the time on your PC over the Internet. import os os.system("w32tm /resync")

makcim646 avatar Sep 05 '21 06:09 makcim646

from control panel > date and time > internet time change the server to >>>> time.nist.gov it worked with me

it's worked for me, thanks 👌

tlhcelik avatar Nov 03 '21 21:11 tlhcelik

CLIENT.get_my_trades(symbol="BNBETH", recvWindow=100000)
CLIENT.get_my_trades(symbol="BNBETH")

Both give the same error. The strange thing is that I don't get this error with get_aggregate_trades function, only with get_my_trades.

I made sure my internet time is synced.

I also had the same issue on my windows PC, And I just adjusted the time to be automatic and its now working perfectly

Andre-Mwendwa avatar Apr 28 '22 05:04 Andre-Mwendwa