Skip to content

Commit

Permalink
feat(*): save output to file
Browse files Browse the repository at this point in the history
Save output to file
  • Loading branch information
benmarten committed Dec 28, 2017
1 parent a3e1105 commit 0de2b1f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion settings.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@
"targetValueUsd": 50000,
"rebalanceDeltaPct": 1.0,
"minValueBtc": 0.0001
}
},
"outputFile": false
}
9 changes: 9 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Portfolio from './model/Portfolio'
import Coinmarket from './model/Coinmarket'
import Coin from './model/Coin'
import Utils from './Utils'
import fs from 'fs';

const settings = require('../settings.json')

Expand Down Expand Up @@ -42,6 +43,14 @@ async function refreshPortfolio() {

Portfolio.removeCoin('USDT')

if (settings.outputFile) {
fs.writeFile(settings.outputFile, Portfolio.getJson(), 'utf8', function(err){
if (err) throw err;
console.log(`Saved data to ${settings.outputFile}...`)
});
}


console.log(Portfolio.getOutput())
}
catch
Expand Down
4 changes: 4 additions & 0 deletions src/model/Portfolio.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,8 @@ export default class Portfolio {
}
return table(data, config)
}

static getJson() {
return JSON.stringify(portfolio, null, 2);
}
}

0 comments on commit 0de2b1f

Please sign in to comment.