I am requesting Bitstamp API in parrallel:
// Simplified version
var async = require('async');
var bitstamp = require('bitstamp');
async.parallel([
bitstamp.balance,
bitstamp.ticker
// ...
],
function() (err, result) {
// process results
});
Those two methods are sending signed requests to Bitstamp API including nonce.
Nonce is a regular integer number. It must be increasing with every request you make. Read more about it here. Example: if you set nonce to 1 in your first request, you must set it to at least 2 in your second request. You are not required to start with 1. A common practice is to use unix time for that parameter.
Underlying library generates nonce traditional way:
var nonce = new Date().getTime() + '' + new Date().getMilliseconds();
Problem
Because of asynchronous API calls, sometimes nonce generated it very same millisecond, while remote side wants them increasing.
Question
Keeping parallel requests, any idea to reliably generate sequential nonce?
My obvious try to:
this.nonce = new Date().getTime() + '' + new Date().getMilliseconds();
// ... on request
var nonce = this.nonce++;
But it doesn't solve the problem, same millisecond just increased by one, but still equal.