binance-trade-bot
binance-trade-bot copied to clipboard
APIError(code=-1021): Timestamp for this request was 1000ms ahead of the server's time.
This issue is caused by the machine the bot is running on being outside the recvWindow. Meaning the time on the bot computer is too far off from the binance server's time. This is an issue for any signed API request. The simple solution to solve this is when the bot starts (and perhaps every 4 hours of running) you make a request to /api/v3/time. you subtract the local time (time on computer bot is running on) from the value returned by this API call. This is the serverOffset. Whenever you make a signed request, you subtract this amount from the timestamp used to generate the sha256 hmac signature and the timestamp passed in the POST request.
Where is /api/v3/time in project, please?
I don't know if it is in the code. I would imagine it isnt.
https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md#timing-security and https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md#check-server-time
Thank you.
Hi @centrex, we are using an external library to handle communications with Binance, so we naturally don't sign our own requests (let alone craft POST headers). Do you have a fix for this within our code base? Perhaps we should use the library differently, in your opinion?
Unfortunately, I am not a python developer, so am I of no use when it comes to this codebase. But this needs to be fixed at the signature creation. I would look at the lib you're using and possibly fix it there and submit your PR to whomever is running that.
even if you are using someone else's binance lib, they should have this accounted in it. read their documentation. it may be as simple as just calling a method they provide to get the server time and then it's handled automatically.
I have been encountering this last night. It kept happening after a certain period of time. binance.exceptions.BinanceAPIException: APIError(code=-1021): Timestamp for this request is outside of the recvWindow
@centrex before trying to fix the error that is not there, could you please check your PC time against the value you receive from /api/v3/time
and see how different they are?
I bet the problem is on your side and once you set up the NTP sync for your PC time you'll never see this problem again.