Could there be a technical issue on the server?

Hello,

I am sending requests using the Binance API from a Windows Server 2019 R2, but I am encountering the following error: “Timestamp for this request is outside of the recvWindow.” On Windows Server 2019, there is no “Sync Now” button, so I used the following command, but I keep getting errors. I haven’t found a different solution anywhere. Could there be a technical issue on the server?

Thank you for your help in advance.

w32tm /config /manualpeerlist:“time.windows.com,0x1” /syncfromflags:manual /reliable:YES /update
w32tm /config /update
w32tm /config /minpoll:4 /maxpoll:4
net stop w32time
net start w32time
w32tm /resync
w32tm /config /syncfromflags:manual /manualpeerlist:time.windows.com /update

The error you get when using the Binance API is “The timestamp for this request is outside of recvWindow.” This error indicates a problem with the timestamp.

Since there is no “Sync Now” button on Windows Server 2019, you need to manually set the time sync. However, this error may not be related to the Binance API, but to your server’s clock settings.

First, make sure that you have configured your server’s clock settings correctly. Then, check your server’s clock before sending your Binance API request. If your server’s clock is not correct, it may cause you to receive an API request timestamp error.

I hope this helps. Take care

check the below steps…

Update the Time Service Configuration… Open Command Prompt as an Administrator

w32tm /config /manualpeerlist:“time.windows.com,0x1” /syncfromflags:manual /reliable:YES /update
w32tm /config /update
w32tm /resync

Restart the Windows Time service

net stop w32time
net start w32time

Check Time Service Status

w32tm /query /status
w32tm /query /peers

Adjust API Timestamp Handling… Increase the recvWindow Parameter… Generate Timestamps Programmatically

import time
import hmac
import hashlib
import requests

api_key = ‘your_api_key’
api_secret = ‘your_secret_key’

Get server time

server_time_url = ‘https://api.binance.com/api/v3/time
server_time = requests.get(server_time_url).json()[‘serverTime’]

Calculate the offset

recv_window = 5000 # milliseconds
timestamp = int(time.time() * 1000) # local timestamp in milliseconds
offset = server_time - timestamp

Adjust local timestamp

params = {
‘symbol’: ‘BTCUSDT’,
‘side’: ‘BUY’,
‘type’: ‘LIMIT’,
‘timeInForce’: ‘GTC’,
‘quantity’: 0.1,
‘price’: ‘40000’,
‘recvWindow’: recv_window,
‘timestamp’: timestamp + offset
}

query_string = ‘&’.join([“{}={}”.format(k, v) for k, v in params.items()])
signature = hmac.new(api_secret.encode(‘utf-8’), query_string.encode(‘utf-8’), hashlib.sha256).hexdigest()
params[‘signature’] = signature

headers = {
‘X-MBX-APIKEY’: api_key
}

response = requests.post(‘https://api.binance.com/api/v3/order’, headers=headers, params=params)
print(response.text)