Pages:
Author

Topic: BTC-E Nonce Generation - page 2. (Read 7000 times)

hero member
Activity: 616
Merit: 522
May 18, 2013, 12:38:37 PM
#4
$mt = explode(' ', microtime());
$req['nonce'] = substr($mt[1],-4).substr($mt[0], 2, 6);

Just make sure that they don't require ever-increasing nonce (but they probably do), because your method will create numbers starting back from 0 after couple of hours. What you have now is a number which increases for 10000 seconds but then starts back from 0. You also don't ensure that you won't generate a nonce that has already been used in the past, as it's possible you'll get a colliding number one day. This is a very dirty hack what you have now.
newbie
Activity: 33
Merit: 0
May 18, 2013, 11:47:30 AM
#3
I am testing code for the BTC-E trading platform, however, it seems like it can only process one API request per second, if I do more it gives an invalid nonce parameter error back.

It can only process one API request per unique nonce and your nonce is number of seconds since the Unix epoch, so you are changing your nonce only once per second. You are skipping the microseconds part of microtime() return. Please read: http://php.net/manual/en/function.microtime.php, or the quickest shortcut would be $req['nonce'] = (int) 10000*microtime(true);

I already tried generating a more complex nonce, but it didn't work.

Apparently it needs a nonce of exactly 10 numbers (this is mentioned nowhere however), which I now generate partly from the seconds and from the microseconds part:

$mt = explode(' ', microtime());
$req['nonce'] = substr($mt[1],-4).substr($mt[0], 2, 6);

Issue solved now, thanks for the reply.
hero member
Activity: 616
Merit: 522
May 18, 2013, 11:27:41 AM
#2
I am testing code for the BTC-E trading platform, however, it seems like it can only process one API request per second, if I do more it gives an invalid nonce parameter error back.

It can only process one API request per unique nonce and your nonce is number of seconds since the Unix epoch, so you are changing your nonce only once per second. You are skipping the microseconds part of microtime() return. Please read: http://php.net/manual/en/function.microtime.php, or the quickest shortcut would be $req['nonce'] = (int) 10000*microtime(true);
newbie
Activity: 33
Merit: 0
May 18, 2013, 11:16:47 AM
#1
Hi,

I am testing code for the BTC-E trading platform, however, it seems like it can only process one API request per second, if I do more it gives an invalid nonce parameter error back.

I use PHP, this is the code to generate the nonce:

        $mt = explode(' ', microtime());
        $req['nonce'] = $mt[1];

If I try a more complex nonce, like:

    $req['nonce'] = $mt[1].substr($mt[0], 2, 6);

I also get an invalid nonce parameter error back.

Anyone ran into the same problem? How to solve it?

Thanks, Dirk
Pages:
Jump to: