Skip to content

Commit

Permalink
Merge pull request #50 from alexandrerocco/split-events
Browse files Browse the repository at this point in the history
Suporte para desdobramento de ações
  • Loading branch information
Menighin authored Jun 11, 2021
2 parents 20b67b4 + ccb992b commit 94a6bdd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ Resultado:

#### getDividends(_date_)
Método que processa todos os dados disponíveis sobre proventos recebidos em um período e retorna como uma lista. Usualmente os proventos disponíveis na página do CEI são os creditados no mês atual e os já anunciados pela empresas com e sem data definida. Registros com date igual `null` são de proventos anunciados mas sem data definida de pagamento.

Além disso, caso existam eventos de desdobramento de ações, eles serão retornados em uma propriedade específica.
```javascript
let dividends = await ceiCrawler.getDividends(date);
```
Expand Down Expand Up @@ -281,7 +283,22 @@ Resultado:
"grossValue": 78,
"netValue": 78
}
]
],
"splitEvents": [
{
"stock": "B3",
"stockType": "ON NM",
"code": "B3SA3",
"type": "DESDOBRAMENTO DE AÇÕES",
"date": "2021-05-18T03:00:00.000Z",
"baseQuantity": 49,
"factor": 1,
"destinationCode": "B3SA3",
"quantity": 98,
"eventValue": 200,
"exerciseValue": 0
}
]
}
]
```
Expand Down
35 changes: 28 additions & 7 deletions src/lib/DividendsCrawler.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const PAGE = {
PAGE_ALERT_SUCCESS: '.alert-box.success',
TABLE_TITLE_SELECTOR: 'p.title',
PAST_EVENTS_TITLE: 'Eventos em Dinheiro Creditado',
FUTURE_EVENTS_TITLE: 'Eventos em Dinheiro Provisionado'
FUTURE_EVENTS_TITLE: 'Eventos em Dinheiro Provisionado',
SPLIT_EVENTS_TITLE: 'Eventos em Ativos Creditado'
}

const DIVIDENDS_TABLE_HEADERS = {
Expand All @@ -36,6 +37,20 @@ const DIVIDENDS_TABLE_HEADERS = {
netValue: 'float'
};

const SPLITS_TABLE_HEADERS = {
stock: 'string',
stockType: 'string',
code: 'string',
type: 'string',
date: 'date',
baseQuantity: 'int',
factor: 'int',
destinationCode:'string',
quantity: 'int',
eventValue: 'float',
exerciseValue: 'float'
}

const FETCH_OPTIONS = {
DIVIDENDS_INSTITUTION: {
"headers": {
Expand Down Expand Up @@ -187,14 +202,15 @@ class DividendsCrawler {

domPage(PAGE.SELECT_ACCOUNT).attr('value', account);

const { futureEvents, pastEvents } = await this._getDataPage(domPage, cookieManager, traceOperations);
const { futureEvents, pastEvents, splitEvents } = await this._getDataPage(domPage, cookieManager, traceOperations);

// Save the result
result.push({
institution: institution.label,
account: account,
futureEvents: futureEvents,
pastEvents: pastEvents
pastEvents: pastEvents,
splitEvents: splitEvents
});
}
}
Expand Down Expand Up @@ -286,11 +302,13 @@ class DividendsCrawler {

const futureEvents = this._processEvents(dividendsDOM, PAGE.FUTURE_EVENTS_TITLE);
const pastEvents = this._processEvents(dividendsDOM, PAGE.PAST_EVENTS_TITLE);
const splitEvents = this._processEvents(dividendsDOM, PAGE.SPLIT_EVENTS_TITLE);

if (errorMessage.type !== undefined || futureEvents.length > 0 || pastEvents.length > 0) {
if (errorMessage.type !== undefined || futureEvents.length > 0 || pastEvents.length > 0 || splitEvents.length > 0) {
return {
futureEvents,
pastEvents
pastEvents,
splitEvents
};
}

Expand All @@ -305,7 +323,10 @@ class DividendsCrawler {
* @param {String} tableTitle The title of the table to process the events
*/
static _processEvents(dom, tableTitle) {
const headers = Object.keys(DIVIDENDS_TABLE_HEADERS);
// The header for dividends is the same, but for the split events is different
const headerKey = tableTitle === PAGE.SPLIT_EVENTS_TITLE ? SPLITS_TABLE_HEADERS : DIVIDENDS_TABLE_HEADERS;

const headers = Object.keys(headerKey);

const data = dom(PAGE.TABLE_TITLE_SELECTOR)
.filter((_, el) => dom(el).text().includes(tableTitle))
Expand All @@ -322,7 +343,7 @@ class DividendsCrawler {
)
.get();

return CeiUtils.parseTableTypes(data, DIVIDENDS_TABLE_HEADERS);
return CeiUtils.parseTableTypes(data, headerKey);
}
}

Expand Down

0 comments on commit 94a6bdd

Please sign in to comment.