fetch bonds every seven minutes and send info
This commit is contained in:
43
bondfetch.js
Normal file
43
bondfetch.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const fetch = require("node-fetch");
|
||||
var mysql = require('mysql');
|
||||
const TelegramBot = require('node-telegram-bot-api');
|
||||
|
||||
const simCo = require('./simco-credentials');
|
||||
const tgInfo = require('./telegram-credentials');
|
||||
if (!simCo.cookie || !tgInfo.token) {
|
||||
console.error("ERR: credentials not set.")
|
||||
return;
|
||||
}
|
||||
const tgBot = new TelegramBot(tgInfo.token, { polling: false });
|
||||
|
||||
const lowbonds = "https://www.simcompanies.com/api/bonds/rating/BB+-to-D";
|
||||
const highbonds = "https://www.simcompanies.com/api/bonds/rating/AAA-to-BBB-";
|
||||
|
||||
var knownBonds = [];
|
||||
|
||||
const bondFetchProcess = async (url) => {
|
||||
try {
|
||||
var BondData = await fetch(url, {
|
||||
headers: {
|
||||
Cookie: simCo.cookie
|
||||
}
|
||||
});
|
||||
var t1 = await BondData.json();
|
||||
} catch (e) {
|
||||
console.warn("errs")
|
||||
}
|
||||
for (let data in t1) {
|
||||
if (t1[data].interest > 0.7 && !knownBonds.includes(t1[data].id)) {
|
||||
knownBonds.push(t1[data].id);
|
||||
tgBot.sendMessage(tgInfo.infoChat, `Found ${t1[data].seller.rating} bond x${t1[data].amount} with ${t1[data].interest}% interest, issued by ${t1[data].seller.company}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const fetchBondData = async () => {
|
||||
await bondFetchProcess(lowbonds);
|
||||
await bondFetchProcess(highbonds);
|
||||
setTimeout(fetchBondData, 450000);
|
||||
}
|
||||
|
||||
fetchBondData();
|
||||
Reference in New Issue
Block a user