Zenbot: ggetBalance error (4.04)

Created on 26 May 2017  Β·  67Comments  Β·  Source: DeviaVir/zenbot

ggetBalance error:
{ error: 'Nonce must be greater than 149582751298100. You provided 149582751297600.' }

Poloniex API is down! unable to call getBalance, retrying in 10s

While making its 1st purchase on poloniex.BCN-BTC

bug help wanted

Most helpful comment

@CreativeBacon
Hmm..
I suggest modify poloniex/exchange.js to
12 function publicClient (product_id) {
13 // if (!public_client) public_client = new
Poloniex(c.poloniex.key, c.poloniex.secret)
14 // return public_client
15 return authedClient()
16 }

I think the reason is exchange.js's two poloniex instance.
So, another instance have old nonce value.
It need to be thread-safe..

All 67 comments

Poloniex API is down!

Did you retry? Are you able to connect to Poloniex (or any internet site) from the box that is running your bot?

I wasn't running Zenbot in a docker container, and not sure the API being down is even related. The provided 'nonce' is incorrect

Having the same issue here.

Nonce must be greater than xxx

or the time out error bellow.

ggetBalance error:
{ error: 'Connection timed out. Please try again.' }
Poloniex API is down! unable to call getBalance, retrying in 10s

It seens like it does not work only some times. I put a console.log in the end of getBalance function and most of the time it passes. Could it be the number of request per second/minute Poloniex accepts?

Also getting this same error:

ggetBalance error:
{ error: 'Nonce must be greater than 1496361634359495. You provided 149636192715100.' }

If you look at the time stamps, they are off by a few orders of 10

Example:
1496361634359495 # Needed
149636192715100 # Provided by Zenbot

Having same issue.

Reference: https://github.com/timmolter/XChange/issues/1193

getBalance error:
{ error: 'Nonce must be greater than 149695216646000. You provided 149695215679400.' }

Poloniex API is down! unable to call getBalance, retrying in 10s

getBalance error:
{ error: 'Nonce must be greater than 149695225678600. You provided 149695224643200.' }

Poloniex API is down! unable to call getBalance, retrying in 10s

getBalance error:
{ error: 'Nonce must be greater than 149695230660000. You provided 149695229647500.' }

Poloniex API is down! unable to call getBalance, retrying in 10s

getBalance error:
{ error: 'Nonce must be greater than 149695237659600. You provided 149695236673600.' }

Poloniex API is down! unable to call getBalance, retrying in 10s

AnnihilaT , it didnt help. I have full default settings. Im trying work with polo in the docker zenbot.

---------------------------- STARTING LIVE TRADING ----------------------------
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705692249700.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705693291700.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705694629500.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705695656400.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705696684000.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705698020600.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705699047800.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705700975900.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705702339800.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705703368000.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705704670000.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705706565900.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705707592600.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705708647000.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705711675200.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705712704600.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705714236500.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705715261200.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705717289200.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705718321400.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705719642600.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705721204200.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705722234000.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705723293500.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705724822400.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 1496885422687535. You provided 149705725911000.' }

bug #help wanted

try new generated api key.
and avoid to use multiple application with same key.

https://github.com/codiwest/zenbot/blob/master/docs/FAQ.md#error-1

nao0811ta, thanks! All work fine!

ggetBalance error:
{ error: 'Nonce must be greater than 149724606975500. You provided 149724606975300.' }

Poloniex API is down! unable to call getBalance, retrying in 10s

To combat these errors I have followed steps other users have taken across the web but no success!

  • changed to a new set of API keys.
  • tested on a whole new installation on a different computer (while a friend who trades with me also has tried it on two of his).
  • run system clock updates to verify if its out of sync and to adjust.

None of the above have worked, it's providing the wrong times to Poloniex (and i assume as it's a nonce issue this is not exchange specific).

Any new suggestions, did anyone else find something different that worked here?
Thanks in advance :)

@CreativeBacon
Hmm..
I suggest modify poloniex/exchange.js to
12 function publicClient (product_id) {
13 // if (!public_client) public_client = new
Poloniex(c.poloniex.key, c.poloniex.secret)
14 // return public_client
15 return authedClient()
16 }

I think the reason is exchange.js's two poloniex instance.
So, another instance have old nonce value.
It need to be thread-safe..

Thank you for the speedy reply, super appreciated!

I have made the edits as specified and the following error is now presented:
`Alexs-MacBook-Pro:zenbot alex$ zenbot trade --period=1m poloniex.doge-btc
fetching pre-roll data:
/Users/alex/zenbot/node_modules/poloniex.js/lib/poloniex.js:30
this._getPrivateHeaders = function(parameters) {
^

TypeError: Cannot set property '_getPrivateHeaders' of undefined
at Poloniex (/Users/alex/zenbot/node_modules/poloniex.js/lib/poloniex.js:30:33)
at publicClient (/Users/alex/zenbot/extensions/exchanges/poloniex/exchange.js:14:9)
at Object.getTrades (/Users/alex/zenbot/extensions/exchanges/poloniex/exchange.js:57:26)
at getNext (/Users/alex/zenbot/commands/backfill.js:75:22)
at Object. (/Users/alex/zenbot/commands/backfill.js:64:11)
at Immediate. (/Users/alex/zenbot/node_modules/sosa/api.js:15:12)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate [as _immediateCallback] (timers.js:617:5)
Alexs-MacBook-Pro:zenbot alex$
`

update, the line wrap on your post made me think line 13 was now to be separated.
I have tried and it's running!

I'll update with progress, thanks again. :)

Period is so short and different line of source with mine.
It works for me with macd strategy and default parameters on up to date version.

screen shot 2017-06-12 at 15 36 23

as shown in the above screenshot, zenbot shows the attempted buy but then thinks it's succeeded.
The bid is not withdrawn and stays there, I have a pending bid at the currency it tried to buy and zenbot has stopped tracking this buy order due to the nonce error.

@CreativeBacon
It's only temporary modification.
Due it's not my logic, Someone Let me know better and safe methology..
Or different poloniex library we need

My logs tracked well.
Which strategy are you using??

How about retrying modified logic with your new key.

Still a lot of nonce errors, debugging at present!

How does the bot calculate the nonce?

@CreativeBacon The nonce generation is not done by the bot. It is done in the API functions from exchange API which is pulled in when you do an "npm install"

@CreativeBacon
I modified like below.
I'm using two API key lol..

 12   function publicClient (product_id) {
 13     if (!public_client) public_client = new Poloniex(c.poloniex.key, c.poloniex.secret)
 14     return public_client
 15   }
 16 
 17   function authedClient () {
 18     if (!authed_client) {
 19       if (!c.poloniex || !c.poloniex.key || c.poloniex.key === 'YOUR-API-KEY') {
 20         throw new Error('please configure your Poloniex credentials in conf.js')
 21       }
 22       authed_client = new Poloniex(c.poloniex2.key, c.poloniex2.secret)
 23     }
 24     return authed_client
 25   }

found

getBalance and getTrades are send sometimes at the same time.
I'm using lock flag . but need to handle by mutex

getBalance
finish getBalance
getTrades
finish getTrades
getBalance
locked from getTrades
finish getBalance
2017-06-12 14:18:51  0.13908836 ETH-BTC   -1.1%    21737      +++  +00.0019      74           2.24 ETH  0.00280 BTC   +12.3%  -14.4%

interesting, I have also added a second set of API keys and will test once they unban me in two minutes!

Nice suggestion.. πŸ‘

@CreativeBacon
Apparently, two API keys was not good idea.
use lock flag and when locked, retry.
Tentatively
ETH-BTC to the Moon now.

@nao0811ta
Removed double API. πŸ‘
By 'lock flag' you mean to add --lock to the run command?

This would be easier messaging back and forth on a skype chat, feel free to add me - my Skype ID is freshlondon.biz

screen shot 2017-06-12 at 23 05 15

not testing with large amounts of course, but if the above image helps..? πŸ˜ƒ

like that

 52     getTrades: function (opts, cb) {
 53 //console.error('getTrades')
 54       var func_args = [].slice.call(arguments)
 55 if (lock) {
 56 //  console.log('locked from getTrades')
 57   return retry('getTrades', func_args)
 58 }
 59 //console.log('getTrades')
 60 lock = true
 61       var client = publicClient()
 62       var args = {
 63         currencyPair: joinProduct(opts.product_id)
 64       }
 65       if (opts.from) {
 66         args.start = opts.from
 67       }
 68       if (opts.to) {
 69         args.end = opts.to
 70       }
 71       if (args.start && !args.end) {
 72         // add 2 hours
 73         args.end = args.start + 7200
 74       }
 75       else if (args.end && !args.start) {
 76         // subtract 2 hours
 77         args.start = args.end - 7200
 78       }
 79 
 80       client._public('returnTradeHistory', args, function (err, body) {
 81 lock = false

screen shot 2017-06-12 at 23 35 50

i hope i did the above correctly, although i am returned:
screen shot 2017-06-12 at 23 36 46

note how i tried running with both --lock and without in the command, just in case.
I wish this wasn't JS, one of the coding languages i totally suck at! πŸ˜’

Thanks a lot for your help so far @nao0811ta - you're a superstar πŸ‘

screen shot 2017-06-13 at 01 26 13

(1 day trading period, keen to get this functioning!)

A trading friend who dabbles with JS has his working a little more productively as far as the error messages go, although they still exist. Apparently it's as if polo is lagging by 20ish seconds, do you have this experience?

Nope. I don't have..
It looks like need to ntcupdate.

had a search online but not finding anything that helps, may i ask what is ntcupdate?

@CreativeBacon
I'm sorry ntcupdate is not proper info.
I recommend c.poll_trades to increase. if you do that, timeout and another api error to be decreased.
I set it to

93 // ms to poll new trades at
94 c.poll_trades = 50000

yup, still the issue of the errors just its asking poloniex less so shows less. Not as effectove for trading, i am doing some trades with my settings but due to the nonce issues it's greatly affected productivity.

Fingers crossed a patch comes out soon!

@CreativeBacon
I hope so.
But I haven't been being happen nonce error now anymore.
I am controling geBalance and getTrades by lock flag.

WOW, incredible! fancy sharing your files? πŸ˜‰

could use wetransfer and email: [email protected] ..without your API keys of course!

I'll then send it back with some super awesome tweaked settings (after testing what works) as a thank you πŸ˜ƒ

Hey folks is there a fix for this in the works? It seems like you found a workaround? This error is hindering my trading as well since it sometimes fails to sell or buy with this error and it misses the ideal signal.

ditto, i've moved to another exchange for now but poloniex is the only one of interest!
strange thing i've noticed is the error doesnt show on any other exchanges, could it be an issue with poloniex themselves?

I'm seeing issue on Bitfinex as well

Anyone want to share a complete file?
:)
get the same error over an dover on polo

When I trade in the same time in the different crypto then I get same error. (In one of the docker console.)
pack is:
edit

Edited /zenbot/extensions/exchanges/poloniex/exchange.js:

var Poloniex = require('poloniex.js')
, path = require('path')
, moment = require('moment')
, n = require('numbro')
, colors = require('colors')

module.exports = function container (get, set, clear) {
var c = get('conf')

var public_client, authed_client

function publicClient (product_id) {
if (!public_client) public_client = new Poloniex(c.poloniex.key,
c.poloniex.secret)
return public_client
}

function authedClient () {
if (!authed_client) {
if (!c.poloniex || !c.poloniex.key || c.poloniex.key ===
'YOUR-API-KEY') {
throw new Error('please configure your Poloniex credentials in
conf.js')
}
authed_client = new Poloniex(c.poloniex.key, c.poloniex.secret)
}
return authed_client
}

function joinProduct (product_id) {
return product_id.split('-')[1] + '_' + product_id.split('-')[0]
}

function retry (method, args) {
if (method !== 'getTrades') {
console.error(('\nPoloniex API is down! unable to call ' + method +
', retrying in 10s').red)
}
setTimeout(function () {
exchange[method].apply(exchange, args)
}, 10000)
}

var orders = {}

var exchange = {
name: 'poloniex',
historyScan: 'backward',
makerFee: 0.15,
takerFee: 0.25,

getProducts: function () {
  return require('./products.json')
},

getTrades: function (opts, cb) {
//console.error('getTrades')
var func_args = [].slice.call(arguments)
var lock = false
if (lock) {
// console.log('locked from getTrades')
return retry('getTrades', func_args)
}
//console.log('getTrades')
lock = true
var client = publicClient()
var args = {
currencyPair: joinProduct(opts.product_id)
}
if (opts.from) {
args.start = opts.from
}
if (opts.to) {
args.end = opts.to
}
if (args.start && !args.end) {
// add 2 hours
args.end = args.start + 7200
}
else if (args.end && !args.start) {
// subtract 2 hours
args.start = args.end - 7200
}

  client._public('returnTradeHistory', args, function (err, body) {

lock = false
if (err) return cb(err)
if (typeof body === 'string') {
return retry('getTrades', func_args)
}
if (!body.map) {
console.error('\getTrades odd result:')
console.error(body)
return retry('getTrades', func_args)
}
var trades = body.map(function (trade) {
return {
trade_id: trade.tradeID,
time: moment.utc(trade.date).valueOf(),
size: Number(trade.amount),
price: Number(trade.rate),
side: trade.type
}
})
cb(null, trades)
})
},

getBalance: function (opts, cb) {
  var args = [].slice.call(arguments)
  var client = authedClient()
  client.returnCompleteBalances(function (err, body) {
    if (err) return cb(err)
    var balance = {asset: 0, currency: 0}
    if (typeof body === 'string') {
      return retry('getBalance', args)
    }
    if (body.error) {
      console.error('\ggetBalance error:')
      console.error(body)
      return retry('getBalance', args)
    }
    if (body[opts.currency]) {
      balance.currency =

n(body[opts.currency].available).add(body[opts.currency].onOrders).format('0.00000000')
balance.currency_hold = body[opts.currency].onOrders
}
if (body[opts.asset]) {
balance.asset =
n(body[opts.asset].available).add(body[opts.asset].onOrders).format('0.00000000')
balance.asset_hold = body[opts.asset].onOrders
}
cb(null, balance)
})
},

getQuote: function (opts, cb) {
  var args = [].slice.call(arguments)
  var client = publicClient()
  var product_id = joinProduct(opts.product_id)
  client.getTicker(function (err, body) {
    if (err) return cb(err)
    if (typeof body === 'string') {
      return retry('getQuote', args)
    }
    if (body.error) {
      console.error('\ggetQuote error:')
      console.error(body)
      return retry('getQuote', args)
    }
    var quote = body[product_id]
    if (!quote) return cb(new Error('no quote for ' + product_id))
    if (quote.isFrozen == '1') console.error('\nwarning: product ' +

product_id + ' is frozen')
cb(null, {
bid: quote.highestBid,
ask: quote.lowestAsk,
})
})
},

cancelOrder: function (opts, cb) {
  var args = [].slice.call(arguments)
  var client = authedClient()
  client._private('cancelOrder', {orderNumber: opts.order_id}, function

(err, result) {
if (typeof result === 'string') {
return retry('cancelOrder', args)
}
if (!err && !result.success) {
// sometimes the order gets cancelled on the server side for some
reason and we get this. ignore that case...
if (result.error !== 'Invalid order number, or you are not the
person who placed the order.') {
err = new Error('unable to cancel order')
err.body = result
}
}
cb(err)
})
},

trade: function (type, opts, cb) {
  var args = [].slice.call(arguments)
  var client = authedClient()
  var params = {
    currencyPair: joinProduct(opts.product_id),
    rate: opts.price,
    amount: opts.size,
    postOnly: opts.post_only === false ? '0' : '1'
  }
  client._private(type, params, function (err, result) {
    if (typeof result === 'string') {
      return retry('trade', args)
    }
    var order = {
      id: result ? result.orderNumber : null,
      status: 'open',
      price: opts.price,
      size: opts.size,
      post_only: !!opts.post_only,
      created_at: new Date().getTime(),
      filled_size: '0'
    }
    if (result && result.error === 'Unable to place post-only order at

this price.') {
order.status = 'rejected'
order.reject_reason = 'post only'
return cb(null, order)
}
else if (result && result.error && result.error.match(/^Not
enough/)) {
order.status = 'rejected'
order.reject_reason = 'balance'
return cb(null, order)
}
if (!err && result.error) {
err = new Error('unable to ' + type)
err.body = result
}
if (err) return cb(err)
orders['~' + result.orderNumber] = order
cb(null, order)
})
},

buy: function (opts, cb) {
  exchange.trade('buy', opts, cb)
},

sell: function (opts, cb) {
  exchange.trade('sell', opts, cb)
},

getOrder: function (opts, cb) {
  var args = [].slice.call(arguments)
  var order = orders['~' + opts.order_id]
  if (!order) return cb(new Error('order not found in cache'))
  var client = authedClient()
  var params = {
    currencyPair: joinProduct(opts.product_id)
  }
  client._private('returnOpenOrders', params, function (err, body) {
    if (err) return cb(err)
    if (typeof body === 'string' || !body) {
      return retry('getOrder', args)
    }
    var active = false
    if (!body.forEach) {
      console.error('\nreturnOpenOrders odd result:')
      console.error(body)
    }
    else {
      body.forEach(function (api_order) {
        if (api_order.orderNumber == opts.order_id) active = true
      })
    }
    if (!active) {
      order.status = 'done'
      order.done_at = new Date().getTime()
      return cb(null, order)
    }
    client.returnOrderTrades(opts.order_id, function (err, body) {
      if (typeof body === 'string' || !body) {
        return retry('getOrder', args)
      }
      if (err || body.error || !body.forEach) return cb(null, order)
      order.filled_size = '0'
      body.forEach(function (trade) {
        order.filled_size =

n(order.filled_size).add(trade.amount).format('0.00000000')
})
if (n(order.filled_size).value() == n(order.size).value()) {
order.status = 'done'
order.done_at = new Date().getTime()
}
cb(null, order)
})
})
},

// return the property used for range querying.
getCursor: function (trade) {
  return Math.floor((trade.time || trade) / 1000)
}

}
return exchange
}

2017-06-15 13:35 GMT+03:00 crack00r notifications@github.com:

Anyone want to share a complete file?
:)
get the same error over an dover on polo

β€”
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/carlos8f/zenbot/issues/193#issuecomment-308694226,
or mute the thread
https://github.com/notifications/unsubscribe-auth/Ab1B_D2xahtW6fdsRrDqhDX5hmnGC07_ks5sEQjogaJpZM4NoBjr
.

With this, you dont have errors? @denisa08

@crack00r I dont have errors when i trade with one crypto. But if i going trading with multiple crypto then i get it error in one of crypto trade console.

I gice it a try, thx

@denisa08 can you may upload on nopaste?
here are to many format errors

http://dropmefiles.com/QbAyU
@crack00r

Click to the "Π‘ΠΊΠ°Ρ‡Π°Ρ‚ΡŒ всС". Im from Russia, sorry:)

thx! I try it now

again :(
and more erros

`ggetBalance error:
{ error: 'Nonce must be greater than 149754973633900. You provided 149754972917800.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
ggetBalance error:
{ error: 'Nonce must be greater than 149754973633900. You provided 149754972919100.' }

Poloniex API is down! unable to call getBalance, retrying in 10s

{ Error: unable to sell
at /root/zenbot/extensions/exchanges/poloniex/exchange.js:206:17
at Request._callback (/root/zenbot/node_modules/poloniex.js/lib/poloniex.js:79:7)
at Request.self.callback (/root/zenbot/node_modules/poloniex.js/node_modules/request/request.js:122:22)
at emitTwo (events.js:125:13)
at Request.emit (events.js:213:7)
at Request. (/root/zenbot/node_modules/poloniex.js/node_modules/request/request.js:888:14)
at emitOne (events.js:120:20)
at Request.emit (events.js:210:7)
at IncomingMessage. (/root/zenbot/node_modules/poloniex.js/node_modules/request/request.js:839:12)
at emitNone (events.js:110:20)
at IncomingMessage.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1045:12)
at _combinedTickCallback (internal/process/next_tick.js:102:11)
at process._tickCallback (internal/process/next_tick.js:161:9)
body: { error: 'Nonce must be greater than 149754975230800. You provided 149754975229100.' },
desc: 'could not execute sell: error placing order' }

ggetBalance error:
{ error: 'Nonce must be greater than 149754975863100. You provided 149754975106300.' }

Poloniex API is down! unable to call getBalance, retrying in 10s
`

@crack00r docker-compose build, docker-compose up and after all works fine

i use ubuntu

@crack00r i see it errors too:( Our patch don't work.

someone fix it here
https://github.com/rferro/plnx/issues/2
but i cant implement it

sorry too late
it's mine it works

var Poloniex = require('poloniex.js')
  , path = require('path')
  , moment = require('moment')
  , n = require('numbro')
  , colors = require('colors')

module.exports = function container (get, set, clear) {
  var c = get('conf')

  var public_client, public_client2, authed_client

  function publicClient (product_id) {
    if (!public_client) public_client = new Poloniex(c.poloniex.key, c.poloniex.secret)
    return public_client
  }

  function authedClient () {
    if (!authed_client) {
      if (!c.poloniex || !c.poloniex.key || c.poloniex.key === 'YOUR-API-KEY') {
        throw new Error('please configure your Poloniex credentials in conf.js')
      }
      authed_client = new Poloniex(c.poloniex.key, c.poloniex.secret)
    }
    return authed_client
  }

  function joinProduct (product_id) {
    return product_id.split('-')[1] + '_' + product_id.split('-')[0]
  }

  function retry (method, args) {
    if (method !== 'getTrades') {
      console.error(('\nPoloniex API is down! unable to call ' + method + ', retrying in 10s').red)
    }
    setTimeout(function () {
      exchange[method].apply(exchange, args)
    }, 10000)
  }

  var orders = {}
  var lock = false
  var exchange = {
    name: 'poloniex',
    historyScan: 'backward',
    makerFee: 0.15,
    takerFee: 0.25,

    getProducts: function () {
      return require('./products.json')
    },

    getTrades: function (opts, cb) {
//console.error('getTrades')
      var func_args = [].slice.call(arguments)
if (lock) {
//  console.log('locked from getTrades')
  return retry('getTrades', func_args)
}
//console.log('getTrades')
lock = true
      var client = publicClient()
      var args = {
        currencyPair: joinProduct(opts.product_id)
      }
      if (opts.from) {
        args.start = opts.from
      }
      if (opts.to) {
        args.end = opts.to
      }
      if (args.start && !args.end) {
        // add 2 hours
        args.end = args.start + 7200
      }
      else if (args.end && !args.start) {
        // subtract 2 hours
        args.start = args.end - 7200
      }

      client._public('returnTradeHistory', args, function (err, body) {
lock = false
//console.log('finish getTrades')
        if (err) return cb(err)
//console.error('getTrades returnTradeHistory')
        if (typeof body === 'string') {
          return retry('getTrades', func_args)
        }
        if (!body.map) {
          console.error('\getTrades odd result:')
          console.error(body)
          return retry('getTrades', func_args)
        }
        var trades = body.map(function (trade) {
          return {
            trade_id: trade.tradeID,
            time: moment.utc(trade.date).valueOf(),
            size: Number(trade.amount),
            price: Number(trade.rate),
            side: trade.type
          }
        })
        cb(null, trades)
      })
    },

    getBalance: function (opts, cb) {
      var args = [].slice.call(arguments)
      var client = authedClient()
if(lock){
// console.error('locked from getBalance')
 return retry('getBalance', args)
}
lock = true
//console.log('getBalance')
      client.returnCompleteBalances(function (err, body) {
lock = false
//console.log('finish getBalance')
        if (err) return cb(err)
//console.error('getBalance returnCompleteBalances')
        var balance = {asset: 0, currency: 0}
        if (typeof body === 'string') {
          return retry('getBalance', args)
        }
        if (body.error) {
          console.error('\ggetBalance error:')
          console.error(body)
          return retry('getBalance', args)
        }
        if (body[opts.currency]) {
          balance.currency = n(body[opts.currency].available).add(body[opts.currency].onOrders).format('0.00000000')
          balance.currency_hold = body[opts.currency].onOrders
        }
        if (body[opts.asset]) {
          balance.asset = n(body[opts.asset].available).add(body[opts.asset].onOrders).format('0.00000000')
          balance.asset_hold = body[opts.asset].onOrders
        }
        cb(null, balance)
      })
    },

    getQuote: function (opts, cb) {
//console.error('getQuote')
      var args = [].slice.call(arguments)
      var client = publicClient()
      var product_id = joinProduct(opts.product_id)
      client.getTicker(function (err, body) {
        if (err) return cb(err)
//console.error('getQuote getTicker')
        if (typeof body === 'string') {
          return retry('getQuote', args)
        }
        if (body.error) {
          console.error('\ggetQuote error:')
          console.error(body)
          return retry('getQuote', args)
        }
        var quote = body[product_id]
        if (!quote) return cb(new Error('no quote for ' + product_id))
        if (quote.isFrozen == '1') console.error('\nwarning: product ' + product_id + ' is frozen')
        cb(null, {
          bid: quote.highestBid,
          ask: quote.lowestAsk,
        })
      })
    },

    cancelOrder: function (opts, cb) {
//console.error('cancelOrder')
      var args = [].slice.call(arguments)
      var client = authedClient()
      client._private('cancelOrder', {orderNumber: opts.order_id}, function (err, result) {
//console.error('cancelOrder2')
        if (typeof result === 'string') {
          return retry('cancelOrder', args)
        }
        if (!err && !result.success) {
          // sometimes the order gets cancelled on the server side for some reason and we get this. ignore that case...
          if (result.error !== 'Invalid order number, or you are not the person who placed the order.') {
            err = new Error('unable to cancel order')
            err.body = result
          }
        }
        cb(err)
      })
    },

    trade: function (type, opts, cb) {
//console.error('trade')
      var args = [].slice.call(arguments)
if(lock)
{
 return retry('trade', args)
}
lock = true
      var client = authedClient()
      var params = {
        currencyPair: joinProduct(opts.product_id),
        rate: opts.price,
        amount: opts.size,
        postOnly: opts.post_only === false ? '0' : '1'
      }
      client._private(type, params, function (err, result) {
//console.error('trade2')
lock = false
        if (typeof result === 'string') {
          return retry('trade', args)
        }
        var order = {
          id: result ? result.orderNumber : null,
          status: 'open',
          price: opts.price,
          size: opts.size,
          post_only: !!opts.post_only,
          created_at: new Date().getTime(),
          filled_size: '0'
        }
        if (result && result.error === 'Unable to place post-only order at this price.') {
          order.status = 'rejected'
          order.reject_reason = 'post only'
          return cb(null, order)
        }
        else if (result && result.error && result.error.match(/^Not enough/)) {
          order.status = 'rejected'
          order.reject_reason = 'balance'
          return cb(null, order)
        }
        if (!err && result.error) {
          err = new Error('unable to ' + type)
          err.body = result
        }
        if (err) return cb(err)
        orders['~' + result.orderNumber] = order
        cb(null, order)
      })
    },

    buy: function (opts, cb) {
      exchange.trade('buy', opts, cb)
    },

    sell: function (opts, cb) {
      exchange.trade('sell', opts, cb)
    },

    getOrder: function (opts, cb) {
//console.error('getOrder')
      var args = [].slice.call(arguments)
      var order = orders['~' + opts.order_id]
      if (!order) return cb(new Error('order not found in cache'))
      var client = authedClient()
      var params = {
        currencyPair: joinProduct(opts.product_id)
      }
      client._private('returnOpenOrders', params, function (err, body) {
        if (err) return cb(err)
//console.error('returnOpenOrders')
        if (typeof body === 'string' || !body) {
          return retry('getOrder', args)
        }
        var active = false
        if (!body.forEach) {
          console.error('\nreturnOpenOrders odd result:')
          console.error(body)
        }
        else {
          body.forEach(function (api_order) {
            if (api_order.orderNumber == opts.order_id) active = true
          })
        }
        if (!active) {
          order.status = 'done'
          order.done_at = new Date().getTime()
          return cb(null, order)
        }
        client.returnOrderTrades(opts.order_id, function (err, body) {
//console.error('returnOrderTrades')
          if (typeof body === 'string' || !body) {
            return retry('getOrder', args)
          }
          if (err || body.error || !body.forEach) return cb(null, order)
          order.filled_size = '0'
          body.forEach(function (trade) {
            order.filled_size = n(order.filled_size).add(trade.amount).format('0.00000000')
          })
          if (n(order.filled_size).value() == n(order.size).value()) {
            order.status = 'done'
            order.done_at = new Date().getTime()
          }
          cb(null, order)
        })
      })
    },

    // return the property used for range querying.
    getCursor: function (trade) {
      return Math.floor((trade.time || trade) / 1000)
    }
  }
  return exchange
}

no rly bug, only api down

Poloniex API is down! unable to call getBalance, retrying in 10s

Poloniex API is down! unable to call getBalance, retrying in 10s

and again
returnOpenOrders odd result:
{ error: 'Nonce must be greater than 149756185095800. You provided 149756185068600.' }

Api down is not bug.
Maybe the reason is your request is frequent.
My code is for avoiding noce error from requesting multiple api at the same time.

My code is not occured since few days before.

and it didnt cancel the orders
http://prntscr.com/fk9slg

so right now, but is useless

Are you play with the date of you pc? I do a few days ago and make the bot crazy with nonce error! The solution was make a new poloniex key.

works, i set my server time 2min. above the real time...
no Nonce must be greater than anymore
but still Poloniex API is down! unable to call getBalance, retrying in 10s
is there any way to add 2 ore more apikeys?

http://prntscr.com/fke1ch

@crack00r
It is really no help in advancing your computers time. the only factor the exchange care about is that the nonce has a higher value than the previous one.
The most important factor is to have a stable clock. You can achieve that by using NTP, but that might not help if you have an unstable computer.

Other reasons:

  • the nonce generator that resides in the exchange API may have bug or bad implementation
  • due to the asyncronous nature of a node program, an old nonce can slip through
  • a bug in the exchange software

due to the asyncronous nature of a node program, an old nonce can slip through

I made some test... that is the problem... the program make 2 even 3 calls to poloniex whitout wait for the first to be resolved.

Fixed by adding --lock and installing NTP on centos and set to sync every minute with --period=1m
But this does not fix my nonce issue!!!!!

THE EDIT in exchange.js:
````
var orders = {}
var lock = false
var exchange = {
name: 'poloniex',
historyScan: 'backward',
makerFee: 0.15,
takerFee: 0.25,

getProducts: function () {
  return require('./products.json')
},

getTrades: function (opts, cb) {

//console.error('getTrades')
var func_args = [].slice.call(arguments)
if (lock) {
// console.log('locked from getTrades')
return retry('getTrades', func_args)
}
//console.log('getTrades')
lock = true
var client = publicClient()
var args = {
currencyPair: joinProduct(opts.product_id)
}
if (opts.from) {
args.start = opts.from
}
if (opts.to) {
args.end = opts.to
}
if (args.start && !args.end) {
// add 2 hours
args.end = args.start + 7200
}
else if (args.end && !args.start) {
// subtract 2 hours
args.start = args.end - 7200
}

  client._public('returnTradeHistory', args, function (err, body) {

lock = false

You also need to do this instead of running docker, use separate configs for each instance for different coins and API keys. I run 5.
````
./zenbot.sh trade --conf=/zenbot0/conf0.js --period=1m --buy_pct=100 --sell_pct=100 --lock
./zenbot.sh trade --conf=/zenbot0/conf1.js --period=1m --buy_pct=100 --sell_pct=100 --lock
./zenbot.sh trade --conf=/zenbot0/conf2.js --period=1m --buy_pct=100 --sell_pct=100 --lock
./zenbot.sh trade --conf=/zenbot0/conf3.js --period=1m --buy_pct=100 --sell_pct=100 --lock
./zenbot.sh trade --conf=/zenbot0/conf4.js --period=1m --buy_pct=100 --sell_pct=100 --lock

But this is still giving the getbalance nonce error? Adjusting the time correctly using ntp seems to help.
Also setting period to 3m seems to help even more.

I guess poloniex has some type of IP-based flood protection.

I have no idea.. Still getting the nonce issue. But atleast now it's only the nonce issue.

UPDATE:
I read somewhere that nonce is a generated with time, and for some reason poloniex takes 30 seconds to s send market data so I set my clock 30 seconds ahead about and did get some better results.

Had following problem with kraken:

Kraken API warning - unable to call trade (Error: Kraken API returned error: API:Invalid nonce), retrying in 0.15s

Increased the nonce window at Kraken API key settings to 360. No problems right now. I think the request takes to long to process and run into this timeout.

With Kraken - check status page https://status.kraken.com/ πŸ‘Ž

Update:
It's no as often as before but still there. Very often if connection to Kraken had a problem
Kraken API warning - unable to call getTrades (Connection between Cloudflare CDN and api.kraken.com failed), retrying in 0.15s
Kraken API warning - unable to call trade (Error: Kraken API returned error: API:Invalid nonce), retrying in 0.15s

Looks like a Kraken issue, closing this side of the equation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mrzobot picture mrzobot  Β·  3Comments

linuxu678 picture linuxu678  Β·  4Comments

gleblanc1783 picture gleblanc1783  Β·  3Comments

0DTE picture 0DTE  Β·  3Comments

KryptoNova picture KryptoNova  Β·  3Comments