🛠 Refactor to use commands

This commit is contained in:
Dennis Reimann
2020-11-10 11:17:07 +01:00
parent d1b2052494
commit 0e571e8965
7 changed files with 89 additions and 107 deletions

25
commands/withdraw.js Normal file
View File

@@ -0,0 +1,25 @@
module.exports = async (kraken, validate, getEnv) => {
const [maxFee, key] = getEnv('KRAKEN_MAX_REL_FEE', 'KRAKEN_WITHDRAW_KEY')
// https://api.kraken.com/0/private/WithdrawInfo
const asset = 'XBT'
const withdrawdetails = { asset, key, amount: 0 }
// Get withdrawal information
const { result: { limit, fee } } = await kraken.api('WithdrawInfo', withdrawdetails)
const relFee = 1/parseFloat(limit)*parseFloat(fee)
console.log(`💡 Relative fee of withdrawal amount: ${(relFee*100).toFixed(2)}%`)
// Place withdrawal when fee is low enough (relatively)
if (relFee < maxFee/100) {
console.log(`💰 Withdraw ${limit} ${asset} now.`)
const withdraw = { asset, key, amount: limit }
if (!validate) {
const { result: { refid } } = await kraken.api('Withdraw', withdraw)
if (refid) console.log(`📎 Withdrawal reference ID: ${refid}`)
}
} else {
console.log(`❌ Fee is too high - max rel. fee: ${parseFloat(maxFee).toFixed(2)}%`)
}
}