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

Nonce is too small #25

Open
360disrupt opened this issue Aug 1, 2016 · 1 comment
Open

Nonce is too small #25

360disrupt opened this issue Aug 1, 2016 · 1 comment

Comments

@360disrupt
Copy link

main code

interval = setInterval( ()->
  startTime = moment()
  exchanges = trader.getExchanges()
  async.parallel
    # quotes: (next)->
    #   getQuotes exchanges, (err, quotes)->
    #     if err?
    #       clearInterval(interval)
    #       return next err
    #     timeDelta = moment().diff(startTime, 'seconds')
    #     if timeDelta > 10
    #       clearInterval(interval)
    #       return next "Time Delay #{timeDelta} is to big, trading may not be safe!"
    #     else if timeDelta > 2
    #       console.warn "Time Delay is #{timeDelta} seconds! Please check Latency!"
    #     else if timeDelta > 0
    #       console.info "Time Delay is #{timeDelta} seconds"
    #     return next null, quotes

    balances: (next)->
      getBalances exchanges, (err, balances)->
        if err?
          clearInterval(interval)
          return next err

        return next null

    (err, results)->
      return callback err if err?
      inspect results

, bitcoinTradingConfig.gapSec * 1000)

Bitfinex class

inspect = require('eyespect').inspector({maxLength: null})
chalk = require('chalk')

Bitcoin = require('./bitcoin.class.js')
BitfinexApi = require('bitfinex')
restSenderService = require('../rest-sender.service.js')

class Bitfinex extends Bitcoin
  constructor: (options)->
    super(options)
    if options.apiKey? && options.apiSecret?
      @.bitfinexApi = new BitfinexApi(options.apiKey, options.apiSecret)
    return


  filterQuote: (response)->
    filter = {'bid':'bid', 'ask':'ask'} #1st name on exchange, 2nd label here
    filteredResponse = {}
    for key, value of filter
      filteredResponse[value] = response[key] if response[key]?
    return filteredResponse

  getQuote: (callback)->
    self = @
    @.bitfinexApi.ticker 'btcusd', (err, response)->
      return callback err if err?
      filteredQuote = self.filterQuote response
      return callback null, filteredQuote

  getAvailableBalance: (callback)->
    self = @
    return 0 if [email protected]?
    @.bitfinexApi.wallet_balances  (err, response)->
      return callback err if err?
      inspect response
      return callback null, response

#/////////////////////////////////////////////////////////////////////////////////////////////////////
module.exports = Bitfinex

I only have one process running. The Api is currently queried every 3s and there are (at the moment) no other queries in async.parallel.

I get on the first API call of wallet_balances the err Nonce is too small

I even get this, when I move all out of the class and the interval function, e.g.

  BitfinexApi = require('bitfinex')
  bitfinexApi = new BitfinexApi(bitcoinTradingConfig['bitfinex'].apiKey, bitcoinTradingConfig['bitfinex'].apiSecret)
  console.log "TEST>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
  bitfinexApi.wallet_balances  (err, response)->
    console.log err, response

Node v: 6.2.1

@360disrupt
Copy link
Author

Ok I realized that is related to the old version on npm. Would be great if a new release would be made. Otherwise the Nonce will make the API requests fail.
Math.ceil((new Date()).getTime() / 1000); becomes -> this.nonce = new Date().getTime();

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

1 participant