sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
6.06k stars 2.21k forks source link

BinanceAPIException: Timestamp for this request is outside of the recvWindow. #1056

Open bmw7 opened 3 years ago

bmw7 commented 3 years ago

I run my codes and wrong message shows: binance.exceptions.BinanceAPIException: APIError(code=-1021): Timestamp for this request is outside of the recvWindow.

how to solve it on linux server and windows server? thanks very much!!

ddroguett commented 3 years ago

In windows I leave running a .bat as administrator to synchronize the time, then the code.

net stop w32time w32tm /unregister w32tm /register net start w32time w32tm /resync timeout /t 120 /nobreak

:inicio

cls @echo off

echo Esto es un bucle infinito %username% w32tm /config /manualpeerlist:"time.nist.gov time.windows.com time-nw.nist.gov time-a.nist.gov time-b.nist.gov time-a.timefreq.bldrdoc.gov time-b.timefreq.bldrdoc.gov time-c.timefreq.bldrdoc.gov utcnist.colorado.edu" /syncfromflags:manual /update

w32tm /resync /force

timeout /t 120 /nobreak

goto inicio

QuanticDisaster commented 3 years ago

You can use the following python script (with your environement run in administrator mode) :

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)
Karlheinzniebuhr commented 2 years ago

I've set up windows auto-sync for time. But still I'm randomly getting this error. Is there a definitive solution for this?

Exception has occurred: BinanceAPIException
APIError(code=-1021): Timestamp for this request is outside of the recvWindow.