Socket
Socket
Sign inDemoInstall

coinx

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

coinx - npm Package Compare versions

Comparing version 0.2.0 to 0.7.1

CHANGELOG.md

59

coinx-buy.js

@@ -12,10 +12,13 @@ 'use strict';

const Poloniex = require('./exchanges/poloniex');
const Liqui = require('./exchanges/liqui');
const Bittrex = require('./exchanges/bittrex');
const Bitfinex = require('./exchanges/bitfinex');
const Kraken = require('./exchanges/kraken');
const Poloniex = require('./lib/poloniex');
const Liqui = require('./lib/liqui');
const Bittrex = require('./lib/bittrex');
const Bitfinex = require('./lib/bitfinex');
const Kraken = require('./lib/kraken');
const cryptocompare = require('./lib/cryptocompare');
const coinxHome = path.join(homedir(), 'coinx');
const keyFilePath = path.join(coinxHome, 'coinx.json');
const coinListPath = path.join(coinxHome, 'coinList.json');

@@ -28,2 +31,10 @@ let configured = true;

let coins = {};
try {
coins = require(coinListPath);
} catch (e) {
console.error(chalk.red('Please run `coinx update` to get the latest list of coins.'));
process.exit(1);
}
program

@@ -154,3 +165,3 @@ .option('-$, --usd [amount]', 'Amount of US Dollars to spend.')

console.log(chalk.green(capitalize(result.market) + ' order number ' + result.orderNumber));
console.log(chalk.green('Bought ' + result.numCoinsBought + ' ' + symbol));
console.log(chalk.green('Bought ' + result.numCoinsBought + ' ' + symbol + ' at ' + result.rate + ' BTC per coin'));
console.log(chalk.green('Worth about $' + parseFloat(result.usdValue).toFixed(2) ));

@@ -163,2 +174,6 @@ } else {

}
})
.catch( e => {
console.error(chalk.red('An error occurred.'));
console.log(e);
});

@@ -169,3 +184,8 @@ });

function getCoinPriceInBTC(symbol) {
console.log(chalk.blue('Checking ' + symbol + ' on the markets...'));
if (coins[symbol]){
console.log(chalk.blue('Checking ' + coins[symbol].name + ' (' + symbol + ') on the markets...'));
} else {
console.log(chalk.blue('Checking ' + symbol + ' on the markets...'));
}
let coinPriceRequests = exchanges.map(exchange => {

@@ -191,24 +211,3 @@ return exchange.getPriceInBTC(symbol).catch(e => {

function getBTCPriceInUSD() {
let btcPriceRequests = exchanges.map(exchange => {
return exchange.getBTCinUSD();
});
return Promise
.all(btcPriceRequests)
.then(results => {
let priceResults = results.filter(result => {
return result.available;
});
if (!priceResults.length) {
console.log(chalk.red('Coin not found on any exchange.'));
process.exit(0);
}
let averageUSD = priceResults.reduce((sum, result) => {
return parseFloat(sum) + parseFloat(result.priceUSD);
}, 0.0) / priceResults.length;
return averageUSD;
});
return cryptocompare.price('BTC','USD');
}

@@ -218,4 +217,4 @@

console.log(chalk.red('Need to configure at least one exchange.'));
console.log(chalk.red('Run \'coinx configure [name of exchange]\''));
console.log(chalk.red('Run \'coinx config [name of exchange]\''));
process.exit(1);
}

@@ -11,13 +11,24 @@ 'use strict';

const columnify = require('columnify');
const _ = require('lodash');
const Poloniex = require('./exchanges/poloniex');
const Liqui = require('./exchanges/liqui');
const Bittrex = require('./exchanges/bittrex');
const Bitfinex = require('./exchanges/bitfinex');
const Kraken = require('./exchanges/kraken');
const Poloniex = require('./lib/poloniex');
const Liqui = require('./lib/liqui');
const Bittrex = require('./lib/bittrex');
const Bitfinex = require('./lib/bitfinex');
const Kraken = require('./lib/kraken');
const cryptocompare = require('./lib/cryptocompare');
const coinxHome = path.join(homedir(), 'coinx');
const keyFilePath = path.join(coinxHome, 'coinx.json');
const coinListPath = path.join(coinxHome, 'coinList.json');
let configured = true;
let coinLookup = {};
try {
coinLookup = require(coinListPath);
} catch (e) {
console.error(chalk.red('Please run `coinx update` to get the latest list of coins.'));
process.exit(1);
}
if (!fs.existsSync(keyFilePath)) showNotConfigured();

@@ -32,2 +43,3 @@

.option('-n, --numerically', 'Sort the balance list by the number of coins, descending.')
.option('-v, --value', 'Sort the balance list by the value of each coin in US dollars, descending.')
.option('-c, --coin [symbol]', 'Only get balances for this coin.')

@@ -46,4 +58,4 @@ .parse(process.argv);

if (program.exchange){
if (validExchanges.indexOf(program.exchange) == -1){
if (program.exchange) {
if (validExchanges.indexOf(program.exchange) == -1) {
console.log(chalk.red('Unknown exchange'));

@@ -70,4 +82,4 @@ process.exit(1);

let requests = exchanges.map(exchange => {
return exchange.getBalances().then( balance => {
if (!balance.available){
return exchange.getBalances().then(balance => {
if (!balance.available) {
console.log(chalk.red(capitalize(balance.market) + ' returned an error. Is your API key and secret correct?'));

@@ -78,20 +90,44 @@ }

});
let balances;
Promise
.all(requests)
.then(balances => {
.then(results => {
let fsymbols = [];
balances = results;
results.forEach(exchange => {
if (exchange.available) {
Object.keys(exchange.funds).forEach(coin => {
fsymbols.push(coin);
});
}
});
fsymbols = _.uniq(fsymbols);
return cryptocompare.priceMulti(_.uniq(fsymbols), 'USD');
})
.then(prices => {
balances.forEach(balance => {
if (balance.available){
if (balance.available) {
let funds = balance.funds;
let coins = Object.keys( funds ).map( coin => {
let coins = Object.keys(funds).map(coin => {
let name = (coinLookup[coin]) ? coinLookup[coin].name : '';
return {
coin: coin,
count: funds[coin]
name: name,
symbol: coin,
count: funds[coin],
valueUSD: funds[coin] * prices[coin]
}
});
if (program.coin){
coins = coins.filter( coin => {
return coin.coin.toLowerCase() == program.coin.toLowerCase();
if (program.coin) {
coins = coins.filter(coin => {
return coin.symbol.toLowerCase() == program.coin.toLowerCase();
});
if (coins.length == 0){
if (coins.length == 0) {
console.log(chalk.red('Coin not found on this exchange'));

@@ -101,5 +137,5 @@ process.exit(0);

}
if (program.alphabetically){
coins.sort( (a, b) => {
if (a.coin < b.coin){
if (program.alphabetically) {
coins.sort((a, b) => {
if (a.name < b.name) {
return -1;

@@ -109,7 +145,6 @@ } else {

}
})
}
if (program.numerically){
coins.sort( (a, b) => {
if (a.count > b.count){
});
} else if (program.numerically) {
coins.sort((a, b) => {
if (a.count > b.count) {
return -1;

@@ -119,8 +154,26 @@ } else {

}
})
});
} else {
coins.sort((a, b) => {
if (parseFloat(a.valueUSD) > parseFloat(b.valueUSD)) {
return -1;
} else {
return 1;
}
});
}
let total = {
name: 'Total',
valueUSD: 0
}
coins.forEach( coin => {
total.valueUSD += coin.valueUSD;
});
coins.push(total);
let columns = columnify(coins, {
columns: ['coin', 'count'],
columns: ['name', 'symbol', 'count', 'valueUSD'],
config: {
coin: {
name: {
headingTransform: function(heading) {

@@ -130,2 +183,7 @@ return capitalize(heading);

},
symbol: {
headingTransform: function(heading) {
return capitalize(heading);
}
},
count: {

@@ -136,5 +194,14 @@ headingTransform: function(heading) {

dataTransform: function(data) {
return parseFloat(data).toFixed(8);
return (data) ? parseFloat(data).toFixed(8) : '';
},
align: 'right'
},
valueUSD: {
headingTransform: function() {
return 'Value USD';
},
dataTransform: function(data) {
return '$' + parseFloat(data).toFixed(2);
},
align: 'right'
}

@@ -145,3 +212,2 @@ }

console.log(columns);
console.log('');
}

@@ -153,4 +219,4 @@ });

console.log(chalk.red('Need to configure at least one exchange.'));
console.log(chalk.red('Run \'coinx configure [name of exchange]\''));
console.log(chalk.red('Run \'coinx config [name of exchange]\''));
process.exit(1);
}

@@ -7,9 +7,24 @@ 'use strict';

const columnify = require('columnify');
const path = require('path');
const homedir = require('homedir');
const Poloniex = require('./exchanges/poloniex');
const Liqui = require('./exchanges/liqui');
const Bittrex = require('./exchanges/bittrex');
const Bitfinex = require('./exchanges/bitfinex');
const Kraken = require('./exchanges/kraken');
const Poloniex = require('./lib/poloniex');
const Liqui = require('./lib/liqui');
const Bittrex = require('./lib/bittrex');
const Bitfinex = require('./lib/bitfinex');
const Kraken = require('./lib/kraken');
const cryptocompare = require('./lib/cryptocompare');
const coinxHome = path.join(homedir(), 'coinx');
const coinListPath = path.join(coinxHome, 'coinList.json');
let coins = {};
try {
coins = require(coinListPath);
} catch (e) {
console.error(chalk.red('Please run `coinx update` to get the latest list of coins.'));
process.exit(1);
}
let exchanges = [

@@ -34,14 +49,21 @@ new Poloniex(),

console.log(chalk.blue('Getting prices for ' + symbol + '...'));
if (coins[symbol]){
console.log(chalk.blue('Getting prices for ' + coins[symbol].name + ' (' + symbol + ')...'));
} else {
console.log(chalk.blue('Getting prices for ' + symbol + '...'));
}
let requests = exchanges.map( exchange => {
return exchange.getBTCinUSD()
});
if (symbol !== 'BTC'){
let requests = [];
if (symbol == 'BTC'){
requests = exchanges.map( exchange => {
return exchange.getBTCinUSD()
});
} else {
requests = [
cryptocompare.price('BTC','USD')
];
let priceInBTCRequests = exchanges.map( exchange => {
return exchange.getPriceInBTC(symbol).then( result => {
//console.log(result);
return result;
});
return exchange.getPriceInBTC(symbol);
});

@@ -116,11 +138,5 @@ requests = requests.concat(priceInBTCRequests);

function processCoin(results){
let btcPrices = results.slice(0, exchanges.length);
let btcPrice = btcPrices.map(result => {
return result.priceUSD;
}).reduce((sum, value) => {
return sum + value;
}, 0) / exchanges.length;
let btcPrice = results.shift();
let priceResults = results.slice(exchanges.length).filter(result => {
let priceResults = results.filter(result => {
return result.available && result.priceBTC;

@@ -127,0 +143,0 @@ }).map(result => {

{
"name": "coinx",
"version": "0.2.0",
"version": "0.7.1",
"description": "Buy and sell crypto-currencies from the command line.",
"main": "index.js",
"main": "coinx.js",
"bin": {
"coinx": "./index.js"
"coinx": "./coinx.js"
},

@@ -30,4 +30,6 @@ "repository": {

"kraken-api": "^0.1.7",
"lodash": "^4.17.4",
"mkdirp": "^0.5.1",
"node.bittrex.api": "^0.3.2",
"node.liqui.io": "^1.0.0",
"poloniex.js": "0.0.7",

@@ -37,2 +39,2 @@ "request": "^2.81.0",

}
}
}

@@ -8,2 +8,6 @@ # coinx

## Upgrade to the latest version
Coinx is currently at version 0.7.1. You can upgrade with npm:
`npm update -g coinx`
## Supported Exchanges

@@ -23,2 +27,5 @@ Currently: Kraken, Poloniex, Bitfinex, Liqui, Bittrex.

## Update
Use `coinx update` to update coinx with the latest list of coins from [coinmarketcap.com](https://coinmaketcap.com).
## Coin Price

@@ -43,11 +50,11 @@ Get the price of any crypto-currency by using the coin's symbol. Bitcoin is shown in US Dollars, all other coins are shown in BTC and in US Dollars.

$ coinx price eth
Getting prices for ETH...
Getting prices for Ethereum (ETH)...
Exchange Price in BTC Price in USD
Bittrex 0.11339041 $275.69
Poloniex 0.11353471 $276.04
Bitfinex 0.11360000 $276.20
Kraken 0.11367900 $276.39
Liqui 0.11460000 $278.63
Liqui 0.08789270 $208.30
Poloniex 0.08809500 $208.78
Kraken 0.08811500 $208.82
Bitfinex 0.08821900 $209.07
Bittrex 0.08840483 $209.51
Average 0.11376082 $276.59
Average 0.08814531 $208.89
```

@@ -58,8 +65,8 @@

$ coinx price sc
Getting prices for SC...
Getting prices for Siacoin (SC)...
Exchange Price in BTC Price in USD
Bittrex 0.00000564 $0.01
Poloniex 0.00000566 $0.01
Bittrex 0.00000335 $0.01
Poloniex 0.00000333 $0.01
Average 0.00000565 $0.01
Average 0.00000334 $0.01
```

@@ -73,15 +80,10 @@

Getting balances...
Poloniex
Coin Count
ARDR 18.48537732
BCN 2.85258566
Name Symbol Count Value USD
Bitcoin BTC 0.03227520 $76.51
Siacoin SC 2465.11765598 $19.46
NEM XEM 151.10258763 $18.43
Dash DASH 0.09817530 $16.94
Liqui
Coin Count
BTC 0.00016854
Bittrex
Coin Count
1ST 10.10023974
...
```

@@ -98,10 +100,13 @@ Options:

```
For example, to check balances only on Poloniex:
For example, to check balances only on Liqui:
```bash
$ coinx funds -e poloniex
Getting balances on Poloniex...
Poloniex
Coin Count
ARDR 6.48537732
BCN 2.85258566
Getting balances on Liqui...
Liqui
Name Symbol Count Value USD
Bitcoin BTC 0.02564645 $30.77
Ethereum ETH 0.08706164 $18.04
Augur REP 0.66674308 $13.59
MobileGo MGO 17.23038495 $13.33
...
```

@@ -113,16 +118,15 @@ Or, to check how many BTC you have on all the exchanges:

Poloniex
Coin Count
BTC 0.00076948
Name Symbol Count Value USD
Bitcoin BTC 0.00227520 $6.53
Total $6.53
Kraken
Name Symbol Count Value USD
Bitcoin BTC 0.00237879 $6.40
Total $6.40
Liqui
Coin Count
BTC 0.00086854
Name Symbol Count Value USD
Bitcoin BTC 0.00256464 $6.81
Total $6.81
Bittrex
Coin Count
BTC 0.00057939
Bitfinex
Coin Count
BTC 0.00098090
```

@@ -139,3 +143,3 @@ ## Buy Coins

$ coinx buy ans -$ 2
Checking ANS on the markets...
Checking AntShares (ANS) on the markets...
Best price found on Bittrex at $8.14

@@ -155,3 +159,3 @@

$ coinx buy eth -e liqui -$ 2
Checking ETH on the markets...
Checking Ethereum (ETH) on the markets...
Best price found on Liqui at $278.70

@@ -158,0 +162,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc