From e907387b123ecf47af9de411a070831fba08bb9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=B6ferle?= <45008800+sstoefe@users.noreply.github.com> Date: Sat, 3 Apr 2021 20:47:12 +0200 Subject: [PATCH] Set Fee currency (#8) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fees are by default paid with the fiat money. This means that you bought crypto for the specified amount (e.g. 25 USD) and the fees are charged separately. When you want to spend 100 USD over 4 weeks, meaning 1 order per week, the last order won't be placed since there is not enough fiat money left. In my case I wanted to spend 100 EUR a month, meaning 25 € once per week. When testing it the first time I was charged 25,065 EUR. By setting the fee to XBT instead of EUR, I can run the script 4 times a month. --- README.md | 1 + commands/stack.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bd86893..043fb25 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ KRAKEN_API_SECRET="privateKeyFromTheKrakenSettings" KRAKEN_ORDER_TYPE="market" # "limit" (default) or "market" KRAKEN_API_FIAT="USD" # the governmental shitcoin you are selling KRAKEN_BUY_AMOUNT=21 # fiat amount you trade for the future of money +KRAKEN_FEE_CURRENCY="XBT" # pay fee in this currency, e.g. buying XBT for USD and paying fee in XBT # used for withdrawal KRAKEN_MAX_REL_FEE=0.5 # maximum fee in % that you are willing to pay diff --git a/commands/stack.js b/commands/stack.js index a79d101..552ea42 100644 --- a/commands/stack.js +++ b/commands/stack.js @@ -1,5 +1,5 @@ module.exports = async (kraken, validate, { getEnv, getEnvOpt }) => { - const [fiat, amount] = getEnv('KRAKEN_API_FIAT', 'KRAKEN_BUY_AMOUNT') + const [fiat, amount, feeCurrency] = getEnv('KRAKEN_API_FIAT', 'KRAKEN_BUY_AMOUNT', 'KRAKEN_FEE_CURRENCY') const ordertype = getEnvOpt('KRAKEN_ORDER_TYPE', 'limit', ['limit', 'market']) // if living in Germany, one needs to add an additional parameter to explicitly agree to the trade // if the parameter is not set one will get the following error: EOrder:Trading agreement required @@ -10,6 +10,16 @@ module.exports = async (kraken, validate, { getEnv, getEnvOpt }) => { const crypto = 'XBT' const pair = `${crypto}${fiat}` + // for explanation of oflags see https://www.kraken.com/features/api#add-standard-order + var fee = "" + if (feeCurrency == crypto) { + fee = "fcib" + } else if (feeCurrency == fiat) { + fee = "fciq" + } else { + fee = "" + } + // Fetch and display information const { result: balance } = await kraken.api('Balance') const { result: ticker } = await kraken.api('Ticker', { pair }) @@ -32,6 +42,7 @@ module.exports = async (kraken, validate, { getEnv, getEnvOpt }) => { const details = { pair, type: 'buy', ordertype, price, volume } if (validate) details.validate = true if (trading_agreement) details.trading_agreement = trading_agreement + if (fee) details.oflags = fee const { result: { descr: { order }, txid } } = await kraken.api('AddOrder', details)