Files
dataminer/bondfetch.js
2020-05-14 12:16:06 +02:00

44 lines
1.3 KiB
JavaScript

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 || !tgInfo.infoChat) {
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.error(e);
}
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();