Skip to content

Timestamp for this request is outside of the recvWindow

Tiago edited this page Apr 8, 2024 · 11 revisions

Different exchanges give different descriptions for this error, some examples:

Binance: "Timestamp for this request is outside of the recvWindow" or "Timestamp for this request was 1000ms ahead of the server's time"

Bybit:
ret_code: 10002,
ret_msg: 'invalid request, please check your timestamp and recv_window param'

Bybit V5:
10002 The request time exceeds the time window range.
--


<br class="Apple-interchange-newline">

Explanation

The auth/signature mechanism works using a time window.

You’re telling the exchange that you signed the request at this timestamp. The server will reject the request if it arrives later than “timestamp + recvWindow”, to prevent replay attacks, on the assumption the request took longer than expected to reach the exchange.

The recv window allows you to tell the API server how much of a delay you're willing to accept. Since this mechanism relies on your machine's clock to get a timestamp, it's important that your machine clock is in sync.

If your machine time is out of sync or your network is suffering from slow requests, you may need more time than the default recv window, but usually it’s better to treat the root cause (sync machine time via something like ntp or fix your internet) than to just keep bumping the recv window to a higher value.

Actions

Check your system time. Ideally use a time service like NTP to set your system clock automatically. It cannot be wrong by more than a few seconds or any authenticated requests will fail.

If you’re more than 5 seconds on the wrong time, it’ll break authenticated requests due to the default recv window. You can change the recv window in most connectors, but the real solution is to fix your time first.

I also made this if you want to experiment with your system time vs latency vs server time on Bybit spot APIs: https://github.com/tiagosiebler/awesome-crypto-examples/blob/master/src/exchanges/bybit/time/log-latency-spot.ts

I'd suggest to try these, with each further step only a last resort if the previous step doesn't fix it:

  • Ensure your time is manually in sync (using whatever time update/sync service your machine has - e.g. on macOS you can set time and date automatically).
  • Ensure your machine is updating/syncing time automatically. Check that your network connection is stable.
  • If it happens sometimes but not often, or if the above solutions still don't help, you can try increasing the recv window param in the config from the default 5000 ms (5 seconds). However, this should be a last resort since 5 seconds is already quite a gap.
  • If it STILL happens, you can try to "enable_time_sync: true" but that should be a last resort as I've seen this cause more problems than it solves, eventually... I used to have it enabled by default in all my connectors, but I've seen that one slow request can offset it too far and start causing timestamp errors. That's why I'd prefer to keep it disabled.

Unix

Use something like NTP to sync your system clock automatically:

Mac

  • Open your system preferences.
  • Navigate to "Date & Time" (usually under "General").
  • Enable "Set time and date automatically".

Windows

  • Open the "Run command" window (Windows + R) and go to "timedate.cpl" to access the "Date & Time" settings.
  • Navigate to the "Internet Time" tab & click "Change settings".
  • Enable "Synchronize with an Internet time server". Optional, use the atomic clock from PTB as the server: "ptbtime1.ptb.de"

More detailed tutorial: https://winbuzzer.com/2020/03/13/windows-10-how-to-sync-time-with-an-atomic-clock-world-time-server-xcxwbt/