Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Catching more recoverable connection errors in Kraken #841

Merged
merged 13 commits into from
Dec 12, 2017
20 changes: 12 additions & 8 deletions extensions/exchanges/kraken/exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function container(get, set, clear) {

var public_client, authed_client
// var recoverableErrors = new RegExp(/(ESOCKETTIMEDOUT|ETIMEDOUT|ECONNRESET|ECONNREFUSED|ENOTFOUND|API:Invalid nonce|API:Rate limit exceeded|between Cloudflare and the origin web server)/)
var recoverableErrors = new RegExp(/(ESOCKETTIMEDOUT|ETIMEDOUT|ECONNRESET|ECONNREFUSED|ENOTFOUND|API:Invalid nonce|between Cloudflare and the origin web server|The web server reported a gateway time\-out|The web server reported a bad gateway|525\: SSL handshake failed|Service\:Unavailable)/)
var recoverableErrors = new RegExp(/(ESOCKETTIMEDOUT|ETIMEDOUT|ECONNRESET|ECONNREFUSED|ENOTFOUND|API:Invalid nonce|between Cloudflare and the origin web server|The web server reported a gateway time\-out|The web server reported a bad gateway|525\: SSL handshake failed|Service\:Unavailable|api.kraken.com \| 522\:)/)
var silencedRecoverableErrors = new RegExp(/(ESOCKETTIMEDOUT|ETIMEDOUT)/)

function publicClient() {
Expand Down Expand Up @@ -75,6 +75,10 @@ module.exports = function container(get, set, clear) {
else if (error.message.match(/Service\:Unavailable/)) {
errorMsg = 'Service Unavailable'
}
else if (error.message.match(/api.kraken.com \| 522\:/)) {
errorMsg = 'Generic 522 Server error'
}

else {
errorMsg = error
}
Expand Down Expand Up @@ -221,7 +225,7 @@ module.exports = function container(get, set, clear) {
return cb(data.error.join(','))
}
if (so.debug) {
console.log("cancelOrder")
console.log('\nFunction: cancelOrder')
console.log(data)
}
cb(error)
Expand All @@ -245,7 +249,7 @@ module.exports = function container(get, set, clear) {
params.price = opts.price
}
if (so.debug) {
console.log("trade")
console.log('\nFunction: trade')
console.log(params)
}
client.api('AddOrder', params, function(error, data) {
Expand All @@ -267,11 +271,11 @@ module.exports = function container(get, set, clear) {
}

if (so.debug) {
console.log("Data")
console.log('\nData:')
console.log(data)
console.log("Order")
console.log('\nOrder:')
console.log(order)
console.log("Error")
console.log('\nError:')
console.log(error)
}

Expand Down Expand Up @@ -329,7 +333,7 @@ module.exports = function container(get, set, clear) {
}
var orderData = data.result[params.txid]
if (so.debug) {
console.log("QueryOrders")
console.log('\nfunction: QueryOrders')
console.log(orderData)
}

Expand Down Expand Up @@ -363,4 +367,4 @@ module.exports = function container(get, set, clear) {
}
}
return exchange
}
}