-
Notifications
You must be signed in to change notification settings - Fork 498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strategy to avoid "INVALID_TIMESTAMP" #80
Comments
Isn't the |
@balthazar Good point! Haven't checked this one. 🙈 I was already investigating on how to determine the local clock drift by using Sntp. My idea was to detect the offset in milliseconds to then add it to all locally created timestamps: const Sntp = require('sntp');
Sntp.time({
host: 'pool.ntp.org',
port: 123,
resolveReference: true,
timeout: 1000
})
.then((time) => {
const offset = parseInt(time.t, 10);
const timestamp = Date.now() + offset;
console.log(`Offset: ${offset}ms`);
console.log(`Adjusted timestamp: ${timestamp}`);
}); I will test the |
Using sntp might worsen the compatibility of the library in the browser, which I think is still not ideal as someone using webpack previously reported. I think the param is the way to go, but maybe it would be better to have it at the client level rather than a per-call basis |
Yeah, we shouldn't break Browser compatibility, so I debugged further... The The My idea was to inject the timestamp offset from the calling application... Demo Code: const Binance = require('binance-api-node').default
const Sntp = require('sntp');
const client = Binance({
apiKey: process.env.BINANCE_API_KEY,
apiSecret: process.env.BINANCE_API_SECRET,
});
Sntp.time({
host: 'pool.ntp.org',
port: 123,
resolveReference: true,
timeout: 1000
})
.then((time) => {
const offset = parseInt(time.t, 10);
return client.prices({ timeOffset: offset });
}); This way we wouldn't need a dependency to Do you maybe have another idea of how we can overcome the timestamp issue? Because the environment, where I am running "binance-api-node", has an offset of -2200ms and I cannot change the clock on that machine. :-/ |
I just had another idea... Would it be possible to send the time offset already with the Code: const Binance = require('binance-api-node').default
const client = Binance({
apiKey: process.env.BINANCE_API_KEY,
apiSecret: process.env.BINANCE_API_SECRET,
clockDrift: -2200 // 2200ms in the past
}); Edit: Because the time drift can change over time, it should also be possible to change |
Instead of a constant like this, I think having a getter |
Ok, I am fine with that as long as it is possible to update the clock drift during runtime. Can you please make a code proposal so that I can work on implementing that? |
Following the docs, it looked to me that The implementation would require to pass a getter in the client, that would be called instead of this |
@balthazar What was the reason that We could also make |
I tried to specify a timestamp for public endpoints at some points and hit some weird issue, which was probably something else and thought that providing a timestamp was not available for public ones. If this is untrue, we can add it to public endpoints too. I'm not really confident with having this confusing API, I would prefer having another parameter for the custom |
Hey @balthazar, it has been some time and I would really like to be able to pass a function to "binance-api-node" which is used to calculate the "timestamp" which is sent to Binance. What would be the easiest to achieve this? Can you give me some pseudo code to point me in the correct direction? |
You would pass a |
Any news about this issue?
|
Any solution for this issue? |
Closing thanks to #162 |
Binance is pretty strict about the timestamp which is sent to the server on every request.
To avoid the "Request used an outdated timestamp" error, we could sync our own time with an online atomic clock service to determine our clock drift (which can then be used to adjust the timestamps).
The text was updated successfully, but these errors were encountered: