Skip to content
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

Invalid nonce error #18

Closed
jasonmellone opened this issue Jun 18, 2014 · 13 comments
Closed

Invalid nonce error #18

jasonmellone opened this issue Jun 18, 2014 · 13 comments

Comments

@jasonmellone
Copy link

Hello,

I posted the question on stackoverflow, but I am getting the following error when using a valid user/key/secret.

http://stackoverflow.com/questions/24285109/python-bitstamp-api-invalid-nonce-error

Unsure what I can do to solve this or what I have done wrong. Please let me know if this is a bug or not as I would love to get it solved. Happy to contribute in modifying the code, but unsure why this is occurring.

This login was working up until it sporadically stopped working yesterday evening.

@kmadac
Copy link
Owner

kmadac commented Jun 18, 2014

Hello,

I just tried to test it, and account_balance() method works fine in my test script.
Do you use account_balance() request in one thread only once per script run, or is it called in a loop many times per second or even in multiple threads?

Kamil

@jasonmellone
Copy link
Author

Hello

Once per script. The script is run once an hour. 

I have a separate php site that reloads my balance and current level but that is once every few hours (manual). 

The website uses the php lib on git. No errors there. 

Sent from Mailbox

On Wed, Jun 18, 2014 at 4:26 PM, Kamil Madac notifications@github.com
wrote:

Hello,
I just tried to test it, and account_balance() method works fine in my test script.
Do you use account_balance() request in one thread only once per script run, or is it called in a loop many times per second or even in multiple threads?

Kamil

Reply to this email directly or view it on GitHub:
#18 (comment)

@jasonmellone
Copy link
Author

Also I tried modifying the nonce get to just take the unix time not the max of nonce and unix time and I get the same error regardless. —
Sent from Mailbox

On Wed, Jun 18, 2014 at 4:26 PM, Kamil Madac notifications@github.com
wrote:

Hello,
I just tried to test it, and account_balance() method works fine in my test script.
Do you use account_balance() request in one thread only once per script run, or is it called in a loop many times per second or even in multiple threads?

Kamil

Reply to this email directly or view it on GitHub:
#18 (comment)

@kmadac
Copy link
Owner

kmadac commented Jun 18, 2014

Is time on your server set correctly?
Can you try generate new Bitstamp API key and secret and try your script with new credentials?

@jasonmellone
Copy link
Author

It has the same error on a windows 8 pc and an up to date mac. I can easily generate a new key/secret. Will check back in once I do that. Thanks. —
Sent from Mailbox

On Wed, Jun 18, 2014 at 5:03 PM, Kamil Madac notifications@github.com
wrote:

Is time on your server set correctly?

Can you try generate new Bitstamp API key and secret and try your script with new credentials?

Reply to this email directly or view it on GitHub:
#18 (comment)

@SmileyChris
Copy link
Contributor

My guess is that you've used an nonce greater than the ones being generated
by this script (maybe the phone nonce is bigger?) You can only ever use an
nonce larger than the max of those used in the past.
On Jun 19, 2014 9:21 AM, "jasonmellone" notifications@github.com wrote:

It has the same error on a windows 8 pc and an up to date mac. I can
easily generate a new key/secret. Will check back in once I do that.
Thanks. —
Sent from Mailbox

On Wed, Jun 18, 2014 at 5:03 PM, Kamil Madac notifications@github.com
wrote:

Is time on your server set correctly?
Can you try generate new Bitstamp API key and secret and try your script

with new credentials?

Reply to this email directly or view it on GitHub:

#18 (comment)


Reply to this email directly or view it on GitHub
#18 (comment)
.

@jasonmellone
Copy link
Author

Hm. Interesting but unsure. Maybe there is a discrepancy between the php nonce and the up nonce. 


Sent from Mailbox

On Wed, Jun 18, 2014 at 6:09 PM, Chris Beaven notifications@github.com
wrote:

My guess is that you've used an nonce greater than the ones being generated
by this script (maybe the phone nonce is bigger?) You can only ever use an
nonce larger than the max of those used in the past.
On Jun 19, 2014 9:21 AM, "jasonmellone" notifications@github.com wrote:

It has the same error on a windows 8 pc and an up to date mac. I can
easily generate a new key/secret. Will check back in once I do that.
Thanks. —
Sent from Mailbox

On Wed, Jun 18, 2014 at 5:03 PM, Kamil Madac notifications@github.com
wrote:

Is time on your server set correctly?
Can you try generate new Bitstamp API key and secret and try your script

with new credentials?

Reply to this email directly or view it on GitHub:

#18 (comment)


Reply to this email directly or view it on GitHub
#18 (comment)
.


Reply to this email directly or view it on GitHub:
#18 (comment)

@SmileyChris
Copy link
Contributor

Er phone -> php (thx autocomplete...)

@jasonmellone
Copy link
Author

I knew what you meant no worries. I'll get a new key and give it a whirl. I will also try to recreate the error to be sure. —
Sent from Mailbox

On Wed, Jun 18, 2014 at 6:12 PM, Chris Beaven notifications@github.com
wrote:

Er phone -> php (thx autocomplete...)

Reply to this email directly or view it on GitHub:
#18 (comment)

@jasonmellone
Copy link
Author

Getting a new api key fixed the problem here. I will give the php a whirl
later tonight to see if the issue is recreated.

Jason Mellone
631.219.5351
jason.mellone@gmail.com

On Wed, Jun 18, 2014 at 6:13 PM, Jason Mellone jason.mellone@gmail.com
wrote:

I knew what you meant no worries. I'll get a new key and give it a whirl.
I will also try to recreate the error to be sure.

Sent from Mailbox https://www.dropbox.com/mailbox

On Wed, Jun 18, 2014 at 6:12 PM, Chris Beaven notifications@github.com
wrote:

Er phone -> php (thx autocomplete...)


Reply to this email directly or view it on GitHub
#18 (comment)
.

@jasonmellone
Copy link
Author

Hello

I discovered and solved the issue for my own uses.

In the php api the following code is establishing the nonce:
// generate a nonce as microtime, with as-string handling to avoid problems
with 32bits systems
$mt = explode(' ', microtime());
$req['nonce'] = $mt[1] . substr($mt[0], 2, 6);
$req['key'] = $key;
$req['signature'] = $this->get_signature($req['nonce']);

with this, I have a comparison to the python code:

def get_nonce(self):

"""

Get a unique nonce for the bitstamp API.

This integer must always be increasing, so use the current unix time.

Every time this variable is requested, it automatically increments to

allow for more than one API request per second.

This isn't a thread-safe function however, so you should only rely on a

single thread if you have a high level of concurrent API requests in

your application.

"""

nonce = getattr(self, '_nonce', 0)

if nonce:

nonce += 1

If the unix time is greater though, use that instead (helps low

concurrency multi-threaded apps always call with the largest nonce).

self._nonce = max(int(time.time()), nonce)

return self._nonce

Which you are familiar with I am sure.

The error was indeed being created by the php/python piece of my cross
language use.

A VERY VERY easy solution (I implemented this locally, but I will let you
discuss if you want to apply it globally) is to chagnge:

self._nonce = max(int(time.time()), nonce)

to

self._nonce = max(int(time.time()*1000000), nonce)

As your nonce is created as:

1403366728.072785 and then cast to int

and the php nonce is created as:

1403366859731819

Do you think it would be best to update the python api to be in line with
the php for cross functional purposes?

This is my first real interaction with a github project, so I am happy to
to be wrong here.

Jason

Jason Mellone
631.219.5351
jason.mellone@gmail.com

On Thu, Jun 19, 2014 at 7:47 AM, Jason Mellone jason.mellone@gmail.com
wrote:

Getting a new api key fixed the problem here. I will give the php a whirl
later tonight to see if the issue is recreated.

Jason Mellone
631.219.5351
jason.mellone@gmail.com

On Wed, Jun 18, 2014 at 6:13 PM, Jason Mellone jason.mellone@gmail.com
wrote:

I knew what you meant no worries. I'll get a new key and give it a whirl.
I will also try to recreate the error to be sure.

Sent from Mailbox https://www.dropbox.com/mailbox

On Wed, Jun 18, 2014 at 6:12 PM, Chris Beaven notifications@github.com
wrote:

Er phone -> php (thx autocomplete...)


Reply to this email directly or view it on GitHub
#18 (comment)
.

@kmadac
Copy link
Owner

kmadac commented Jun 27, 2014

Hi Jason,

thank you for investigation and sorry for delayed response. I think that it is not bad idea to generate nonce with microsecond precision. Could you please create pull request (https://help.github.com/articles/using-pull-requests) with your code change? It is easy and you will be become contributor of the Bitstamp client;)

@kmadac
Copy link
Owner

kmadac commented Sep 8, 2017

Closed because no reaction for a long time.

@kmadac kmadac closed this as completed Sep 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants