coins-coingecko 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of coins-coingecko might be problematic. Click here for more details.

package/README.md ADDED
@@ -0,0 +1 @@
1
+ # Get Coingecko Coin Id
package/index.js ADDED
@@ -0,0 +1,6 @@
1
+ const { getCoingeckoCoin, getCoingeckoCoinId } = require('./src')
2
+
3
+ module.exports = {
4
+ getCoingeckoCoin,
5
+ getCoingeckoCoinId
6
+ }
package/index.test.js ADDED
@@ -0,0 +1,3 @@
1
+ const { getCoingeckoCoinId } = require('./src')
2
+
3
+ getCoingeckoCoinId('eth').then(console.log)
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "coins-coingecko",
3
+ "version": "1.0.1",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "start": "node src/index.js",
8
+ "test": "node index.test.js"
9
+ },
10
+ "keywords": [],
11
+ "author": "",
12
+ "license": "ISC",
13
+ "dependencies": {
14
+ "axios": "^0.26.1",
15
+ "mongoose": "^6.2.10"
16
+ }
17
+ }
@@ -0,0 +1,19 @@
1
+ const mongoose = require("mongoose");
2
+
3
+ const username = "chinhbc";
4
+ const password = "access.0987";
5
+ const mongodb_url = `mongodb+srv://${username}:${password}@coinscoingecko.ig5oa.mongodb.net/crawled`;
6
+
7
+ const connect = () => {
8
+ mongoose
9
+ .connect(mongodb_url, {
10
+ useNewUrlParser: true,
11
+ useUnifiedTopology: true,
12
+ })
13
+ .then(() => {})
14
+ .catch((error) => console.error(`Crawled Failed with: ${error}`));
15
+ };
16
+
17
+ module.exports = {
18
+ connect,
19
+ };
@@ -0,0 +1,5 @@
1
+ const db = require('./db')
2
+
3
+ module.exports = {
4
+ db
5
+ }
@@ -0,0 +1,18 @@
1
+ const axios = require("axios");
2
+ const { db } = require("../configs");
3
+ const CoingeckoCoin = require("../models/coingeckoCoin")
4
+
5
+ db.connect();
6
+
7
+ const { makeCoingeckoCoinOperations } = require("./makeCoingeckoCoinOperations");
8
+
9
+ const COINGECKO_API = "https://api.coingecko.com/api/v3";
10
+
11
+ const crawlAndSave = async () => {
12
+ let endpoint = `${COINGECKO_API}/coins/list`;
13
+ const { data } = await axios.get(endpoint);
14
+ const operations = await makeCoingeckoCoinOperations(data);
15
+ await CoingeckoCoin.bulkWrite(operations)
16
+ };
17
+
18
+ module.exports = { crawlAndSave };
@@ -0,0 +1,7 @@
1
+ const { crawlAndSave } = require('./crawlAndSave')
2
+ const { makeCoingeckoCoinOperations } = require('./makeCoingeckoCoinOperations')
3
+
4
+ module.exports = {
5
+ makeCoingeckoCoinOperations,
6
+ crawlAndSave
7
+ }
@@ -0,0 +1,24 @@
1
+ const CoingeckoCoin = require("../models/coingeckoCoin");
2
+
3
+ const makeCoingeckoCoinOperations = async (coins) => {
4
+ const operations = [];
5
+ for (let coin of coins) {
6
+ let instance = await CoingeckoCoin.findOne({ symbol: coin.symbol });
7
+ if (!instance) {
8
+ operations.push({
9
+ insertOne: {
10
+ document: {
11
+ coingecko_id: coin.id,
12
+ symbol: coin.symbol,
13
+ name: coin.name,
14
+ },
15
+ },
16
+ });
17
+ }
18
+ }
19
+ return operations;
20
+ };
21
+
22
+ module.exports = {
23
+ makeCoingeckoCoinOperations,
24
+ };
package/src/index.js ADDED
@@ -0,0 +1,18 @@
1
+ const CoingeckoCoin = require('./models/coingeckoCoin')
2
+ const { db } = require('./configs')
3
+
4
+ db.connect()
5
+
6
+ module.exports.getCoingeckoCoinId = async (symbol) => {
7
+ let instance = await CoingeckoCoin.findOne({ symbol })
8
+ return instance.coingecko_id
9
+ }
10
+
11
+ module.exports.getCoingeckoCoin = async (symbol) => {
12
+ let {coingecko_id, name} = await CoingeckoCoin.findOne({ symbol });
13
+ return {
14
+ id: coingecko_id,
15
+ symbol,
16
+ name
17
+ };
18
+ }
@@ -0,0 +1,20 @@
1
+ const mongoose = require('mongoose')
2
+
3
+ const CoingeckoCoinSchema = new mongoose.Schema({
4
+ coingecko_id: {
5
+ type: String,
6
+ index: true,
7
+ },
8
+ symbol: {
9
+ type: String,
10
+ index: true,
11
+ },
12
+ name: {
13
+ type: String,
14
+ index: true,
15
+ },
16
+ });
17
+
18
+ const CoingeckoCoin = mongoose.model("CoingeckoCoin", CoingeckoCoinSchema, 'coingecko_coins');
19
+
20
+ module.exports = CoingeckoCoin