Question about duplicate nonce
See original GitHub issueA question. I continue to try and make a custom nonce, because even when ratelimit is enabled, it regularly produces a duplicate nonce error.
If the Yobit exchange default ratelimit nonce is defined in milliseconds by default as we discussed in #2153, then I do not understand how this could happen in any case - even programmer error.
In any case, I tried to fix it by using this;
// A: custom nonce value
class MyOKCoinUSD extends \ccxt\okcoinusd {
public function __construct ($options = array ()) {
parent::__construct (array_merge (array ('i' => 1), $options));
}
public function nonce () {
return $this->i++;
}
}
As well as by this;
// B: milliseconds nonce
class MyZaif extends \ccxt\zaif {
public function __construct ($options = array ()) {
parent::__construct (array_merge (array ('i' => 1), $options));
}
public function nonce () {
return $this->milliseconds ();
}
}
As per https://github.com/ccxt/ccxt/wiki/Manual (Overriding The Nonce)
Btw, the same page it says for the ratelimit option that “This parameter is not used for now (reserved for future).” (incorrect?)
In any case, both methods above fail. If I use the second, it gives this;
Assert! ccxt\ExchangeError: yobit unknown "error" value => {"success":0,"error":"invalid nonce (max 2147483646), please generate new key"} in /home/roel/ccxt/php/liqui.php:736
If I use the first, I am not sure how to set the custom nonce (I am reading/storing it from/to a file), but if I use the code as-is, it produces;
Assert! ccxt\ExchangeError: yobit unknown "error" value => {"success":0,"error":"invalid nonce (has already been used)"} in /home/roel/ccxt/php/liqui.php:736
Even if I set ‘i’=>1 to a much larger random number which never have been used.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (4 by maintainers)
For anyone wanting to read/store a nonce from a nonce.dat file (which can be created and pre-set with a number using a standard text editor);
[…then init exchange…]
Code provided as-is without any warranties.
@forexhill you don’t really need a custom procedure with a new key. You can just remove the overrided procedure and use the default nonce as is with a new key…
Now, as for your questions:
I would agree with @mkutny , whenever you find yourself in such a situation, the best way is to make sure you fully understand the nature of the bug, before trying to fix anything.
Right, and this is something that is the most important aspect to investigate, all other measures are applied prematurely.
Redefining a nonce won’t solve a reappearing nonce conflict in general case, unfortunately, so, the fix isn’t fixing it really.
Outdated somewhat… Needs to be constantly updated, I’m doing whatever I can to keep it up, really.
Random nonces won’t work in general. The nonce not only has to be unique, but also has to be greater than the previous nonce, so a random number will sooner or later hit a nonce smaller than the previously used value, and Yobit will confuse you with their non-intuitive error messaging
{"success":0,"error":"invalid nonce (has already been used)"}
, which in fact means an absolutely different reason: “you’re sending a nonce that is smaller than the biggest nonce I’ve seen so far with this api key” (this is what Yobit is trying to tell you, really).Anyway, there’s a Troubleshooting procedure and if you follow if from top to bottom literally one point after the other, you will inevitably try a new key among the first troubleshooting steps. That is something you should have tried in the first place. And this is what, most likely, fixed the issue for you. However, if you run into the same issue again, I’d recommend to stop right there, do some preparation and debugging and in case of a difficulty with it, report the code and verbose output, as usually, we will be happy to help.
Thx, closing it for now, if you don’t mind. Feel free to reopen it if needed or just ask questions if any.