Skip to content

Commit

Permalink
improving documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
msperlin committed Jun 4, 2024
1 parent 73816ee commit dd0fe8d
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 41 deletions.
2 changes: 1 addition & 1 deletion R/base-query.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Low level (unexported) function for fetching data from API
#' Low level (unexported) function for retrieving data from API
#'
#' @param url A well formed url
#'
Expand Down
2 changes: 1 addition & 1 deletion R/dividends.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ get_dividends <- function(ticker = "AAPL", exchange = "US",
cache_folder = get_default_cache(),
check_quota = TRUE) {

cli::cli_h1("fetching dividends for ticker {ticker}|{exchange}")
cli::cli_h1("retrieving dividends for ticker {ticker}|{exchange}")

if (check_quota) {
get_quota_status()
Expand Down
2 changes: 1 addition & 1 deletion R/exchanges.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#'
get_exchanges <- function() {

cli::cli_h1("fetching exchange list")
cli::cli_h1("retrieving exchange list")

token <- get_token()
if (token == get_demo_token()) {
Expand Down
2 changes: 1 addition & 1 deletion R/fundamentals.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ get_fundamentals <- function(ticker = "AAPL",
cache_folder = get_default_cache(),
check_quota = TRUE) {

cli::cli_h1("fetching fundamentals for ticker {ticker}|{exchange}")
cli::cli_h1("retrieving fundamentals for ticker {ticker}|{exchange}")

token <- get_token()

Expand Down
2 changes: 1 addition & 1 deletion R/prices.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ get_prices <- function(ticker = "AAPL",
cache_folder = get_default_cache(),
check_quota = TRUE) {

cli::cli_h1("fetching price data for ticker {ticker}|{exchange}")
cli::cli_h1("retrieving price data for ticker {ticker}|{exchange}")

if (check_quota) {
get_quota_status()
Expand Down
2 changes: 1 addition & 1 deletion R/splits.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ get_splits <- function(ticker = "AAPL", exchange = "US",
cli::cli_abort("You need a proper token (not demonstration) for exchange list..")
}

cli::cli_alert_info("fetching splits for ticker {ticker}|{exchange}")
cli::cli_h1("retrieving splits for ticker {ticker}|{exchange}")

if (check_quota) {
get_quota_status()
Expand Down
2 changes: 1 addition & 1 deletion R/tickers.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ get_tickers <- function(exchange = "US") {
cli::cli_abort("You need a proper token (not demonstration) for the ticker list..")
}

cli::cli_alert_info("fetching tickers for {exchange}")
cli::cli_h1("retrieving tickers for {exchange}")

url <- glue::glue('{get_base_url()}/exchange-symbol-list/{exchange}?api_token={token}&fmt=json')

Expand Down
6 changes: 3 additions & 3 deletions R/token.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ set_token <- function(token = get_demo_token()) {

if (token == get_demo_token()) {
cli::cli_alert_danger(
"You are using a DEMONSTRATION token for testing pourposes, with limited access to the data repositories.
See <https://eodhd.com/> for registration and use function set_token(TOKEN) to set your own token.")
"You are using a **DEMONSTRATION** token for testing pourposes, with limited access to the data repositories.
See <https://eodhd.com/> for registration and, after finding your token, use it with function eodhd2::set_token(TOKEN).")
}

return(invisible(TRUE))
Expand All @@ -57,7 +57,7 @@ get_token <- function() {
token <- Sys.getenv("eodhd-token")

if (token == "") {
cli::cli_abort("Cant find token. Set your token with function eodhd2::set_token()")
cli::cli_abort("Can't find eodhd token. Set your token with function eodhd2::set_token()")
}

return(token)
Expand Down
18 changes: 11 additions & 7 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@ knitr::opts_chunk$set(
[![codecov](https://codecov.io/github/msperlin/eodhd2/graph/badge.svg?token=9Y5GNHALC4)](https://codecov.io/github/msperlin/eodhd2)
<!-- badges: end -->

[eodhd](https://eodhd.com/) is a private company that offers access to a set of comprehensive and high quality financial data for over 70+ exchanges across the world. This includes:
[eodhd](https://eodhd.com/) is a private company that offers APIs to a set of comprehensive and high quality financial data for over 70+ exchanges across the world. This includes:

* Adjusted and unadjusted prices of financial contracts (equity, funds, ETF, cryptocurrencies, ..)
* Financial information of companies (Balance Sheet, Income/Cashflow statement)
* Valuation indicators
* And [more](https://eodhd.com/)..

Package eodhd2 is an R port of the API, allowing fast and intelligent access to most endpoints.
Package eodhd2 is the second and backwards incompatible version of [eodhd](https://github.com/EodHistoricalData/EODHD-APIs-R-Financial-Library), allowing fast and intelligent access to most of the API's endpoints.


# Features

- A local caching system that saves queries to the disk, improving execution time and reducing api calls on repeated queries.
- A local caching system that saves all API queries to the disk, improving execution time and reducing api calls on repeated queries.
- A quota management system, informing the user of how much of the API daily quota was used and how much time is left to refresh it.
- Function for aggregating and organizing financial information into a single dataframe, allowing easier access to clean financial data in the wide or long format.
- Function for aggregating and organizing financial information into a single dataframe, allowing easier access to clean financial data in the [wide or long format](https://libguides.princeton.edu/R-reshape#:~:text=A%20dataset%20can%20be%20written,repeat%20in%20the%20first%20column.&text=We%20can%20see%20that%20in,value%20in%20the%20first%20column).


# Installation
Expand All @@ -52,17 +53,20 @@ devtools::install_github("msperlin/eodhd2")

## Authentication

After registering at the [website](https://eodhd.com/) and choosing a subscription, all users will authenticate an R session using a token from the website:
After registering at the [website](https://eodhd.com/) and choosing a subscription, all users will authenticate an R session using a token from the website. For that:

1) Create an account at [https://eodhd.com/](https://eodhd.com/)
2) Go in "Settings" and look for your API token

![](inst/extdata/figs/token.png)

The authentication is managed with function `set_token()`:
While using `eodhd2`, all authentications are managed with function `eodhd2::set_token()`:

```{r, eval=FALSE}
eodhd2::set_token("YOUR_TOKEN")
```

Alternatively, you can use the "demo" token for demonstration.
Alternatively, while testing the API, you can use the "demo" token for demonstration.

```{r, eval=TRUE}
token <- eodhd2::get_demo_token()
Expand Down
47 changes: 27 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[![codecov](https://codecov.io/github/msperlin/eodhd2/graph/badge.svg?token=9Y5GNHALC4)](https://codecov.io/github/msperlin/eodhd2)
<!-- badges: end -->

[eodhd](https://eodhd.com/) is a private company that offers access to a
[eodhd](https://eodhd.com/) is a private company that offers APIs to a
set of comprehensive and high quality financial data for over 70+
exchanges across the world. This includes:

Expand All @@ -22,18 +22,20 @@ exchanges across the world. This includes:
- Valuation indicators
- And [more](https://eodhd.com/)..

Package eodhd2 is an R port of the API, allowing fast and intelligent
access to most endpoints.
Package eodhd2 is the second and backwards incompatible version of
[eodhd](https://github.com/EodHistoricalData/EODHD-APIs-R-Financial-Library),
allowing fast and intelligent access to most of the API’s endpoints.

# Features

- A local caching system that saves queries to the disk, improving
execution time and reducing api calls on repeated queries.
- A local caching system that saves all API queries to the disk,
improving execution time and reducing api calls on repeated queries.
- A quota management system, informing the user of how much of the API
daily quota was used and how much time is left to refresh it.
- Function for aggregating and organizing financial information into a
single dataframe, allowing easier access to clean financial data in
the wide or long format.
the [wide or long
format](https://libguides.princeton.edu/R-reshape#:~:text=A%20dataset%20can%20be%20written,repeat%20in%20the%20first%20column.&text=We%20can%20see%20that%20in,value%20in%20the%20first%20column).

# Installation

Expand All @@ -51,27 +53,32 @@ devtools::install_github("msperlin/eodhd2")

After registering at the [website](https://eodhd.com/) and choosing a
subscription, all users will authenticate an R session using a token
from the website:
from the website. For that:

1) Create an account at <https://eodhd.com/>
2) Go in “Settings” and look for your API token

![](inst/extdata/figs/token.png)

The authentication is managed with function `set_token()`:
While using `eodhd2`, all authentications are managed with function
`eodhd2::set_token()`:

``` r
eodhd2::set_token("YOUR_TOKEN")
```

Alternatively, you can use the “demo” token for demonstration.
Alternatively, while testing the API, you can use the “demo” token for
demonstration.

``` r
token <- eodhd2::get_demo_token()
eodhd2::set_token(token)
#> ✔ eodhd API token set
#> ℹ Account name: API Documentation 2 (supportlevel1@eodhistoricaldata.com)
#> ℹ Quota: 46886 | 10000000
#> ℹ Quota: 57033 | 10000000
#> ℹ Subscription: demo
#> ✖ You are using a DEMONSTRATION token for testing pourposes, with limited access to the data repositories.
#> See <https://eodhd.com/> for registration and use function set_token(TOKEN) to set your own token.
#> ✖ You are using a **DEMONSTRATION** token for testing pourposes, with limited access to the data repositories.
#> See <https://eodhd.com/> for registration and, after finding your token, use it with function eodhd2::set_token(TOKEN).
```

# Examples
Expand All @@ -84,9 +91,9 @@ exchange <- "US"

df_prices <- eodhd2::get_prices(ticker, exchange)
#>
#> ── fetching price data for ticker AAPL|US ──────────────────────────────────────
#> ! Quota status: 46887|10000000, refreshing in 9.99 hours
#> ℹ cache file '/tmp/RtmpT3AO3H/eodhd2-cache/AAPL_US_eodhd_prices.rds' saved
#> ── retrieving price data for ticker AAPL|US ────────────────────────────────────
#> ! Quota status: 57034|10000000, refreshing in 6.95 hours
#> ℹ cache file '/tmp/RtmpjBU71O/eodhd2-cache/AAPL_US_eodhd_prices.rds' saved
#> ✔ got 10959 rows of prices
#> ℹ got daily data from 1980-12-12 to 2024-06-03
```
Expand Down Expand Up @@ -134,9 +141,9 @@ exchange <- "US"

df_div <- eodhd2::get_dividends(ticker, exchange)
#>
#> ── fetching dividends for ticker AAPL|US ───────────────────────────────────────
#> ! Quota status: 46890|10000000, refreshing in 9.99 hours
#> ℹ cache file '/tmp/RtmpT3AO3H/eodhd2-cache/AAPL_US_eodhd_dividends.rds' saved
#> ── retrieving dividends for ticker AAPL|US ─────────────────────────────────────
#> ! Quota status: 57037|10000000, refreshing in 6.94 hours
#> ℹ cache file '/tmp/RtmpjBU71O/eodhd2-cache/AAPL_US_eodhd_dividends.rds' saved
#> ✔ got 83 rows of dividend data
```

Expand Down Expand Up @@ -182,8 +189,8 @@ exchange <- "US"

l_fun <- eodhd2::get_fundamentals(ticker, exchange)
#>
#> ── fetching fundamentals for ticker AAPL|US ────────────────────────────────────
#> ! Quota status: 46891|10000000, refreshing in 9.99 hours
#> ── retrieving fundamentals for ticker AAPL|US ──────────────────────────────────
#> ! Quota status: 57038|10000000, refreshing in 6.94 hours
#> ✔ querying API
#> ✔ got 13 elements in raw list
```
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-dividend.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test_that("fetch dividends", {
test_that("dividends", {

suppressMessages({
set_token()
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-prices.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test_that("fetching prices", {
test_that("prices", {

suppressMessages({
set_token()
Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test-splits.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
test_that("fetching splits", {
test_that("splits", {

#' Fetches dividend data from eodhd
skip_if(get_token() == get_demo_token(),
"Found a test/demo token, which does not allow for querying splits data")
})

0 comments on commit dd0fe8d

Please sign in to comment.