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 +1 -0
- package/index.js +6 -0
- package/index.test.js +3 -0
- package/package.json +17 -0
- package/src/configs/db.js +19 -0
- package/src/configs/index.js +5 -0
- package/src/helpers/crawlAndSave.js +18 -0
- package/src/helpers/index.js +7 -0
- package/src/helpers/makeCoingeckoCoinOperations.js +24 -0
- package/src/index.js +18 -0
- package/src/models/coingeckoCoin.js +20 -0
package/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Get Coingecko Coin Id
|
package/index.js
ADDED
package/index.test.js
ADDED
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,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,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
|