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

CEXIO use "my" fees #967

Merged
merged 2 commits into from
Jan 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions extensions/exchanges/cexio/exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,31 @@ module.exports = function container (get, set, clear) {
}, 10000)
}

function refreshFees(args) {
var skew = 5000 // in ms
var now = new Date();
var nowUTC = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds())
var midnightUTC = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds()).setHours(24,0,0,0)
var countdown = midnightUTC - nowUTC + skew
if (so.debug) {
var hours = parseInt((countdown/(1000*60*60))%24)
var minutes = parseInt((countdown/(1000*60))%60)
var seconds = parseInt((countdown/1000)%60)
console.log('\nRefreshing fees in ' + hours + ' hours ' + minutes + ' minutes ' + seconds + ' seconds')
}
setTimeout(function() {
exchange['setFees'].apply(exchange, args)
}, countdown)
}

var orders = {}
var exchange = {
name: 'cexio',
historyScan: 'forward',
backfillRateLimit: 0,
makerFee: 0.16,
takerFee: 0.25,
dynamicFees: true,

getProducts: function () {
return require('./products.json')
Expand Down Expand Up @@ -182,6 +200,32 @@ module.exports = function container (get, set, clear) {
})
},

setFees: function(opts) {
var func_args = [].slice.call(arguments)
var client = authedClient()
client.get_my_fee(function (err, body) {
if (err || (typeof body === 'string' && body.match(/error/))) {
if (so.debug) {
console.log(('\nsetFees ' + body + ' - using fixed fees!').red)
}
return retry('setFees', func_args)
} else {
var pair = opts.asset + ':' + opts.currency
var makerFee = (parseFloat(body[pair].buyMaker) + parseFloat(body[pair].sellMaker)) / 2
var takerFee = (parseFloat(body[pair].buy) + parseFloat(body[pair].sell)) / 2
if (exchange.makerFee != makerFee) {
if (so.debug) console.log('\nMaker fee changed: ' + exchange.makerFee + '% -> ' + makerFee + '%')
exchange.makerFee = makerFee
}
if (exchange.takerFee != takerFee) {
if (so.debug) console.log('\nTaker fee changed: ' + exchange.takerFee + '% -> ' + takerFee + '%')
exchange.takerFee = takerFee
}
}
return refreshFees(func_args)
})
},

// return the property used for range querying.
getCursor: function (trade) {
return trade.trade_id
Expand Down
3 changes: 3 additions & 0 deletions lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ module.exports = function container (get, set, clear) {
console.error('error: could not find product "' + s.product_id + '"')
process.exit(1)
}
if ((so.mode === 'live' || so.mode === 'paper') && s.exchange.dynamicFees) {
s.exchange.setFees({asset: s.asset, currency: s.currency})
}
if (so.mode === 'sim' || so.mode === 'paper') {
s.balance = {asset: so.asset_capital, currency: so.currency_capital}
}
Expand Down