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!
-250
but you have positive value – Bozcaadaif (timestamp < (serverTime + 1000) && (serverTime - timestamp) <= recvWindow) {
which can rewrite as(serverTime - recvWindow) <= timestamp < (serverTime + 1000)
and maybe yourtimestamp
satisfies(serverTime - recvWindow) <= timestamp
but not satisfiestimestamp < (serverTime + 1000)
- and this can be in your errorTimestamp for this request was 1000ms ahead of the server's time
– Bozcaadatimestamp < (serverTime + 1000)
astimestamp - serverTime < 1000
which is te same as yourint(t)-result["serverTime"]
but you get6997
and this is not satisfies6997 < 1000
As for me you have to correct clock/time in your system. OR maybe you need faster connection. – Bozcaada