🧤 Cleanups
This commit is contained in:
86
README.md
86
README.md
@@ -5,21 +5,6 @@ First off: Here's to you, [Bittr](https://getbittr.com/) – you will be missed!
|
|||||||
This script is not a full replacement for the incredible service Bittr offered, but it's a start:
|
This script is not a full replacement for the incredible service Bittr offered, but it's a start:
|
||||||
Automate your Stacking Sats process by regularly placing buy orders using the [Kraken API](https://www.kraken.com/features/api).
|
Automate your Stacking Sats process by regularly placing buy orders using the [Kraken API](https://www.kraken.com/features/api).
|
||||||
|
|
||||||
Holding significant amounts on an exchange is never a good idea. You should regularly take ownership of your coins by withdrawing to your own wallet. This can either be done manually or it can be automated. The script provided here will only withdraw to a previously defined Bitcoin address if the relative fees do not exceed a certain limit.
|
|
||||||
*It is optional to run the witdrawal script.*
|
|
||||||
|
|
||||||
**Example 1**
|
|
||||||
- Max. relative fee: 0.5%
|
|
||||||
- Fixed Kraken fee: ₿ 0.00050
|
|
||||||
- Balance: ₿ 0.06000
|
|
||||||
- \> No withdrawal since fee actual (0.83%) is too high
|
|
||||||
|
|
||||||
**Example 2**
|
|
||||||
- Max. relative fee: 0.5%
|
|
||||||
- Fixed Kraken fee: ₿ 0.00050
|
|
||||||
- Balance: ₿ 0.12000
|
|
||||||
- \> Withdrawal executed since actual fee (0.42%) is low enough
|
|
||||||
|
|
||||||
## ✋ Caveat
|
## ✋ Caveat
|
||||||
|
|
||||||
You need to install the dependency [kraken-api](https://github.com/nothingisdead/npm-kraken-api), which is a third-party package.
|
You need to install the dependency [kraken-api](https://github.com/nothingisdead/npm-kraken-api), which is a third-party package.
|
||||||
@@ -36,9 +21,7 @@ Generate a new API key dedicated for stacking using the "Query Funds" and "Modif
|
|||||||

|

|
||||||
|
|
||||||
Only check the "Withdraw Funds" option if you plan to automatically withdraw Bitcoin from Kraken.
|
Only check the "Withdraw Funds" option if you plan to automatically withdraw Bitcoin from Kraken.
|
||||||
|
See details below.
|
||||||
## 🔑 Withrawal method
|
|
||||||
In case you plan to automatically withdraw from Kraken, a withdrawal method must first be defined. If you already set up a methode you can reuse it. Otherwise generate a new one by going to **Funding** > **Bitcoin (XBT) withdraw** > **Add address**. The description field will later be used as an environment variable in the script.
|
|
||||||
|
|
||||||
## 📦 Setup
|
## 📦 Setup
|
||||||
|
|
||||||
@@ -56,10 +39,10 @@ Setup the environment variables for the script:
|
|||||||
# used to authenticate with Kraken
|
# used to authenticate with Kraken
|
||||||
export KRAKEN_API_KEY="apiKeyFromTheKrakenSettings"
|
export KRAKEN_API_KEY="apiKeyFromTheKrakenSettings"
|
||||||
export KRAKEN_API_SECRET="privateKeyFromTheKrakenSettings"
|
export KRAKEN_API_SECRET="privateKeyFromTheKrakenSettings"
|
||||||
# used only for buying
|
# used for buying
|
||||||
export KRAKEN_API_FIAT="USD" # the governmental shitcoin you are selling
|
export KRAKEN_API_FIAT="USD" # the governmental shitcoin you are selling
|
||||||
export KRAKEN_BUY_AMOUNT=21 # fiat amount you trade for the future of money
|
export KRAKEN_BUY_AMOUNT=21 # fiat amount you trade for the future of money
|
||||||
# used only for withdrawing
|
# used for withdrawal
|
||||||
export KRAKEN_MAX_REL_FEE=0.5 # maximum fee in % that you are willing to pay
|
export KRAKEN_MAX_REL_FEE=0.5 # maximum fee in % that you are willing to pay
|
||||||
export KRAKEN_WITHDRAW_KEY="descriptionOfWithdrawalAddress"
|
export KRAKEN_WITHDRAW_KEY="descriptionOfWithdrawalAddress"
|
||||||
```
|
```
|
||||||
@@ -67,7 +50,7 @@ export KRAKEN_WITHDRAW_KEY="descriptionOfWithdrawalAddress"
|
|||||||
Use a dry run to test the script and see the output without placing an order:
|
Use a dry run to test the script and see the output without placing an order:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
npm test
|
npm run test:stack-sats
|
||||||
```
|
```
|
||||||
|
|
||||||
You should see something like this sample output:
|
You should see something like this sample output:
|
||||||
@@ -82,20 +65,6 @@ You should see something like this sample output:
|
|||||||
📎 Transaction ID: 2121212121
|
📎 Transaction ID: 2121212121
|
||||||
```
|
```
|
||||||
|
|
||||||
To test the withdrawal of funds to your defined address run:
|
|
||||||
```sh
|
|
||||||
npm run test-withdraw-sats
|
|
||||||
```
|
|
||||||
You should see something like this:
|
|
||||||
```text
|
|
||||||
💡 Relative fee of withdrawal amount: 5.57%
|
|
||||||
|
|
||||||
❌ Don't withdraw now. Fee is too high. Max rel. fee: 0.50%
|
|
||||||
|
|
||||||
🚨 THIS WAS JUST A VALIDATION RUN, NO WITHDRAWAL HAS BEEN PLACED!
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
## 🤑 Stack sats
|
## 🤑 Stack sats
|
||||||
|
|
||||||
When you are good to go, execute this command in a regular interval:
|
When you are good to go, execute this command in a regular interval:
|
||||||
@@ -137,14 +106,57 @@ Make it executable with `chmod +x stack-sats.sh` and go wild.
|
|||||||
|
|
||||||
[Stay humble!](https://twitter.com/matt_odell/status/1117222441867194374) 🙏
|
[Stay humble!](https://twitter.com/matt_odell/status/1117222441867194374) 🙏
|
||||||
|
|
||||||
## 🔑 Withraw sats
|
## 🔑 Withdrawal
|
||||||
|
|
||||||
|
Holding significant amounts on an exchange is never a good idea.
|
||||||
|
You should regularly take ownership of your coins by withdrawing to your own wallet.
|
||||||
|
This can either be done manually or it can be automated.
|
||||||
|
The script provided here will only withdraw to a previously defined Bitcoin address if the relative fees do not exceed a certain limit.
|
||||||
|
|
||||||
|
*It is optional to run the witdrawal script.*
|
||||||
|
|
||||||
|
### Example 1
|
||||||
|
|
||||||
|
- Max. relative fee: 0.5%
|
||||||
|
- Fixed Kraken fee: ₿ 0.00050
|
||||||
|
- Balance: ₿ 0.06000
|
||||||
|
- \> No withdrawal since fee actual (0.83%) is too high
|
||||||
|
|
||||||
|
### Example 2
|
||||||
|
|
||||||
|
- Max. relative fee: 0.5%
|
||||||
|
- Fixed Kraken fee: ₿ 0.00050
|
||||||
|
- Balance: ₿ 0.12000
|
||||||
|
- \> Withdrawal executed since actual fee (0.42%) is low enough
|
||||||
|
|
||||||
|
In case you plan to automatically withdraw from Kraken, a withdrawal method must first be defined.
|
||||||
|
If you already set up a methode you can reuse it.
|
||||||
|
Otherwise generate a new one by going to **Funding > Bitcoin (XBT) withdraw > Add address**.
|
||||||
|
The description field will later be used as an environment variable in the script.
|
||||||
|
|
||||||
|
To test the withdrawal of funds to your defined address run:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm run test:withdraw-sats
|
||||||
|
```
|
||||||
|
|
||||||
|
You should see something like this:
|
||||||
|
|
||||||
|
```text
|
||||||
|
💡 Relative fee of withdrawal amount: 5.57%
|
||||||
|
❌ Don't withdraw now. Fee is too high – max rel. fee: 0.50%
|
||||||
|
|
||||||
|
🚨 THIS WAS JUST A VALIDATION RUN, NO WITHDRAWAL HAS BEEN PLACED!
|
||||||
|
```
|
||||||
|
|
||||||
It is recommended to run the withdrawal script every time you stacked sats:
|
It is recommended to run the withdrawal script every time you stacked sats:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
npm run withdraw-sats
|
npm run withdraw-sats
|
||||||
```
|
```
|
||||||
Since it can take a couple seconds or minutes for your order to fill, you should run the following script maybe a couple hours later after your `stack-sats` script ran. Just set up a second cron job which executes the following script.
|
|
||||||
|
Since it can take a couple seconds or minutes for your order to fill, you should run the following script maybe a couple hours later after your `stack-sats` script ran.
|
||||||
|
Just set up a second cron job which executes the following script.
|
||||||
|
|
||||||
Here's a sample `withdraw-sats.sh` script:
|
Here's a sample `withdraw-sats.sh` script:
|
||||||
|
|
||||||
|
|||||||
@@ -5,12 +5,12 @@
|
|||||||
"description": "Use the Kraken API to stack sats",
|
"description": "Use the Kraken API to stack sats",
|
||||||
"author": "Dennis Reimann <mail@dennisreimann.de>",
|
"author": "Dennis Reimann <mail@dennisreimann.de>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "index.js",
|
"main": "stack.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"stack-sats": "node index.js",
|
"stack-sats": "node stack.js",
|
||||||
"withdraw-sats": "node withdraw.js",
|
"withdraw-sats": "node withdraw.js",
|
||||||
"test-withdraw-sats": "node withdraw.js --validate",
|
"test:stack-sats": "node stack.js --validate",
|
||||||
"test": "node index.js --validate"
|
"test:withdraw-sats": "node withdraw.js --validate"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"kraken-api": "1.0.0"
|
"kraken-api": "1.0.0"
|
||||||
|
|||||||
12
withdraw.js
12
withdraw.js
@@ -13,22 +13,22 @@ assert(max_fee && wdr_key, 'Provide the KRAKEN_MAX_REL_FEE and KRAKEN_WITHDRAW_K
|
|||||||
|
|
||||||
// https://www.kraken.com/features/api
|
// https://www.kraken.com/features/api
|
||||||
const kraken = new Kraken(key, secret)
|
const kraken = new Kraken(key, secret)
|
||||||
const crypto = 'XBT'
|
const asset = 'XBT'
|
||||||
const validate = process.argv[2] === '--validate'
|
const validate = process.argv[2] === '--validate'
|
||||||
|
|
||||||
;(async () => {
|
;(async () => {
|
||||||
// Get withdrawal information
|
// Get withdrawal information
|
||||||
// URL: https://api.kraken.com/0/private/WithdrawInfo
|
// URL: https://api.kraken.com/0/private/WithdrawInfo
|
||||||
const withdrawdetails = { asset: crypto, key: wdr_key, amount: 0 }
|
const withdrawdetails = { asset, key: wdr_key, amount: 0 }
|
||||||
try {
|
try {
|
||||||
const { result: { method, limit, fee } } = await kraken.api('WithdrawInfo', withdrawdetails);
|
const { result: { limit, fee } } = await kraken.api('WithdrawInfo', withdrawdetails);
|
||||||
const rel_fee = 1/parseFloat(limit)*parseFloat(fee)
|
const rel_fee = 1/parseFloat(limit)*parseFloat(fee)
|
||||||
console.log(`💡 Relative fee of withdrawal amount: ${(rel_fee*100).toFixed(2)}%`)
|
console.log(`💡 Relative fee of withdrawal amount: ${(rel_fee*100).toFixed(2)}%`)
|
||||||
|
|
||||||
// Place withdrawal when fee is low enough (relatively)
|
// Place withdrawal when fee is low enough (relatively)
|
||||||
if (rel_fee < max_fee/100) {
|
if (rel_fee < max_fee/100) {
|
||||||
console.log(`⏏️ Withdraw ${limit} ${crypto} now.`)
|
console.log(`💰 Withdraw ${limit} ${asset} now.`)
|
||||||
const withdraw = { asset: crypto, key: wdr_key, amount: limit }
|
const withdraw = { asset, key: wdr_key, amount: limit }
|
||||||
if (!validate) {
|
if (!validate) {
|
||||||
try {
|
try {
|
||||||
const { result: { refid } } = await kraken.api('Withdraw', withdraw)
|
const { result: { refid } } = await kraken.api('Withdraw', withdraw)
|
||||||
@@ -38,7 +38,7 @@ const validate = process.argv[2] === '--validate'
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log(`\n❌ Don\'t withdraw now. Fee is too high. Max rel. fee: ${parseFloat(max_fee).toFixed(2)}%`);
|
console.log(`❌ Don't withdraw now. Fee is too high - max rel. fee: ${parseFloat(max_fee).toFixed(2)}%`);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(`\n🚨 Failure:`, err.message)
|
console.log(`\n🚨 Failure:`, err.message)
|
||||||
|
|||||||
Reference in New Issue
Block a user