Financial Data

This project is open source and you can check it here!

For this project I worked in two parts:
- BACEN data: getting SELIC and IPCA.
- StockMarket data: getting all current stocks on B3 (Brazil's stock trading center) and it's history.

BACEN
For getching BACEN's data I went to their public domain to see what was avaiable and for my surprise they have a lot os data already structured and updated daily!
For example, if you enter here you'll see that it has several options to download the data from and you'll also notice it has a code to is, in this example it's 1178 as well the dates that you want to download.
With that being said i did an engine that will run through and array of codes, check the latest date you'll input and download the data from this date untill today.

async function fetchBACENData(seriesCode, startDate, endDate) {
  const url = `https://api.bcb.gov.br/dados/serie/bcdata.sgs.${seriesCode}/dados?formato=json&dataInicial=${startDate}&dataFinal=${endDate}`;
  const response = await axios.get(url);
  return response.data;
};


So i looped this getting all the data and saving it into json files.


StockMarket
To get the stockmarket data i used yahoo-finance2 dependency.
const queryOptions = { period1: startPeriod, return: "object", };
const result = await yahooFinance.chart(symbol, queryOptions);


This gets the stock ticker and the latest date you want to fetch the information from and gives back a really long object with several options on it, for this project i used this ones:
for(elementTimeStamp of timestampArray){
  date = new Date(elementTimeStamp*1000); // *1000 to fix the timestamp from unix to javascript
  dateArray.push(date);
};

let finalObject = {};

finalObject.stockTicker = symbol;
finalObject.dates = dateArray;
finalObject.volume = result.indicators.quote[0].volume;
finalObject.open = result.indicators.quote[0].open;
finalObject.low = result.indicators.quote[0].low;
finalObject.high = result.indicators.quote[0].high;
finalObject.close = result.indicators.quote[0].close;


So with that i have the stock information trading history and after that i save it all into a sql database using knex.


If you need more information you can check my github repository.
I hope you have enjoyed the reading for i sure did enjoy writting it!


Don't forget to check the links!
by Thales Fornazari