question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Desync, Timestamp for this request was 1000ms ahead of the server's time

See original GitHub issue

Java version : C:\Program Files\Java\jdk1.8.0_152\bin>java.exe -version java version “1.8.0_152” Java™ SE Runtime Environment (build 1.8.0_152-b16) Java HotSpot™ 64-Bit Server VM (build 25.152-b16, mixed mode)

Quite a common error, here is the snippet of code I am using to compare the time between my computer and binance API :

package laby.java;

import com.binance.api.client.BinanceApiClientFactory;
import com.binance.api.client.BinanceApiRestClient;

public class Main {

    private static final String APIKEY = "key";
    private static final String APISECRET = "secret";

    public static void main(String[] args) {

        BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(APIKEY, APISECRET);
        BinanceApiRestClient client = factory.newRestClient();


        while (true) {
            // Checking time between
            Long clientTime = java.lang.System.currentTimeMillis();
            Long serverTimerTime = client.getServerTime();
            System.out.println("Times : client[" + clientTime + "] server[" + serverTimerTime + "] diff[" + (serverTimerTime - clientTime) + "]");
        }
    }

}

Results:

Times : client[1514132675503] server[1514132675624] diff[121]
Times : client[1514132677246] server[1514132676946] diff[-300]
Times : client[1514132678541] server[1514132677226] diff[-1315]
Times : client[1514132678820] server[1514132677505] diff[-1315]
Times : client[1514132679098] server[1514132677788] diff[-1310]
Times : client[1514132679420] server[1514132678111] diff[-1309]
Times : client[1514132679729] server[1514132678414] diff[-1315]
Times : client[1514132680007] server[1514132678698] diff[-1309]
Times : client[1514132680293] server[1514132678983] diff[-1310]
Times : client[1514132680579] server[1514132679265] diff[-1314]
Times : client[1514132680858] server[1514132679544] diff[-1314]
Times : client[1514132681137] server[1514132679823] diff[-1314]
Times : client[1514132681417] server[1514132680107] diff[-1310]

Process finished with exit code 1

Registry setting is set to update time each ten minutes, it doesn’t change anything:

image

For your information, I updated the clock time before each attempt : image

I am loosing around 1.2 seconds somewhere, and I don’t know where

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
SungMinHongcommented, Mar 26, 2018

I just solve this problem using getServerTime() and gap time for example

before

@Override
public Account getAccount() {
    return getAccount(BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis());
}

after

  @Override
  public Account getAccount() {
	  long start = System.currentTimeMillis();
	  long serverTime = this.getServerTime();
	  long end = System.currentTimeMillis();
	  long gap = end - start; 
	  return getAccount(BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, serverTime + gap);
  }

But It is need 1 weight more When call the method. If weight is important I will make static time variable and just call only one getServerTime(). I hope this way help you. : )

1reaction
JamesBarnes88commented, Dec 26, 2017

I put a PR up for this #11. Its been working for a couple days so I think its safe. Not sure if its the best implementation though. Check it out if you want.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Binance order: Timestamp for this request was 1000ms ahead ...
Binance server time is behind your server time, because Binance servers do not sync often with ntp servers. Workaround: binance.
Read more >
Binance error: Timestamp for this request was 1000ms ahead ...
For windows, i opened the time and click de sync the clock with windows server. When i did it, it worked! Before you...
Read more >
get_account error "Timestamp for this request was 1000ms ...
Hey I m trying to do this (on python): a = client.get_acount() print(a) and return me this error "Timestamp for this request was...
Read more >
timestamp for this request was 1000ms ahead of the server's ...
In this video we are fix the time server error when using python binance library.# time server #Binance API #python binanceit is just...
Read more >
How to resolve Binance's Timestamp ahead of Server's time ...
"Binance error: Timestamp for this request is 1000ms ahead of the server's time". At first, I thought I made a mistake when typing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found