Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 347a60a
Showing
7 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
#! /usr/bin/env node | ||
|
||
const each = require('foreach'); | ||
const request = require('request'); | ||
const chalk = require('chalk'); | ||
const Table = require('cli-table'); | ||
const jsonfile = require('jsonfile'); | ||
const figlet = require('figlet'); | ||
const file = 'portfolio.json'; | ||
const portfolio = jsonfile.readFileSync(file); | ||
|
||
figlet('Crypto Portfolio', function(err, data) { | ||
if (err) { | ||
console.log('Something went wrong...'); | ||
console.dir(err); | ||
return; | ||
} | ||
console.log(data) | ||
}); | ||
|
||
request('https://api.coinmarketcap.com/v1/ticker/?limit=100', function (error, response, body) { | ||
var data = JSON.parse(body); | ||
var table = new Table({ head: [ | ||
chalk.blue('Rank'), | ||
chalk.blue('Coin'), | ||
chalk.blue('USD Price'), | ||
chalk.blue('Coins Owned'), | ||
chalk.blue('Net Worth'), | ||
chalk.blue('24 Hour Volume'), | ||
chalk.blue('Market Cap'), | ||
chalk.blue('1 Hour'), | ||
chalk.blue('24 Hours'), | ||
chalk.blue('7 Days'), | ||
chalk.blue('Last Updated'), | ||
] }); | ||
var currSym = '$'; | ||
each(data, function (value, key, array) { | ||
if(portfolio.hasOwnProperty(value.id)) { | ||
table.push([ | ||
chalk.blue(value.rank), | ||
chalk.green(value.id), | ||
chalk.green(currSym + addCommas(value.price_usd)), | ||
chalk.green(addCommas(portfolio[value.id])), | ||
chalk.green(currSym + addCommas(Number(Math.round(value.price_usd * portfolio[value.id])))), | ||
chalk.green(currSym + addCommas(addZeroes(value['24h_volume_usd']))), | ||
chalk.green(currSym + addCommas(addZeroes(value.market_cap_usd))), | ||
chalk.green(`${value.percent_change_1h} %`), | ||
chalk.green(`${value.percent_change_24h} %`), | ||
chalk.green(`${value.percent_change_7d} %`), | ||
chalk.green(timeSince(new Date(value.last_updated * 1000)) + ' ago'), | ||
]); | ||
} | ||
}); | ||
console.log(table.toString()); | ||
}); | ||
|
||
/** | ||
* Add zero if number only has one zero | ||
* Example: $666,888.0 >> $666,888.00 | ||
* Fixes coinmarketcap API issues for market caps | ||
* https://stackoverflow.com/a/24039448 | ||
*/ | ||
|
||
function addZeroes( num ) { | ||
var value = Number(num); | ||
var res = num.split("."); | ||
if(num.indexOf('.') === -1) { | ||
value = value.toFixed(2); | ||
num = value.toString(); | ||
} else if (res[1].length < 3) { | ||
value = value.toFixed(2); | ||
num = value.toString(); | ||
} | ||
return num | ||
} | ||
|
||
/** | ||
* Comma seperate big numbers | ||
* Took multiple answers | ||
* from https://stackoverflow.com/questions/1990512/add-comma-to-numbers-every-three-digits/ | ||
* This work with small coins like dogecoin and does not comma seperate AFTER decimals | ||
*/ | ||
|
||
function addCommas(nStr){ | ||
nStr += ''; | ||
x = nStr.split('.'); | ||
x1 = x[0]; | ||
x2 = x.length > 1 ? '.' + x[1] : ''; | ||
var rgx = /(\d+)(\d{3})/; | ||
while (rgx.test(x1)) { | ||
x1 = x1.replace(rgx, '$1' + ',' + '$2'); | ||
} | ||
return x1 + x2; | ||
}; | ||
|
||
|
||
/** | ||
* Pretty time format X ago function | ||
* https://stackoverflow.com/a/3177838 | ||
*/ | ||
|
||
function timeSince(date) { | ||
var seconds = Math.floor((new Date() - date) / 1000); | ||
var interval = Math.floor(seconds / 31536000); | ||
if (interval > 1) { | ||
return interval + " years"; | ||
} | ||
interval = Math.floor(seconds / 2592000); | ||
if (interval > 1) { | ||
return interval + " months"; | ||
} | ||
interval = Math.floor(seconds / 86400); | ||
if (interval > 1) { | ||
return interval + " days"; | ||
} | ||
interval = Math.floor(seconds / 3600); | ||
if (interval > 1) { | ||
return interval + " hours"; | ||
} | ||
interval = Math.floor(seconds / 60); | ||
if (interval > 1) { | ||
return interval + " minutes"; | ||
} | ||
return Math.floor(seconds) + " seconds"; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2017 christ0ph3r | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "cryptocurrency-cli", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "node index.js", | ||
"crypto-cli": "node index.js" | ||
}, | ||
"author": "n053", | ||
"license": "MIT", | ||
"dependencies": { | ||
"chalk": "^2.2.0", | ||
"cli-table": "^0.3.1", | ||
"figlet": "^1.2.0", | ||
"foreach": "^2.0.5", | ||
"jsonfile": "^4.0.0", | ||
"request": "^2.83.0" | ||
}, | ||
"bin": { | ||
"crypto-cli": "index.js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"bitcoin": ".002", | ||
"litecoin": "1", | ||
"ripple": "100", | ||
"bitcoin-cash": ".002", | ||
"nem": "66", | ||
"neo": ".3", | ||
"ethereum": ".095", | ||
"dogecoin": "10000" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Cryptocurrency CLI | ||
|
||
Cryptocurrency CLI lets you monitor cryptocurrencies in your portfolio and track your earnings through the command line. It uses the coinmarketcap.com API to fetch crypto data. | ||
|
||
![Cryptocurrency CLI](https://i.imgur.com/QEJOIle.png) | ||
|
||
## Features | ||
|
||
### General | ||
1. Command Line Interface | ||
1. Supports the top 100 coins based on market cap | ||
1. Track your portfolio holdings | ||
|
||
### Crypto Table Data | ||
1. Coin Rank | ||
1. Price | ||
1. Coins Owned | ||
1. Net Worth | ||
1. 24 Hour Volume | ||
1. Market Cap | ||
1. % Change 1 Hour | ||
1. % Change 1 Day | ||
1. % Change 1 Week | ||
1. Last Updated | ||
|
||
## Installation Instructions | ||
|
||
|
||
1. Git Clone the repo | ||
|
||
``` | ||
git clone https://github.com/christ0ph3r/cryptocurrency-cli/ | ||
``` | ||
|
||
2. Enter the repository | ||
|
||
``` | ||
cd cryptocurrency-cli && npm install | ||
``` | ||
|
||
3. Edit portfolio.json | ||
|
||
```json | ||
{ | ||
"bitcoin": ".002", | ||
"litecoin": "1", | ||
"ethereum": ".095", | ||
"dogecoin": "10000" | ||
} | ||
``` | ||
|
||
4. Run | ||
|
||
``` | ||
crypto-cli | ||
``` | ||
|
||
## Like my work? Donate some coin! | ||
|
||
|
||
| Coin | Address | | ||
| -------- |:------------------------------------------:| | ||
| Bitcoin | 1LFTccjYHbiVekdm8XYC1ucNqdGsAC3frc | | ||
| Ethereum | 0x071Fe2Bb50430A3f6af398A410a78B67e1A783AE | | ||
| Litecoin | Lh9eV96yhTyrkv2VkWG7RZvas9TzFuYZbR | | ||
|