Skip to content

Commit

Permalink
Merge pull request #65 from wilsonfreitas/main
Browse files Browse the repository at this point in the history
Correct SSL errors and disabled CDIIDI scrape
  • Loading branch information
wilsonfreitas committed Jul 13, 2024
2 parents f23e08b + 0de7fe3 commit 996fff6
Show file tree
Hide file tree
Showing 24 changed files with 29 additions and 63 deletions.
4 changes: 3 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ templates_save.r
^README\.Rmd$
^codemeta\.json$
Contributing.md
examples
examples
^doc$
^Meta$
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ aux.R
.lintr
inst/doc
docs
/doc/
/Meta/
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ Collate:
'download-data.R'
'file.R'
'convert_to.R'
'scraper-cdi.R'
'scraper-futures.R'
'scraper-yc.R'
'scraper-cotahist.R'
Expand All @@ -75,6 +74,6 @@ URL: https://github.com/ropensci/rb3,
http://ropensci.github.io/rb3/
VignetteBuilder: knitr
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
Config/testthat/edition: 3
Encoding: UTF-8
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(cachedir)
export(cdi_get)
export(clearcache)
export(code2month)
export(company_cash_dividends_get)
Expand All @@ -28,7 +27,6 @@ export(display_template)
export(download_marketdata)
export(futures_get)
export(futures_mget)
export(idi_get)
export(index_by_segment_get)
export(index_comp_get)
export(index_get)
Expand Down
10 changes: 5 additions & 5 deletions R/downloaders.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ settlement_prices_download <- function(., dest, ...) {
verifyssl <- if (!is.null(.$verifyssl)) .$verifyssl else TRUE
if (verifyssl) {
res <- POST(.$downloader$url,
body = list(dData1 = strdate),
encode = "form"
body = list(dData1 = strdate),
encode = "form"
)
} else {
res <- POST(.$downloader$url,
body = list(dData1 = strdate),
encode = "form", config(ssl_verifypeer = FALSE)
body = list(dData1 = strdate),
encode = "form", config(ssl_verifypeer = FALSE)
)
}
if (status_code(res) != 200) {
Expand Down Expand Up @@ -180,7 +180,7 @@ url_encoded_download <- function(., dest, ...) {
if (verifyssl) {
res <- GET(url)
} else {
res <- GET(url, config(ssl_verifypeer = FALSE))
res <- GET(url, config(ssl_verifypeer = 0L))
}
if (status_code(res) != 200) {
return(FALSE)
Expand Down
7 changes: 2 additions & 5 deletions R/rb3-package.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#' @keywords internal
"_PACKAGE"

#' @title Read files from Brazilian Financial Market
#'
#' @description
Expand Down Expand Up @@ -42,7 +39,6 @@
#' }
#'
#' @name rb3-package
#' @docType package
#'
#' @importFrom ascii ascii
#' @importFrom proto proto
Expand Down Expand Up @@ -73,4 +69,5 @@
#' @importFrom rvest read_html html_nodes html_text
#' @importFrom rvest html_table html_element read_html
#' @importFrom XML xmlInternalTreeParse getNodeSet xmlValue
NULL
#' @keywords internal
"_PACKAGE"
4 changes: 0 additions & 4 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ reference:
- maturity2date
- code2month

- title: CDI rate and IDI index
contents:
- cdi_get

- title: Super datasets (mix datasets)
contents:
- yc_superset
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 5 additions & 4 deletions examples/cotahist-options-examples.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

library(tidyverse)
library(bizdays)
library(oplib)

refdate <- Sys.Date() - 2

Expand All @@ -21,11 +22,11 @@ maturities <- df |>
df |>
filter(symbol.underlying == "PETR4", maturity_date %in% maturities[1:2]) |>
ggplot(aes(
x = strike, y = close, size = volume,
x = strike, y = close, linewidth = volume,
group = maturity_date, color = factor(maturity_date)
)) +
geom_vline(
xintercept = close_underlying[1], size = 1, color = "red", alpha = 0.25
xintercept = close_underlying[1], linewidth = 1, color = "red", alpha = 0.25
) +
geom_point(alpha = 0.5) +
facet_grid(. ~ type)
Expand Down Expand Up @@ -80,4 +81,4 @@ m1 |>

m1 |>
ggplot(aes(x = delta, y = sigma, size = volume, color = type)) +
geom_point(alpha = 0.5)
geom_point(alpha = 0.5)
3 changes: 3 additions & 0 deletions examples/debug-rb3.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
devtools::load_all()
debugonce(url_encoded_download)
single_index_get("IBOV", 2024, cachedir(), FALSE)
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions inst/extdata/templates/GetDetailsCompany.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ filename: ~
filetype: MCUSTOM
description: Informação suplementar das companhias listadas na Bolsa
locale: pt
verifyssl: false
downloader:
function: company_details_download
url: https://sistemaswebb3-listados.b3.com.br/listedCompaniesProxy/CompanyCall/GetDetail
Expand Down
1 change: 1 addition & 0 deletions inst/extdata/templates/GetListedCashDividends.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ filename: ~
filetype: CUSTOM
description: Listagem de dividendos em dinheiro
locale: pt
verifyssl: false
downloader:
function: company_cash_dividends_download
url: https://sistemaswebb3-listados.b3.com.br/listedCompaniesProxy/CompanyCall/GetListedCashDividends
Expand Down
1 change: 1 addition & 0 deletions inst/extdata/templates/GetListedSupplementCompany.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ filename: ~
filetype: MCUSTOM
description: Informação suplementar das companhias listadas na Bolsa
locale: pt
verifyssl: false
downloader:
function: company_listed_supplement_download
url: https://sistemaswebb3-listados.b3.com.br/listedCompaniesProxy/CompanyCall/GetListedSupplementCompany
Expand Down
1 change: 1 addition & 0 deletions inst/extdata/templates/GetPortfolioDay.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ filename: ~
filetype: MCUSTOM
description: Carteira Teórica dos índices da B3 com pesos e quantidades por segmentos
locale: pt
verifyssl: false
downloader:
function: stock_indexes_current_portfolio_download
url: https://sistemaswebb3-listados.b3.com.br/indexProxy/indexCall/GetPortfolioDay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ filename: ~
filetype: MCUSTOM
description: Dados históricos de cotação dos índices da Bolsa
locale: pt
verifyssl: false
downloader:
function: stock_indexes_statistics_download
url: https://sistemaswebb3-listados.b3.com.br/indexStatisticsProxy/IndexCall/GetPortfolioDay
Expand Down
1 change: 1 addition & 0 deletions inst/extdata/templates/GetStockIndex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ filename: ~
filetype: MCUSTOM
description: Composição dos índices da B3
locale: pt
verifyssl: false
downloader:
function: stock_indexes_composition_download
url: https://sistemaswebb3-listados.b3.com.br/indexProxy/indexCall/GetStockIndex
Expand Down
1 change: 1 addition & 0 deletions inst/extdata/templates/GetTheoricalPortfolio.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ filename: ~
filetype: MCUSTOM
description: Carteira Teórica dos índices da B3 com pesos e posições
locale: pt
verifyssl: false
downloader:
function: stock_indexes_theo_portfolio_download
url: https://sistemaswebb3-listados.b3.com.br/indexProxy/indexCall/GetTheoricalPortfolio
Expand Down
25 changes: 0 additions & 25 deletions man/cdi-idi.Rd

This file was deleted.

6 changes: 1 addition & 5 deletions man/rb3-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions tests/testthat/test-downloaders.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ if (Sys.info()["sysname"] == "Linux") {
httr::set_config(httr::config(ssl_verifypeer = FALSE))
}

test_that("it should download a file with a simple downloader", {
tpl <- .retrieve_template(NULL, "CDIIDI")
dest <- tempfile()
vcr::use_cassette("CDIIDI", {
x <- tpl$download_marketdata(dest)
})
expect_true(x)
expect_true(file.exists(dest))
})

test_that("it should download a file with a datetime downloader", {
tpl <- .retrieve_template(NULL, "COTAHIST_DAILY")
dest <- tempfile()
Expand Down

0 comments on commit 996fff6

Please sign in to comment.