gazbert / bxbot

A simple Bitcoin trading bot written in Java.
MIT License
775 stars 275 forks source link

KrakenChangeAdapter.java calculates nonce in incorrect format #127

Closed roywasse closed 3 years ago

roywasse commented 3 years ago

The KrakenAPI doesn't allow the nonce is currently formatted: nonce = System.currentTimeMillis() \ 1000; Solution: nonce = System.currentTimeMillis();

gazbert commented 3 years ago

Thanks again for identifying another bug Roy.

If you fancy having a go at a fix and PR, you're more than welcome :-)

I'm pretty busy at the moment with other stuff, but I plan on releasing a maintenance/dependency update release of the bot in the Spring.

MarcDahlem commented 3 years ago

When the bot is running a long time, I still receive errors from Kraken saying that the nonce is invalid.

According to this kraken article https://support.kraken.com/hc/en-us/articles/360022636092-Sample-implementations , the following implementation is an working example implementation for the rest api:

https://github.com/CryptoFacilities/REST-v3-Java/blob/master/Java/cfRestAPIv3/src/com/cryptofacilities/REST/v3/CfApiMethods.java#L104

Maybe, bxbot should use this calculation as well?

roywasse commented 3 years ago

@MarcDahlem It seems that nonce can indeed cause issues in the current implementation in certain circumstances. But the root cause is not what you might think (IMO).

The comments in the existing code explain this and provide a solution, copy paste of this comments:

_Note: Sometimes requests can arrive out of order or NTP can cause your clock to rewind,

The current nonce is derived from the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC. See https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/System.html#currentTimeMillis()

This should ensure the nonce is always unique.

I therefore don't think it's necessary to update the calculation method of the nonce