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. 13147
      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) [![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) [![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 ## Install
@ -22,12 +22,12 @@ const coins = require('coinlist');
// coins is an array of coin objects: // coins is an array of coin objects:
[ [
{ {
id: 1, id: 'bitcoin',
symbol: 'BTC', symbol: 'BTC',
name: 'Bitcoin' name: 'Bitcoin'
}, },
{ {
id: 2, id: 'litecoin',
symbol: 'LTC', symbol: 'LTC',
name: 'Litecoin' name: 'Litecoin'
}, },
@ -86,7 +86,7 @@ A single coin property to return instead of the entire coin object.
Valid properties are: Valid properties are:
- `id` The CoinMarketCap API id. - `id` The CoinGecko API id.
- `symbol` The ticker symbol. - `symbol` The ticker symbol.
- `name` The readable name. - `name` The readable name.
@ -94,9 +94,8 @@ Valid properties are:
``` ```
$ yarn update $ yarn update
Fetching latest currencies from the coinmarketcap.com API... Fetching latest currencies from the coingecko.com API...
Written 1633 coins to src/coins.json Written 2306 coins to src/coins.json
✨ Done in 0.85s.
``` ```
## Contributing ## Contributing

13147
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 => { test('coins.get searches symbols', t => {
const expectedBtc = { const expectedBtc = {
id: 1, id: 'bitcoin',
symbol: 'BTC', symbol: 'BTC',
name: 'Bitcoin' name: 'Bitcoin'
}; };

16
update/index.js

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

Loading…
Cancel
Save