Time Difference with Binance Server

Viewed 518

I'm trying to build a very simple automated tool in Python to allow me to post orders on Binance. It's really to get the hang of Python while having a "goal" in mind, a finish line.

I'm using this great library and of one the basic things I want to do is find out if there is a time difference between my computer time and Binance server's.

I'm using, to this end, the get_server_time method. Both times are returned in EPOCH which is ok but there is a small time difference.

It's not a problem for me to pass orders or to keep on with my journey but I'd like to understand the reason behind it ; I'm curious to be thorough and understanding all of the ins and outs of this.

Here is my code:

# Get Server Time
def get_server_time():
    ts = client.get_server_time()['serverTime']
    server_time = datetime.utcfromtimestamp(ts / 1000).strftime('%Y-%m-%d %H:%M:%S')
    return server_time

print(round(time.time()*1000))
print(client.get_server_time()['serverTime'])

# Check if computer time is the same as server time
if time.time()*1000 != client.get_server_time()['serverTime']:
    print("There is a problem in time sync.")
else:
    print("Your computer time matches server time.")

And it returns a small time difference, as seen here:

1639147119502
1639147120114
There is a problem in time sync.

I've tried syncing my computer clock through various ways (the most famous you see on Google ; fiddling with the Time Service of Windows10).

Is there any reasons behind this you all could think of ?

Thanks a lot in advance ;)

1 Answers

Is there any reasons behind this you all could think of ?

Difference between

1639147119502
1639147120114

is 612 that is 0.612 second, this might be simple time required by message to go through network, consider what happens when you run your code

  1. you are checking current time in your computer clock
  2. you ask binance server: what is your time, but before it reach it it must travel via net which takes time
  3. it does check time and send response

If you want to investigate further you might look for binance server you are asking geographical location versus your geographical location, try ping command to check response time or traceroute to deduce number of hops.

Related