python-binance: APIError(code=-1021): Timestamp for this request was 1000ms ahead of the server's time.
Hello - first off great program. when I run the example code (from readme):
# place a test market buy order, to place an actual order use the create_order function
order = client.create_test_order(
symbol='BNBBTC',
side=Client.SIDE_BUY,
type=Client.ORDER_TYPE_MARKET,
quantity=100)
I receive the following error:
line 199, in _handle_response raise BinanceAPIException(response) binance.exceptions.BinanceAPIException: APIError(code=-1021): Timestamp for this request was 1000ms ahead of the server’s time.
I am able to successfully run the previous example:
# get market depth
depth = client.get_order_book(symbol='BNBBTC')
with no problems. How can I fix this issue? I know it has to do with my computer being different than the binance server time, but I thought that this was automatically handled by python-binance? Thanks in advance.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 25 (1 by maintainers)
Commits related to this issue
- integrated solution to issue #249 into request method — committed to NeillHerbst/python-binance by NeillHerbst 6 years ago
Sorry for posting on a closed issue, but, having awful internet here I am often burdened with getting rid of this issue in order to interact with Binance’s private API methods.
This, for posterity, is my solution. I create wrapper around the client object, with an extra function
synced
.I then instantiate it and call my private account functions with
synced
Hope this is of help.
from control panel > date and time > internet time change the server to >>>> time.nist.gov it worked with me
hi @ShervinDD , thank you for the suggestion. I was able to ‘sync’ with Nist.gov internet time, and the 1000 ms error went away. Here’s how I did it on Windows 10:
Date & Time -> Internet Time (tab) -> sync with nist.gov
it now says it will sync tomorrow at 7:31 A.M.
can you explain the solution? seems like its not work for me
In my case, I use Windows and from Settings -> Date & Time, with the switch “Set the time automatically” and “Set the time zone automatically” both on, them pressed the “Sync now” button, and that worked for me.
I’m not sure. If your system time is constantly out of sync with internet time, then there’s something wrong with your system. Try to fix that first.
hi @ShervinDD - this solution worked for me last night, however, when I tried to run the script today I received the same error (1000ms ahead of server time), and I synchronized it 10 minutes previously (automatically). when I re-synced it (manually) the program worked for a few minutes, but once again it is giving same error message. Is there anyway to fix this inside the program, such as setting request time = binance server time?
I’ve experienced this issue a lot (specially in docker environment). I solved the problem by updating the system time either manually or using ntp service
hello hello,
args[timestamp] should be in seconds or ms? I suspect ms?
So we should correct from: def synced(self, fn_name, **args): args[‘timestamp’] = int(time.time() - self.time_offset) return getattr(self.b, fn_name)(**args)
To… def synced(self, fn_name, **args): args[‘timestamp’] = int(time.time() *1000 - self.time_offset) return getattr(self.b, fn_name)(**args)
Right?
I’ve just had a similar problem [also using OSX]. I’m in Europe and my OSX SystemPreferences for Date & Time are already set to use sync via the internet using Apple’s Europe time servers. As an experiment, I changed the prefs to use Apple’s US time servers instead and ran the example code again and the error went away.
Interestingly, I’ve just reset the prefs back to use Apple’s Europe time servers again and the error has [so far!] not returned. Seems, on that basis, to be a problem with Apple’s time servers.
From my other comment thread, and thanks to nadir for code:
when I try to run win32api as suggested by nadir’s code, I receive following error:
line 19, in <module> win32api.SetSystemTime(tt[0],tt[1],0,tt[2],tt[3],tt[4],tt[5],0) pywintypes.error: (1314, 'SetSystemTime', 'A required privilege is not held by the client.')
I understand this has to do with permissions on my Windows machine.
When I run this code:
I receive the following output:
The first time struct is my local time, the second is the time formatted, which seems to be off by 3 hours and 1 second.