pythondatetimecryptoapibinance-api-client

Binance order: Timestamp for this request was 1000ms ahead of the server's time


I am writing some Python code to create an order with the Binance API:

from binance.client import Client

client = Client(API_KEY, SECRET_KEY)

client.create_order(symbol='BTCUSDT',
                    recvWindow=59999, #The value can't be greater than 60K
                    side='BUY',
                    type='MARKET',
                    quantity = 0.004)

Unfortunately I get the following error message:

"BinanceAPIException: APIError(code=-1021): Timestamp for this request was 1000ms ahead of the server's time."

I already checked the difference (in miliseconds) between the Binance server time and my local time:

import time
import requests
import json
url = "https://api.binance.com/api/v1/time"
t = time.time()*1000
r = requests.get(url)

result = json.loads(r.content)

print(int(t)-result["serverTime"]) 

OUTPUT: 6997

It seems that the recvWindow of 60000 is still not sufficient (but it may not exceed 60K). I still get the same error. Does anybody know how I can solve this issue?

Many thanks in advance!


Solution

  • Probably the PC's time is out of sync.

    You can do it using Windows -> Setting-> Time & Language -> Date & Time -> 'Sync Now'.

    Screenshot:

    I share the picture as well