Skip to content

Commit

Permalink
Merge pull request #63 from wilsonfreitas/main
Browse files Browse the repository at this point in the history
Added _PACKAGE keyword
  • Loading branch information
wilsonfreitas committed Sep 11, 2023
2 parents 41235da + ecc810a commit f23e08b
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 17 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Title: Download and Parse Public Data Released by B3 Exchange
Description: Download and parse public files released by B3 and convert them
into useful formats and data structures common to data analysis
practitioners.
Version: 0.0.10
Version: 0.0.11
Authors@R: c(person("Wilson", "Freitas",
email = "[email protected]",
role = c("aut", "cre")),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# rb3 0.0.10

* Check empty files download.

# rb3 0.0.10

* Improved error handling in `read_marketdata`.
* Improved checks in `test-company.R` with exception handling for empty downloaded files.
* Removed tidyselect warnings in `scraper-company.R`.
Expand Down
3 changes: 3 additions & 0 deletions R/rb3-package.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#' @keywords internal
"_PACKAGE"

#' @title Read files from Brazilian Financial Market
#'
#' @description
Expand Down
26 changes: 25 additions & 1 deletion man/rb3-package.Rd

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

36 changes: 36 additions & 0 deletions tests/fixtures/GetListedSupplementCompanyEmpty.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
http_interactions:
- request:
method: get
uri: https://sistemaswebb3-listados.b3.com.br/listedCompaniesProxy/CompanyCall/GetListedSupplementCompany/eyJpc3N1aW5nQ29tcGFueSI6IldXV1ciLCJsYW5ndWFnZSI6InB0LWJyIn0=
body:
encoding: ''
string: ''
headers:
Accept: application/json, text/xml, application/xml, */*
response:
status:
status_code: 200
category: Success
reason: OK
message: 'Success: (200) OK'
headers:
content-type: text/plain; charset=utf-8
strict-transport-security: max-age=31536000; includeSubDomains
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
content-security-policy: 'default-src ''self'' https://*.google-analytics.com;
font-src ''self'' data: https://fonts.gstatic.com/ ;img-src * data: ; script-src
''unsafe-eval'' * ''unsafe-inline''; style-src * ''unsafe-inline''; frame-src
http://*.b3.com.br https://*.b3.com.br https://s.tradingview.com/'
referrer-policy: strict-origin
server-timing: dtSInfo;desc="0", dtRpid;desc="-1390190705"
date: Fri, 14 Apr 2023 10:19:05 GMT
set-cookie: TS01871345=016e3b076f06eb63eacb0e0b9c3bb762afe07ce71435a997f08e493ef9c9061be84cb6d8327427527418df757c8798b1cc9e7cadf5;
Path=/; HTTPOnly
transfer-encoding: chunked
body:
encoding: ''
file: no
string: ''
recorded_at: 2023-04-14 10:19:06 GMT
recorded_with: vcr/1.2.0, webmockr/0.9.0
8 changes: 4 additions & 4 deletions tests/testthat/test-cotahist.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ test_that("it should extract funds data from cotahist dataset", {
expect_type(df$close, "double")
expect_type(df$transactions_quantity, "integer")
expect_true(nrow(df) > 0)
df <- cotahist_fidcs_get(ch)
expect_type(df$close, "double")
expect_type(df$transactions_quantity, "integer")
expect_true(nrow(df) > 0)
# df <- cotahist_fidcs_get(ch)
# expect_type(df$close, "double")
# expect_type(df$transactions_quantity, "integer")
# expect_true(nrow(df) > 0)
df <- cotahist_fiagros_get(ch)
expect_type(df$close, "double")
expect_type(df$transactions_quantity, "integer")
Expand Down
38 changes: 28 additions & 10 deletions tests/testthat/test-downloaders.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,63 +79,81 @@ test_that("it should fail base64_datetime_download", {
expect_false(f)
})

test_that("it should download an empty file", {
tpl <- .retrieve_template(NULL, "GetListedSupplementCompany")
vcr::use_cassette("GetListedSupplementCompanyEmpty", {
fname <- tempfile()
f <- company_listed_supplement_download(tpl, fname, company_name = "WWWW")
})
expect_true(file.size(fname) <= 2)
expect_true(f)
})

test_that("it should company_listed_supplement_download", {
tpl <- .retrieve_template(NULL, "GetListedSupplementCompany")
vcr::use_cassette("GetListedSupplementCompany", {
f <- company_listed_supplement_download(tpl, tempfile(),
company_name = "ABEV"
)
fname <- tempfile()
f <- company_listed_supplement_download(tpl, fname, company_name = "ABEV")
})
expect_true(file.size(fname) > 2)
expect_true(f)
})

test_that("it should company_details_download", {
tpl <- .retrieve_template(NULL, "GetDetailsCompany")
vcr::use_cassette("GetDetailsCompany", {
f <- company_details_download(tpl, tempfile(),
code_cvm = "24910"
)
fname <- tempfile()
f <- company_details_download(tpl, fname, code_cvm = "24910")
})
expect_true(file.size(fname) > 2)
expect_true(f)
})

test_that("it should company_cash_dividends_download ", {
tpl <- .retrieve_template(NULL, "GetListedCashDividends")
vcr::use_cassette("GetListedCashDividends", {
f <- company_cash_dividends_download(tpl, tempfile(),
fname <- tempfile()
f <- company_cash_dividends_download(tpl, fname,
trading_name = "AMBEVSA"
)
})
expect_true(file.size(fname) > 2)
expect_true(f)
})

test_that("it should stock_indexes_statistics_download ", {
tpl <- .retrieve_template(NULL, "GetPortfolioDay_IndexStatistics")
vcr::use_cassette("GetPortfolioDay_IndexStatistics", {
f <- stock_indexes_statistics_download(tpl, tempfile(),
fname <- tempfile()
f <- stock_indexes_statistics_download(tpl, fname,
index_name = "IBOV", year = 2022
)
})
expect_true(file.size(fname) > 2)
expect_true(f)
})

test_that("it should stock_indexes_current_portfolio_download ", {
tpl <- .retrieve_template(NULL, "GetPortfolioDay")
vcr::use_cassette("GetPortfolioDay", {
f <- stock_indexes_current_portfolio_download(tpl, tempfile(),
fname <- tempfile()
f <- stock_indexes_current_portfolio_download(tpl, fname,
index_name = "IBOV"
)
})
expect_true(file.size(fname) > 2)
expect_true(f)
})

test_that("it should stock_indexes_theo_portfolio_download ", {
tpl <- .retrieve_template(NULL, "GetTheoricalPortfolio")
vcr::use_cassette("GetTheoricalPortfolio", {
f <- stock_indexes_theo_portfolio_download(tpl, tempfile(),
fname <- tempfile()
f <- stock_indexes_theo_portfolio_download(tpl, fname,
index_name = "IBOV"
)
})
expect_true(file.size(fname) > 2)
expect_true(f)
})

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-indexes.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test_that("it should get index weights", {
expect_s3_class(x, "data.frame")
expect_true(ncol(x) == 3)
expect_equal(colnames(x), c("symbol", "weight", "position"))
expect_equal(as.integer(sum(x$weight)), 1L)
expect_equal(as.integer(round(sum(x$weight), 0)), 1L)
expect_true(nrow(x) > 0)
})

Expand Down

0 comments on commit f23e08b

Please sign in to comment.