kraken-grid 1.0.1 → 1.0.2

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.
Files changed (3) hide show
  1. package/README.md +18 -19
  2. package/index.js +14 -9
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -4,18 +4,7 @@ A bot that extends grid trading once you use it to create a grid using orders wi
4
4
  This was developed with NodeJS running in the BASH shell provided by Windows 10. I believe it's using "Windows Subsystem for Linux" and that there are some oddities because of this. I don't see them as odd because I'm not familiar enough with Linux yet.
5
5
 
6
6
  ## Installation
7
- I would like `npm install kraken-grid` to work, and it may work simply because the code is here on Github. If not, perhaps someone who knows how to make it work will explain that to me. Assuming that doesn't work yet, place the file kraken-grid.js into a folder and then call `node kraken-grid.js` from a console using that folder as its working directory.
8
-
9
- Once the file (kraken-grid.js) is installed with the dependencies (NPM and/or Node figures this out), you can run it and it will tell you to save a file `keys.js` to the parent folder after adding your API keys from Kraken to it:
10
- ```
11
- exports.key=' **your key goes here** ';
12
- exports.secret=' **Your secret goes here** ';
13
-
14
- // If you want private initialization code, (mine backs up the file)
15
- // this is a good place to put it.
16
- ```
17
-
18
- Once you've done that, the first thing it will do is execute the `report` command, described below.
7
+ Once the file (kraken-grid.js) is installed with the dependencies (NPM and/or Node figures this out), you can run it and it will save a file`keys.txt to your home folder.
19
8
 
20
9
  ## Usage
21
10
  At the prompt that kraken-grid presents (>), you can enter one of these commands:
@@ -45,7 +34,7 @@ XLTC ...
45
34
  3. extend the grid if there are only buys or only sells remaining for the crypto identified in each order.
46
35
  4. identify any orders that are gone or new using Kraken's Order ID and for new orders, it also describes them.
47
36
 
48
- ### list
37
+ ### list [SEARCH]
49
38
  This simply prints out a list of all the orders the code last retrieved (it does NOT retrieve them again, so...) It may have orders in it that have already been executed. Each order is presented as:
50
39
  `Counter amount pair @ limit price [with A:B leverage] userref [close position @ limit price]`
51
40
  ...where:
@@ -55,6 +44,8 @@ This simply prints out a list of all the orders the code last retrieved (it does
55
44
  * The bracketed item will be missing for an order with default leverage or an order without a conditional close.
56
45
  * `userref` is a user-reference number derived from the UNIX TimeStamp when the order was placed. Extending the grid to higher sells uses a userref 10,000,000 less than the current highest sell's userref, and extending it to lower-priced buys uses a userref 1,000,000 less than the current lowest buy's userref. The last six digits of all userrefs are assumed to be different for every order.
57
46
 
47
+ If you enter anything for [SEARCH], the list will only display lines that contain what you entered, except in one case, C. If it's just the C, it will retrieve the last 50 orders that are no longer open (Filled, Cancelled, or Expired), but only list those that actually executed (Filled). If you add the userref then it will fetch only orders with that userref, which means the buys and sells at one grid point. See `set` for a list of them. Such orders also include the time at which the order filled completely.
48
+
58
49
  ### set
59
50
  This lists the `userref`s and prices at which buys and sells have been (and will be) placed.
60
51
 
@@ -71,7 +62,15 @@ X can be an Order ID from Kraken (recognized by the presence of dashes), a userr
71
62
 
72
63
  ### delev
73
64
  `delev C`
74
- C _must be_ a `Counter` as shows by executing `list`. If the identified order uses leverage, this command will first create an order without any leverage to replace it, and then kill the one identified. ***NOTE: The new order often (or always?) appears at the top of `list` after this, so the `Counter`s identifying other orders may change.
65
+ C _must be_ a `Counter` as shown by executing `list`. If the identified order uses leverage, this command will first create an order without any leverage to replace it, and then kill the one identified. ***NOTE: The new order often (or always?) appears at the top of `list` after this, so the `Counter`s identifying other orders may change.
66
+
67
+ ### addlev
68
+ `addlev C`
69
+ The semantics are the same as for `delev`.
70
+
71
+ ### refnum
72
+ `refnum C R`
73
+ C _must be_ a `Counter` as shown by executing `list`, and it must be an order that was entered without a userref. All orders added by the bot (automatically and manually) have a userref. This function is to allow you to enter an order at trade.kraken.com and then include it into an existing grid point by using that grid point's refnum (see `set`) as R.
75
74
 
76
75
  ### manual
77
76
  This stops the automatic calling of `report`. The bot will do nothing until you give it a new command.
@@ -79,16 +78,16 @@ This stops the automatic calling of `report`. The bot will do nothing until you
79
78
  ### verbose
80
79
  There is a little bit of logic in the code to spit out a lot more information when verbose is on. It's off by default and this command just toggles it.
81
80
 
81
+ ### safe
82
+ When the bot starts, it is in "safe" mode, which means that it will not __actually__ add or cancel any orders. The idea is that it won't do anything, but instead just show you what it would do if __safe__ were off. Your have to enter `safe` to turn this off so that the bot will actually do things. It allows for startup with a lot less rish with a possible buggy bot.
83
+
82
84
  ### ws - EXPERIMENTAL
83
85
  This connects to Kraken's WebSockets, which, I have to warn you, send you something about every second, and sometimes silently disconnects.
84
86
 
85
87
  ## Internals
86
- When you place an order through trade.kraken.com or through kraken.com, it will have a `userref` of zero. It will be displayed but ignored for the purposes of the grid trading it does. When you place an order through the bot, it will have a userref and the bot will assume you have not yet decided at what price to close it. It will ask _every time_ `report` is called, for example, from `auto` and it will do nothing until you answer. It will ask for every order that doesn't have a conditional close, and fill out the internal record of prices using your answer. To skip the rest of its requests for prices, answer with a question mark. If you're still running `auto`, however, it's going to ask again in N seconds.
87
-
88
- ### Handling pasted commands
89
- I use Excel to calculate my grid prices so I like to copy the commands that Excel builds for me. I thought Node would accept multiline iput as several pieces of input but it doesn't. They are all combined into one large input string that I first broke up using CHR(13) (whatever that was in Javascript, I can't remember now), but process.stdin handles it a little differently. Search for `readable` to see how I handled it.
88
+ When you place an order through trade.kraken.com or through kraken.com, it will have a `userref` of zero. It will be displayed but ignored for the purposes of the grid trading it does. When you place an order through the bot, it will have a userref and the bot will assume you have not yet decided at what price to close it.
90
89
 
91
90
  ## HELP!
92
91
  This code is messy and monolithic. It works for me and I didn't want to keep waiting until I cleaned it up to publish it. I haven't yet put enough thought into how (and whether) I would break it up into smaller files with specific purposes, so I'd love to see proposals. One of the major motivations I have for publishing it is that as more people use a strategy like "grid trader" to balance their savings, the prices of the cryptos with which they do it will become more stable.
93
92
 
94
- All calls to @nothingisdead's [Kraken-API](https://github.com/nothingisdead/npm-kraken-api) are made through a function I called `kapi` so that any other exchange could be used by updating that funtion to translate Kraken's APIs to those of other exchanges.
93
+ All calls to @nothingisdead's [Kraken-API](https://github.com/nothingisdead/npm-kraken-api) (which I have copied and renamed to kraka-djs to add CancelAll) are made through a function I called `kapi` so that any other exchange could be used by updating that funtion to translate Kraken's APIs to those of other exchanges.
package/index.js CHANGED
@@ -1,15 +1,21 @@
1
1
  #!/usr/bin/env node
2
- // COmment Line to see git diff...
3
2
  const fs = require('fs');
3
+ const prompt = require('prompt-sync')({sigint: true});
4
+
5
+ let homeDir = process.env.APPDATA
6
+ || (process.platform == 'darwin'
7
+ ? process.env.HOME + '/Library/Preferences'
8
+ : process.env.HOME + "/.local/share"),
9
+ keyFile = homeDir+'/keys.txt';
4
10
 
5
- if(!fs.existsSync('../keys.js')) {
6
- console.log("Paste your key and secret between the single quotes and save this"
7
- +" to the parent folder as keys.js:\nexports.key='';\nexports.secret='';");
8
- process.exit(1);
11
+ if(!fs.existsSync(keyFile)) {
12
+ const key = prompt("Enter your API key: ");
13
+ const secret = prompt('Enter your API secret: ');
14
+ fs.writeFileSync(keyFile,key+' '+secret);
9
15
  }
10
- const my = require('../keys.js');
11
- const key = my.key; // API Key
12
- const secret = my.secret; // API Private Key
16
+
17
+ const myKeys = fs.readFileSync(keyFile,{encoding:'utf8', flag:'r'});
18
+ const [key,secret] = myKeys.split(' ');
13
19
  const KrakenClient = require('kraken-api');
14
20
  const kraken = new KrakenClient(key, secret);
15
21
  function sleep(ms) {
@@ -656,7 +662,6 @@ async function marginReport(show = true) {
656
662
  return brief;
657
663
  }
658
664
 
659
- const prompt = require('prompt-sync')({sigint: true});
660
665
  let stopNow = false,
661
666
  portfolio = [],
662
667
  histi = Math.floor(Date.now() / 1000),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kraken-grid",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Bot repeatedly buys & sells on kraken from a conditional close order.",
5
5
  "main": "index.js",
6
6
  "bin": "./index.js",