b3_insigths
Version:
A brazillian stock exchange CLI
74 lines • 2.52 kB
JavaScript
import inquirer from "inquirer";
import figlet from "figlet";
import chalk from "chalk";
import ora from "ora";
import VariableIncomeScraper from "./scrapers/VariableIncomeScraper.js";
import IpcaScraper from "./scrapers/IpcaScraper.js";
import SelicScraper from "./scrapers/SelicScraper.js";
const loadingSpinner = ora("Carregando...");
console.log(chalk.yellow(figlet.textSync("B3 Insigths", { horizontalLayout: "full", font: "Roman" })));
processDefaultQuestion();
async function processDefaultQuestion() {
const answers = await inquirer.prompt([
{
name: "choice",
type: "list",
message: chalk.yellow("O que você deseja consultar?"),
choices: [
"Ação",
"FII",
"Benchmark"
]
}
]);
const { choice } = answers;
if (["Ação", "FII"].includes(choice)) {
await LogVariableIncomeValue(choice);
}
else if (choice === "Benchmark") {
loadingSpinner.start();
await LogBenchmarkValues();
}
}
async function LogVariableIncomeValue(choice) {
const type = choice === "Ação" ? "stock" : "reit";
const name = await getVariableIncomeNameFromUserInput();
const scraper = new VariableIncomeScraper(type);
const price = await scraper.getValue(name);
loadingSpinner.stop();
console.log(chalk.green(price));
}
async function LogBenchmarkValues() {
const indexScraper = new VariableIncomeScraper("index");
const ipcaScraper = new IpcaScraper();
const selicScraper = new SelicScraper();
const [ifixValue, ibovespaValue, ipcaValue, selicValue] = await Promise.all([
indexScraper.getValue("ifix"),
indexScraper.getValue("ibovespa"),
ipcaScraper.getValue(),
selicScraper.getValue()
]);
loadingSpinner.stop();
console.log(`Taxa Selic: ${chalk.green(selicValue)}
Taxa Tesouro IPCA: ${chalk.green(ipcaValue)}
Índice IFIX: ${chalk.green(ifixValue)}
Índice IBOVESPA: ${chalk.green(ibovespaValue)}`);
}
async function getVariableIncomeNameFromUserInput() {
try {
const answers = await inquirer.prompt([
{
name: "variableIncomeName",
type: "input",
message: "Digite o nome do ativo:"
}
]);
loadingSpinner.start();
return answers["variableIncomeName"];
}
catch (error) {
console.log("exiting...");
}
}
//# sourceMappingURL=main.js.map