updating price update logic
This commit is contained in:
parent
df8cb9c189
commit
794ba968c6
13
index.js
13
index.js
@ -168,22 +168,15 @@ function loadHistoricToDb() {
|
|||||||
inr: parseFloat(parseFloat(close2).toFixed(2)),
|
inr: parseFloat(parseFloat(close2).toFixed(2)),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// update many
|
||||||
|
await PriceHistory.deleteMany({ asset: 'btc' });
|
||||||
await PriceHistory.insertMany(priceHistoryData);
|
await PriceHistory.insertMany(priceHistoryData);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// run loadHistoricToDb() only once when the server starts and no data is present in the database
|
|
||||||
PriceHistory.countDocuments()
|
|
||||||
.then((count) => {
|
|
||||||
if (count === 0) {
|
|
||||||
loadHistoricToDb();
|
loadHistoricToDb();
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
})
|
|
||||||
|
|
||||||
app.get("/price-history", async (req, res) => {
|
app.get("/price-history", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
@ -240,7 +233,7 @@ app.post("/price-history", async (req, res) => {
|
|||||||
app.listen(PORT, HOST, () => {
|
app.listen(PORT, HOST, () => {
|
||||||
console.log(`Listening on ${HOST}:${PORT}`);
|
console.log(`Listening on ${HOST}:${PORT}`);
|
||||||
});
|
});
|
||||||
cron.schedule('0 12 * * *', async () => {
|
cron.schedule('0 */4 * * *', async () => {
|
||||||
try {
|
try {
|
||||||
// will return a csv file
|
// will return a csv file
|
||||||
const [usd, inr] = await Promise.all([
|
const [usd, inr] = await Promise.all([
|
||||||
|
|||||||
2
index.min.js
vendored
2
index.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user