Skip to content

Commit

Permalink
FIxing kraken product update and product list (DeviaVir#483)
Browse files Browse the repository at this point in the history
* Fixing kraken product update and product list

* Fix for Kraken's inconsistent approach to currency

Also update products as kraken recently delisted some pairs.
  • Loading branch information
cmroche authored and DeviaVir committed Aug 27, 2017
1 parent 0bdf3d8 commit 48d5b24
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 110 deletions.
19 changes: 16 additions & 3 deletions extensions/exchanges/kraken/exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ module.exports = function container(get, set, clear) {
return product_id.split('-')[0] + product_id.split('-')[1]
}

// This is to deal with a silly bug where kraken doesn't use a consistent definition for currency
// with certain assets they will mix the use of 'Z' and 'X' prefixes
function joinProductFormatted(product_id) {
var asset = product_id.split('-')[0]
var currency = product_id.split('-')[1]

var assetsToFix = ['BCH', 'DASH', 'EOS', 'GNO']
if (assetsToFix.indexOf(asset) >= 0 && currency.length > 3) {
currency = currency.substring(1)
}
return asset + currency;
}

function retry(method, args, error) {
if (error.message.match(/API:Rate limit exceeded/)) {
var timeout = 10000
Expand Down Expand Up @@ -77,7 +90,7 @@ module.exports = function container(get, set, clear) {
var func_args = [].slice.call(arguments)
var client = publicClient()
var args = {
pair: joinProduct(opts.product_id)
pair: joinProductFormatted(opts.product_id)
}
if (opts.from) {
args.since = Number(opts.from) * 1000000
Expand Down Expand Up @@ -155,7 +168,7 @@ module.exports = function container(get, set, clear) {
getQuote: function(opts, cb) {
var args = [].slice.call(arguments)
var client = publicClient()
var pair = joinProduct(opts.product_id)
var pair = joinProductFormatted(opts.product_id)
client.api('Ticker', {
pair: pair
}, function(error, data) {
Expand Down Expand Up @@ -206,7 +219,7 @@ module.exports = function container(get, set, clear) {
var args = [].slice.call(arguments)
var client = authedClient()
var params = {
pair: joinProduct(opts.product_id),
pair: joinProductFormatted(opts.product_id),
type: type,
ordertype: (opts.order_type === 'taker' ? 'market' : 'limit'),
volume: opts.size,
Expand Down
77 changes: 0 additions & 77 deletions extensions/exchanges/kraken/products.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,6 @@
"increment": "0.00000001",
"label": "EOS/ETH"
},
{
"asset": "EOS",
"currency": "ZEUR",
"min_size": "0.01",
"increment": "0.00000001",
"label": "EOS/EUR"
},
{
"asset": "EOS",
"currency": "ZUSD",
"min_size": "0.01",
"increment": "0.00000001",
"label": "EOS/USD"
},
{
"asset": "EOS",
"currency": "XXBT",
Expand All @@ -76,20 +62,6 @@
"increment": "0.00000001",
"label": "GNO/ETH"
},
{
"asset": "GNO",
"currency": "ZEUR",
"min_size": "0.01",
"increment": "0.00000001",
"label": "GNO/EUR"
},
{
"asset": "GNO",
"currency": "ZUSD",
"min_size": "0.01",
"increment": "0.00000001",
"label": "GNO/USD"
},
{
"asset": "GNO",
"currency": "XXBT",
Expand Down Expand Up @@ -153,13 +125,6 @@
"increment": "0.00000001",
"label": "ETH/EUR"
},
{
"asset": "XETH",
"currency": "ZGBP",
"min_size": "0.01",
"increment": "0.00000001",
"label": "ETH/GBP"
},
{
"asset": "XETH",
"currency": "ZJPY",
Expand Down Expand Up @@ -244,13 +209,6 @@
"increment": "0.00000001",
"label": "REP/EUR"
},
{
"asset": "XREP",
"currency": "ZUSD",
"min_size": "0.01",
"increment": "0.00000001",
"label": "REP/USD"
},
{
"asset": "XXBT",
"currency": "ZCAD",
Expand All @@ -265,13 +223,6 @@
"increment": "0.00000001",
"label": "XBT/EUR"
},
{
"asset": "XXBT",
"currency": "ZGBP",
"min_size": "0.01",
"increment": "0.00000001",
"label": "XBT/GBP"
},
{
"asset": "XXBT",
"currency": "ZJPY",
Expand Down Expand Up @@ -300,20 +251,6 @@
"increment": "0.00000001",
"label": "XLM/XBT"
},
{
"asset": "XXLM",
"currency": "ZEUR",
"min_size": "0.01",
"increment": "0.00000001",
"label": "XLM/EUR"
},
{
"asset": "XXLM",
"currency": "ZUSD",
"min_size": "0.01",
"increment": "0.00000001",
"label": "XLM/USD"
},
{
"asset": "XXMR",
"currency": "XXBT",
Expand Down Expand Up @@ -342,27 +279,13 @@
"increment": "0.00000001",
"label": "XRP/XBT"
},
{
"asset": "XXRP",
"currency": "ZCAD",
"min_size": "0.01",
"increment": "0.00000001",
"label": "XRP/CAD"
},
{
"asset": "XXRP",
"currency": "ZEUR",
"min_size": "0.01",
"increment": "0.00000001",
"label": "XRP/EUR"
},
{
"asset": "XXRP",
"currency": "ZJPY",
"min_size": "0.01",
"increment": "0.00000001",
"label": "XRP/JPY"
},
{
"asset": "XXRP",
"currency": "ZUSD",
Expand Down
60 changes: 30 additions & 30 deletions extensions/exchanges/kraken/update-products.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,42 @@ var mapping
var products = []

function addProduct(base, quote, altname) {
products.push({
asset: base,
currency: quote,
min_size: '0.01',
increment: '0.00000001',
label: getPair(base) + '/' + getPair(quote)
})
products.push({
asset: base,
currency: quote,
min_size: '0.01',
increment: '0.00000001',
label: getPair(base) + '/' + getPair(quote)
})
}

function getPair(name) {
return mapping[name].altname
return mapping[name].altname
}

kraken.api('Assets', null, function (error, data) {
if (error) {
console.log(error)
process.exit(1)
} else {
kraken.api('Assets', null, function(error, data) {
if (error) {
console.log(error)
process.exit(1)
} else {

mapping = data.result
mapping = data.result

kraken.api('AssetPairs', null, function (error, data) {
if (error) {
console.log(error)
process.exit(1)
} else {
Object.keys(data.result).forEach(function (result) {
if(!result.match('\.d')) {
addProduct(data.result[result].base, data.result[result].quote, data.result[result].altname)
}
})
var target = require('path').resolve(__dirname, 'products.json')
require('fs').writeFileSync(target, JSON.stringify(products, null, 2))
console.log('wrote', target)
process.exit()
}
kraken.api('AssetPairs', null, function(error, data) {
if (error) {
console.log(error)
process.exit(1)
} else {
Object.keys(data.result).forEach(function(result) {
if (!result.match('\.d')) {
addProduct(data.result[result].base, data.result[result].quote, data.result[result].altname)
}
})
}
var target = require('path').resolve(__dirname, 'products.json')
require('fs').writeFileSync(target, JSON.stringify(products, null, 2))
console.log('wrote', target)
process.exit()
}
})
}
})

0 comments on commit 48d5b24

Please sign in to comment.