cryptoeax / arbbot

Arbitrator, a bitcoin/altcoin arbitrage trading bot
https://gitter.im/cryptoeax-arbbot/Lobby
GNU General Public License v3.0
198 stars 78 forks source link

Bleutrade sets a max nonce #107

Closed claytondukes closed 6 years ago

claytondukes commented 6 years ago

I noted in Bleutrade's API docs that they say:

nonce is a number that should never be repeated and always greater than the previous number. Is used to increase your safety, is optional, but if it is first used, it becomes mandatory. Max = 2147483647.

But in bot/Exchange.php, the nonce is set using microtime( true ).

I'm not sure if this is the cause of the Bleutrade issues, but thought it might be worth investigating.

I also notice that other api's/scripts, etc. just use time() so it wasn't clear to me why arbbot is using microseconds.

 protected function nonce() {

    static $previousNonce = array( );
    $id = $this->getID();
    if ( !isset( $previousNonce[ $id ] ) ) {
      $previousNonce[ $id ] = 0;
    }

    // Try the current time, if we're getting called too fast, step up one by one.
    $nonce = floor( microtime( true ) * 1000000);
    if ( $nonce <= $previousNonce[ $id ] ) {
      $nonce = $previousNonce[ $id ] + 1;
    }

    $previousNonce[ $id ] = $nonce;
    return $nonce;

  }
cryptoeax commented 6 years ago

We use microseconds in order to get a higher resolution. We can probably mask off anything above the higher 32-bits. But this is a disruptive change, since it will mean all nonce values will suddenly decrease, which effectively means people will need to regenerate their API keys. So there should be a good reason why we would change our behavior here...

cryptoeax commented 6 years ago

I don't think there is anything that we should do here. Closing the issue.