Generate oAuth nonce for parallel requests

后端 未结 3 1153
生来不讨喜
生来不讨喜 2021-01-21 09:12

I am requesting Bitstamp API in parrallel:

// Simplified version

var async = require(\'async\');
var bitstamp = require(\'bitstamp\');

async.parallel([
    bit         


        
3条回答
  •  心在旅途
    2021-01-21 10:10

    I had exactly the same problem, so I took askmike's code and modified it slightly.

    var nonce = new (function() {
    
        this.generate = function() {
    
            var now = Date.now();
    
            this.counter = (now === this.last? this.counter + 1 : 0);
            this.last    = now;
    
            // add padding to nonce
            var padding = 
                this.counter < 10 ? '000' : 
                    this.counter < 100 ? '00' :
                        this.counter < 1000 ?  '0' : '';
    
            return now+padding+this.counter;
        };
    })();
    

    use it like this

    nonce.generate();
    

    check out my jsfiddle with example

提交回复
热议问题