Browse Source

Switch to coingecko.com

Context: https://github.com/atomiclabs/hyperdex/issues/464
pull/10/head
Sindre Sorhus 6 years ago
parent
commit
cfeb655eff
  1. 13
      README.md
  2. 13149
      src/coins.json
  3. 2
      test/index.js
  4. 16
      update/index.js

13
README.md

@ -6,7 +6,7 @@
[![Coverage Status](https://coveralls.io/repos/github/lukechilds/coinlist/badge.svg?branch=master)](https://coveralls.io/github/lukechilds/coinlist?branch=master)
[![npm](https://img.shields.io/npm/v/coinlist.svg)](https://www.npmjs.com/package/coinlist)
List compiled from the coinmarketcap.com API. Importable as a raw JSON file or an array with helper methods.
List compiled from the [coingecko.com API](https://www.coingecko.com/api/docs/v3). Importable as a raw JSON file or an array with helper methods.
## Install
@ -22,12 +22,12 @@ const coins = require('coinlist');
// coins is an array of coin objects:
[
{
id: 1,
id: 'bitcoin',
symbol: 'BTC',
name: 'Bitcoin'
},
{
id: 2,
id: 'litecoin',
symbol: 'LTC',
name: 'Litecoin'
},
@ -86,7 +86,7 @@ A single coin property to return instead of the entire coin object.
Valid properties are:
- `id` The CoinMarketCap API id.
- `id` The CoinGecko API id.
- `symbol` The ticker symbol.
- `name` The readable name.
@ -94,9 +94,8 @@ Valid properties are:
```
$ yarn update
Fetching latest currencies from the coinmarketcap.com API...
Written 1633 coins to src/coins.json
✨ Done in 0.85s.
Fetching latest currencies from the coingecko.com API...
Written 2306 coins to src/coins.json
```
## Contributing

13149
src/coins.json

File diff suppressed because it is too large

2
test/index.js

@ -18,7 +18,7 @@ test('coin object has expected properties', t => {
test('coins.get searches symbols', t => {
const expectedBtc = {
id: 1,
id: 'bitcoin',
symbol: 'BTC',
name: 'Bitcoin'
};

16
update/index.js

@ -6,13 +6,15 @@ const writeJsonFile = require('write-json-file');
const jsonFile = 'src/coins.json';
(async () => {
console.log(`Fetching latest currencies from the coinmarketcap.com API...`);
const response = await got('https://api.coinmarketcap.com/v2/listings/', { json: true });
const coins = response.body.data.map(coin => {
const { id, symbol, name } = coin;
return { id, symbol, name };
});
console.log(`Fetching latest currencies from the coingecko.com API...`);
const response = await got('https://api.coingecko.com/api/v3/coins/list', { json: true });
const coins = response.body
.map(coin => ({
id: coin.id,
symbol: coin.symbol.toUpperCase(),
name: coin.name
}))
.sort((a, b) => a.id.localeCompare(b.id));
await writeJsonFile(jsonFile, coins);
console.log(`Written ${coins.length} coins to ${jsonFile}`);
})();

Loading…
Cancel
Save