kraken-grid 1.2.10 → 1.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
File without changes
package/README.md CHANGED
@@ -79,9 +79,27 @@ This version stores your API key and secret using your password. This informati
79
79
  This software will save a file `keys.txt` to your home folder.
80
80
 
81
81
  ## Usage
82
+ If you have proceeded with step four of the installation, then you have a running bot. You can issue commands to it by typing in the same console where you ran `kraken-gird`. This section describes what the commands are, but first, here's...
83
+ ### How the author (Dave) does it for himself and others:
84
+ 1. Select a random number between 8000 and 65000 and then issue the command `web on X`, replacing X with your number. You will see the URL this creates for you to use the webpage the bot builds to show what it's doing.
85
+ 2. Visit that webpage.
86
+ 2.a. The username for the webpage is `admin`. The password you set is the password for the webpage also.
87
+ 2.b. You will notice some "handles" that indicate rectangular elements of the page which you can resize by moving the handles around. Two of these "handles" are at the bottom, one for the "Table of Contents" help section, and one that determines how much horizontal space the two tables next it can use. Adjust as you please. The bot will record these sizes in your browsers' cookies.
88
+ 3. You will see that the both tables show what assets you have on the exchange, and the lower table ("Allocation") shows what portion of your exchange holdings are held in each asset in the "Current" line. In the "Desired" line below it, you can click any of these except the one for U.S. Dollars (ZUSD) to change their value. If you increase it, the ZUSD value will be decreased by the same amount. This will be reflected in the "Desired" line, which shows the target allocations for each asset. We recommend setting a target allocation of an equal amount for each asset, but only half, as you'll see below.
89
+ 4. If you have bitcoin, in the console where you started the bot, type `adjust XXBT` (XXBT is bitcoin's ticker on Kraken) followed by two numbers. The first should be under the allocation you set for ZUSD and the second is best described as a guess about what percentage of the price range of XXBT will volatility stay within. I'll use 25 because bitcoin is still kind of volatile. The adjust command tells the bot to increase the allocation for an asset as the price goes down through the most recent trading range in which the high is at least X% more than the low where X is the second number you entered. For me this would mean the high is 125% of the low. If the price is near the low, the first number you used is the percent that will be subtracted from ZUSD and added to XXBT ("buy low"). Thus, your savings might be 50% BTC around the price 12500, but 60% BTC when it's around 10000 (if the second number were 10; 50 + 10 = 60). In this way, when the bot trades to rebalance, it will be trading larger amounts for more profit on round trips.
90
+ 5. If you have some other crypto on the exchange, you can do the same thing with it as I described in step 4 for XXBT (bitcoin). During a heavy drop across all cryptos, this will cause your USD allocation to drop a lot. For this reason, the bot won't let you do an adjustment that would require a negative allocation of USD. It misreports this as "You'd run out of cash" which should be "You'd have to short USD".
91
+ 6. Once you have determined the allocation you want, with enough allocated to USD to make adjustments at lower prices, and you've added all the adjustments you want (only one for each crypto), then you can use the `balance` command. In the lower table of the web page, there is a clickable number in the upper left corner which says "Balance Tolerance" when you hover over it. This is used to build a `balance` command that will be proposed to be sent to the bot when you click the price of any asset. We recommend reading the documentation for `balance` as it places trades for you to achieve your target allocation and maintain it when the bot is in `auto` mode.
92
+ #### Discussion of the `adjust` command.
93
+ This strategy can only _increase_ the allocation, and not decrease it. To put it simply, allocation should be set to how much of your savings you want to be in this asset when it's _at the highest price_. Let's sayyou want the allocation to be perfectly even across all assets. When the prices are (all) at the bottom, you want all your cash to be spent. Here's how to set this up, assuming you want to hold at least half of your target allocation in an asset _at its highest price_ and the full target at the lowest one (This assumes you choose a trading range of 20%):
94
+
95
+ For a single crypto: Set your allocation to 50% (and 50% in USD or EUR or YEN, your _numeraire_, meaning the currency you use). Your adjust command would be `adjust TKR 50 20` where TKR is the ticker for your crypto. For two cryptos, set the allocation for each to 33.33% (leaving 33.33% for your numeraire). Your adjust command would be `adjust TKR 16.67 20` for each one.
96
+
97
+ How did I get the 50% and the 33.33%? Imagine the assets are all at their highest prices. This is what the allocation and adjust commands are designed to handle. It's the smallest amount you'd ever want to hold, and the result of leaving enough cash to be evenly allocated at all the lowest prices. Since you're doing it evenly across all your assets, we want to evenly distribute between all assets and then evenly distribute whatever is in cash between everything else. Including cash, divide 100% by the number of assets (100/3 or 100/2 for two or one crypto). That's how much goes into each asset for the allocation command. Divide by one less than your asset count (or just exclude cash) to see how much cash will need to be spent on each asset when all prices are at their lowest. 50/1 is 50%, and 33.33/2 is 16.67%. For three cryptos and cash, the numbers are 25 and 25/3 = 8.33%, so allocate 25% to each asset and do `adjust TKR 8.33 20` for each one.
98
+
99
+ If you have 9 cryptos you're balancing (plus cash), your numbers are 10 and 10/9 = 1.11. For each of the nine cryptos, you'd do `allocate TKR 10` and `adjust TKR 1.11 20`.
82
100
 
83
101
  ### Web UI
84
- `web [on|off]` This turns the web User Interface on or off.
102
+ `web [on|off] P` This turns the web User Interface on or off, providing the URL. P is the port number, which will default to 8000.
85
103
 
86
104
  This readme is displayed in the web User Interface. It contains `code that looks like this` which you can click to send commands to the bot. If you just tried it, check the console and you will see that it's asking you to "Try code raw"...
87
105
  * Answering with anything that starts with a y will send it to kraken which will reject it. The error also causes the bot to abandon [auto](#auto) mode if it was in auto mode.
@@ -212,8 +230,8 @@ As LTC bumps around near the price of 100, you will be trading more of it and th
212
230
 
213
231
  Note: The bot does not (yet) adjust the volume on trades when the price of an adjusted allocation exceeds the current range. It does adjust the allocation and so you will see that the trades need to be reset when you look at the Allocation table in the Web UI.
214
232
 
215
- #### allocate [S P [A]]
216
- `allocate` starts a process through which you can enter how you want your savings allocated (see [Balancing the Present](https://litmocracy.blogspot.com/2019/06/balancing-present.html), which is the motivation for this software). It will ask if you want to erase your current allocation even if you don't have one. When you have no allocation, it starts with the actual current allocation as a default and allows you to adjust it. When you are satisfied with your allocation settings, enter N instead of a ticker to get back to the bot.
233
+ #### allocate
234
+ `allocate [S P [A]]` starts a process through which you can enter how you want your savings allocated (see [Balancing the Present](https://litmocracy.blogspot.com/2019/06/balancing-present.html), which is the motivation for this software). It will ask if you want to erase your current allocation even if you don't have one. When you have no allocation, it starts with the actual current allocation as a default and allows you to adjust it. When you are satisfied with your allocation settings, enter N instead of a ticker to get back to the bot.
217
235
  If you include parameters to `allocate`:
218
236
  * `S` is a symbol and if it is found in the list of asset tickers from the exchange (only Kraken at the time of writing), the bot will record `P` as the percentage allocation target for your savings.
219
237
  * `P` must be a number (any more than two decimal places will be ignored). It is interpreted as the percentage of your entire savings you would like this asset to be. If such an allocation is already recorded (and `A` is not present and "false"), the bot will ask you to confirm that you want to update it. Your default currency allocation will be adjusted so that the full allocation adds up to 100%.
package/allocation.js CHANGED
File without changes
package/balancer.js CHANGED
File without changes
package/bot.js CHANGED
@@ -24,6 +24,7 @@ function Bot() {
24
24
  //p.
25
25
  if(FLAGS.verbose) console.log(p);
26
26
  Bot.s = this;
27
+ Bot.PW = safestore.getPW();
27
28
  Bot.extra = p.extra ? p.extra : {};
28
29
  kraken = new KrakenClient(p.key, p.secret);
29
30
  Bot.pairs = await cachePairs();
@@ -170,6 +171,7 @@ if(FLAGS.verbose) console.log(p);
170
171
  console.log(172,err.message+" Maybe next time.");
171
172
  ret = { result: { descr: "Postponed" }};
172
173
  } else {
174
+ console.log(174,"API key: ", portfolio.key);
173
175
  throw err;
174
176
  }
175
177
  await sleep(1000);
package/manager.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kraken-grid",
3
- "version": "1.2.10",
3
+ "version": "1.2.11",
4
4
  "description": "Bot repeatedly buys & sells on kraken from a conditional close order.",
5
5
  "main": "init.js",
6
6
  "bin": "./init.js",
@@ -41,10 +41,12 @@
41
41
  "concat-stream": "^2.0.0",
42
42
  "cryptex": "^1.0.1",
43
43
  "express": "^4.18.2",
44
+ "express-basic-auth": "^1.2.1",
44
45
  "express-session": "^1.17.3",
45
46
  "glob": "^10.1.0",
46
47
  "http-server": "^14.1.1",
47
48
  "kraka-djs": "^1.0.3",
49
+ "nvm": "^0.0.4",
48
50
  "prompt-sync": "^4.2.0",
49
51
  "ws": "^8.4.0"
50
52
  },
package/pricers/openex.js CHANGED
File without changes
package/safestore.js CHANGED
@@ -97,7 +97,10 @@ function Safestore(pwp = 'abc123') {
97
97
  persistent = p;
98
98
  return p;
99
99
  }
100
- return Object.freeze({persistent, read, replace, _update});
100
+
101
+ function getPW() { return pw; }
102
+
103
+ return Object.freeze({persistent, read, replace, _update, getPW});
101
104
  }
102
105
 
103
106
  module.exports = Safestore;
package/savings.js CHANGED
File without changes
package/static/aed.png CHANGED
File without changes
package/static/ag.png CHANGED
File without changes
package/static/au.png CHANGED
File without changes
package/static/aud.png CHANGED
File without changes
package/static/cad.png CHANGED
File without changes
package/static/client.js CHANGED
File without changes
package/static/eur.png CHANGED
File without changes
File without changes
package/static/gbp.png CHANGED
File without changes
File without changes
package/static/luna2.png CHANGED
File without changes
package/static/main.css CHANGED
File without changes
File without changes
package/static/usd.png CHANGED
File without changes
package/static/yen.png CHANGED
File without changes
package/test/test.js CHANGED
File without changes
File without changes
package/tt.js CHANGED
File without changes
package/web.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const express = require('express');
2
+ const basicAuth = require("express-basic-auth");
2
3
  const app = express();
3
4
  const path = require("path");
4
5
  const session = require('express-session');
@@ -24,31 +25,34 @@ function Web(man) {
24
25
  // Initialize
25
26
  const host = 'localhost';
26
27
  const port = process.TESTING ? 8001 : 8000;
27
- app.set('trust proxy', 1) // trust first proxy
28
- app.use(session({
29
- secret: '537R37',
30
- resave: false,
31
- saveUninitialized: false,
32
- cookie: { secure: false }
33
- }));
34
-
35
- app.use("/js",express.static(path.join(__dirname, 'static')));
36
- app.use("/img",express.static(path.join(__dirname, 'static')));
37
-
38
- function stop() {
39
- if(server) server.close();
40
- server = false;
41
- if(log_original) console.log = log_original;
42
- console.log("WebServer is off.");
43
- }
44
- function start(pport = port) {
45
- if(server) server.close();
46
- server = app.listen(pport,(e) => { if(e) console.log("HTTP Server failed:",e); });
47
- // Trap the console.log function
48
- console.log = log;
49
- log_original(`Server is running on http://${host}:${pport}`);
50
- }
51
- function address() { return server ? server.address : false; }
28
+ app.set('trust proxy', 1); // trust first proxy
29
+ app.use(session({
30
+ secret: '537R37',
31
+ resave: false,
32
+ saveUninitialized: false,
33
+ cookie: { secure: false }
34
+ }));
35
+
36
+ app.use("/js",express.static(path.join(__dirname, 'static')));
37
+ app.use("/img",express.static(path.join(__dirname, 'static')));
38
+ app.use(basicAuth({
39
+ challenge: true,
40
+ users: { 'admin': Bot.PW }
41
+ }));
42
+ function stop() {
43
+ if(server) server.close();
44
+ server = false;
45
+ if(log_original) console.log = log_original;
46
+ console.log("WebServer is off.");
47
+ }
48
+ function start(pport = port) {
49
+ if(server) server.close();
50
+ server = app.listen(pport,(e) => { if(e) console.log("HTTP Server failed:",e); });
51
+ // Trap the console.log function
52
+ console.log = log;
53
+ log_original(`Server is running on http://${host}:${pport}`);
54
+ }
55
+ function address() { return server ? server.address : false; }
52
56
 
53
57
  app.use(bodyParser.urlencoded({ extended: false }));
54
58