kraken-grid 1.0.4 → 1.0.5

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 (2) hide show
  1. package/index.js +12 -12
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -74,7 +74,7 @@ async function order(buysell, xmrbtc, price, amt, lev='none', uref=0, closeO=nul
74
74
  if( cO>0 && (buysell == 'buy' ? cO <= price : cO >= price) )
75
75
  throw 'Close price, '+cO+' is on the wrong side of '+buysell+' at '+price+'!';
76
76
  ret = ['AddOrder',
77
- { pair: xmrbtc+'USD', // Just call it 'pair'! #USD Refactor
77
+ { pair: xmrbtc+'USD', // Just call it 'pair' so it already has the USD at the end! #USD Refactor
78
78
  userref: uref,
79
79
  type: buysell,
80
80
  ordertype: 'limit',
@@ -223,7 +223,7 @@ async function listOpens(portfolio = null, isFresh=false) {
223
223
  volume: Number(oo.vol),
224
224
  type: od.type,
225
225
  sym: /USD/.test(od.pair) ? /^([A-Z]+)USD/.exec(od.pair)[1] : od.pair,
226
- // Just call it 'pair'! #USD Refactor
226
+ // Just call it 'pair' instad of sym and use od.pair! #USD Refactor
227
227
  ctype: ct,
228
228
  lev: od.leverage,
229
229
  ids: [o],
@@ -258,7 +258,7 @@ async function listOpens(portfolio = null, isFresh=false) {
258
258
  if(portfolio && isFresh && od.leverage == "none") {
259
259
  if(od.type == "buy") {
260
260
  if(/USD$/.test(od.pair)) { // Deplete our cash
261
- portfolio['ZUSD'][2] -= od.price*opens[o].vol;
261
+ portfolio['ZUSD'][2] -= od.price*opens[o].vol; // #USD Refactor and basePair()
262
262
  } else if(/XBT$/.test(od.pair)) { // Deplete our BTC
263
263
  portfolio['XBT'][0] -= od.price*opens[o].vol;
264
264
  }
@@ -286,7 +286,7 @@ async function listOpens(portfolio = null, isFresh=false) {
286
286
  }
287
287
  gp[c.ctype] = c.open;
288
288
  gp[c.type] = c.price;
289
- [,sym,price] = /([A-Z]+)USD([0-9.]+)/.exec(comp); //#USD Refactor
289
+ [,sym,price] = /([A-Z]+)USD([0-9.]+)/.exec(comp); //remove USD #USD Refactor
290
290
  if(verbose) console.log("Checking: " + c.type + ' '
291
291
  + sym + ' ' + price + ' ' + Math.round(c.total*10000)/10000
292
292
  + (c.open ? ' to '+c.ctype+'-close @'+c.open : '') +' (' + c.userref + "):");
@@ -385,9 +385,9 @@ function getLev(portfolio,buysell,price,amt,xmrbtc,posP) {
385
385
  if(1*price > 1*portfolio[xmrbtc][1] && posP)
386
386
  return "Buying "+xmrbtc+" @ "+price+" isn't a limit order.";
387
387
  if(price*amt > 1*portfolio['ZUSD'][2]) { // #USD Refactor - This doesn't support leverage
388
- lev = '2'; // on non-USD pairs.
388
+ lev = '2'; // on non-USD pairs. Hunt ZUSD and add basePair(pair) to get base.
389
389
  } else {
390
- portfolio['ZUSD'][2] -= price*amt;
390
+ portfolio['ZUSD'][2] -= price*amt; // #USD Refactor and basePair()
391
391
  }
392
392
  } else {
393
393
  if(price*1 < 1*portfolio[xmrbtc][1] && posP) return "Selling "+xmrbtc+" @ "+price+" isn't a limit order.";
@@ -627,8 +627,8 @@ async function report(portfolio,showBalance=true) {
627
627
 
628
628
  let price;
629
629
  for( const p in bal.result) {
630
- let ts = p+'USD',
631
- tsz = p+'ZUSD',
630
+ let ts = p+'USD', // #USD Refactor and basePair()
631
+ tsz = p+'ZUSD', // #USD Refactor and basePair()
632
632
  sym = /^X/.test(p) ? p.substr(1) : p,
633
633
  amt = toDec(bal.result[p],4);
634
634
  if(ts in tik.result) price = tik.result[ts].c[0];
@@ -679,7 +679,6 @@ async function marginReport(show = true) {
679
679
 
680
680
  let stopNow = false,
681
681
  portfolio = [],
682
- histi = Math.floor(Date.now() / 1000),
683
682
  ts150 = 0,
684
683
  delay = 60,
685
684
  auto = 0,
@@ -715,8 +714,8 @@ async function runOnce(cmdList) {
715
714
  if(args[1]&&!isNaN(args[1])) delay = args[1];
716
715
  let counter = delay;
717
716
  auto = setInterval(async function() {
718
- if(0 == --counter && !auto_on_hold) {
719
- await report(portfolio,false);
717
+ if(0 == --counter) {
718
+ if(!auto_on_hold) await report(portfolio,false);
720
719
  counter = delay;
721
720
  }
722
721
  },1000);
@@ -734,7 +733,7 @@ async function runOnce(cmdList) {
734
733
  console.log("Verbose is "+(verbose ? 'on' : 'off'));
735
734
  } else if(args[0] == 'margin') {
736
735
  await marginReport();
737
- } else await handleArgs(portfolio, args, ++histi).then(console.log);
736
+ } else await handleArgs(portfolio, args, 0).then(console.log);
738
737
  } catch(err) {
739
738
  catcher(468,err);
740
739
  }
@@ -771,6 +770,7 @@ function catcher(line,err) {
771
770
  if(/ETIMEDOUT/.test(err.code)) return; // We can ignore timeout errors.
772
771
  console.log("Line "+line+";\n",err);
773
772
  clearInterval(auto);
773
+ auto = 0;
774
774
  }
775
775
 
776
776
  process.on('uncaughtException', function (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kraken-grid",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Bot repeatedly buys & sells on kraken from a conditional close order.",
5
5
  "main": "index.js",
6
6
  "bin": "./index.js",