/selic

A tiny lib to scrap brazilian's selic, poupança and cdi rates

Primary LanguageTypeScriptMIT LicenseMIT

Selic

Donate via Paypal Build Status License npm GitHub stars GitHub forks

A tiny lib to scrap brazilian's selic, poupança and cdi rates.

About

This is a tiny lib compatible with Node.js v11+ and TypeScript, with zero dependencies, supports ES Import and CommonJS.

Basically this lib fetchs the current brazilian SELIC rates and CDI rates, all values in apy (percentage per year).

The Selic rate is fetched from Banco Central do Brasil The CDI rate is fetched from CETIP

How to install

npm install --save selic

How to use

ESImport

import { Selic } from 'selic';

CommonJS

const { Selic } = require('selic');

Fetch selic and cdi brazilian rates in array version

(async () => {
  const selic = new Selic();
  const rates = await selic.getAllRates();
  /*
   * [
   *  { name: 'Selic', apy: 7.75 },
   *  { name: 'CDI', apy: 7.65 }
   * ]
   */
  console.log(rates);
})()

Fetch selic and cdi brazilian rates in object version

(async () => {
  const selic = new Selic();
  const rates = await selic.getRatesObject();
  /*
   * { selic: 7.75, cdi: 7.65 }
   */
  console.log(rates);
})()

Get only Selic rate

(async () => {
  const selic = new Selic();
  const selicValue = await selic.getSelicRate();
  console.log(selicValue); // 7.75
})()

Get only CDI rate

(async () => {
  const selic = new Selic();
  const cdiValue = await selic.getCdiRate();
  console.log(cdiValue); // 7.65
})()

Author

Caio Ribeiro Pereira caio.ribeiro.pereira@gmail.com
Twitter: https://twitter.com/crp_underground
About me: https://crpwebdev.github.io