Title: | Wrapper for the National Bank of Poland API |
---|---|
Description: | Use the <http://api.nbp.pl/> API through R. Retrieve currency exchange rates and gold prices data published by the National Bank of Poland in form of convenient R objects. |
Authors: | Ryszard Szymanski [aut, cre] |
Maintainer: | Ryszard Szymanski <[email protected]> |
License: | GPL-3 |
Version: | 0.2.1 |
Built: | 2025-02-22 02:54:47 UTC |
Source: | https://github.com/szymanskir/rnbp |
Returns the base url for the gold price endpoint.
.goldprice_base_url()
.goldprice_base_url()
Returns the base url for the rates endpoint.
.rates_base_url()
.rates_base_url()
Sends a request and parses the gold price endpoint response.
.send_gold_endpoint_request(request_url)
.send_gold_endpoint_request(request_url)
request_url |
url to which the request should be sent. |
nbp_api_response object with the request content.
Sends a request and parses the rates endpoint response.
.send_rates_endpoint_request(request_url)
.send_rates_endpoint_request(request_url)
request_url |
url to which the request should be sent. |
nbp_api_response object with the request content.
Sends a request and parses the tables endpoint response.
.send_tables_endpoint_request(request_url)
.send_tables_endpoint_request(request_url)
request_url |
url to which the request should be sent. |
nbp_api_response object with the request content.
Returns the base url for the tables endpoint.
.tables_base_url()
.tables_base_url()
Adds the json formatting option to the passed url request.
add_json_format(url)
add_json_format(url)
url |
request url to which the json format option should be added |
url with json format option added
Adds a path part to the given url
add_path_part(url, path_name)
add_path_part(url, path_name)
url |
url to which a path part should be added |
path_name |
path part which should be added to the url |
url with the path part added
Creates a request with the given path parts. The json format argument is included by default.
create_request(base_url, path_parts = NULL)
create_request(base_url, path_parts = NULL)
base_url |
base url of the API for which a request should be created |
path_parts |
that should be added to the base url |
request url composed of the given base url and specified path parts
Retrieves the current exchange rate for the given currency.
get_current_exchangerate(table, currency_code)
get_current_exchangerate(table, currency_code)
table |
specifies which from which table the exchange rate should be fetched. |
currency_code |
code of the currency for which the exchange rate should be fetched. |
nbp_api_response object containing the current exchange rate.
https://api.nbp.pl/#kursyWalut
Other rates:
get_exchangerate_from_interval()
,
get_exchangerate_from()
,
get_last_n_exchangerates()
,
get_todays_exchangerate()
tryCatch({ ## Retrieve the current exchange rate for euros response <- get_current_exchangerate("A", "EUR") ## Retrieve the content response$content }, error = function(e) message(e) )
tryCatch({ ## Retrieve the current exchange rate for euros response <- get_current_exchangerate("A", "EUR") ## Retrieve the content response$content }, error = function(e) message(e) )
Retrieves the current exchange rate table.
get_current_exchangerate_table(table)
get_current_exchangerate_table(table)
table |
specifies which table should be fetched. |
nbp_api_response object containing the current exchange rate table.
https://api.nbp.pl/#kursyWalut
Other tables:
get_exchangerate_table_from()
,
get_exchangerate_tables_from_interval()
,
get_last_n_exchangerate_tables()
,
get_todays_exchangerate_table()
tryCatch({ ## Retrieve the current A exchange rate table response <- get_current_exchangerate_table("A") ## Retrieve the content response$content }, error = function(e) message(e) )
tryCatch({ ## Retrieve the current A exchange rate table response <- get_current_exchangerate_table("A") ## Retrieve the content response$content }, error = function(e) message(e) )
Retrieves the current gold price.
get_current_goldprice()
get_current_goldprice()
nbp_api_response object containing the current gold price.
Other goldprice:
get_goldprice_from_interval()
,
get_goldprice_from()
,
get_last_n_goldprices()
,
get_todays_goldprice()
tryCatch({ ## Fetch the current gold price response <- get_current_goldprice() ## Retrieve the current gold price value response$content$cena }, error = function(e) message(e) )
tryCatch({ ## Fetch the current gold price response <- get_current_goldprice() ## Retrieve the current gold price value response$content$cena }, error = function(e) message(e) )
Retrieves the exchange rate from a specific date.
get_exchangerate_from(table, currency_code, date)
get_exchangerate_from(table, currency_code, date)
table |
specifies which from which table the exchange rate should be fetched. |
currency_code |
code of the currency for which the exchange rate should be fetched. |
date |
date from which the exchange rate should be fetched. |
As exchange rates are not published on the weekends fetching values from a weekend date will result in a 404 error. In those cases the function returns an error with an appropriate message.
nbp_api_response object containing the exchange rate from the specified date.
https://api.nbp.pl/#kursyWalut
Other rates:
get_current_exchangerate()
,
get_exchangerate_from_interval()
,
get_last_n_exchangerates()
,
get_todays_exchangerate()
tryCatch({ ## Fetch the euro exchange rate from a week ago response <- get_exchangerate_from("A", "EUR", Sys.Date() - 7) ## Preview response content response$content }, error = function(e) message(e) )
tryCatch({ ## Fetch the euro exchange rate from a week ago response <- get_exchangerate_from("A", "EUR", Sys.Date() - 7) ## Preview response content response$content }, error = function(e) message(e) )
Retrieves the exchange rates from a specific interval.
get_exchangerate_from_interval(table, currency_code, from, to)
get_exchangerate_from_interval(table, currency_code, from, to)
table |
specifies which from which table the exchange rate should be fetched. |
currency_code |
code of the currency for which the exchange rate should be fetched. |
from |
start day of the interval. |
to |
end day of the interval. |
As exchange rates are not published on the weekends fetching values from an interval containing a weekend will result in a response that omits those days.
nbp_api_response object containing the exchange rates from the specified interval.
https://api.nbp.pl/#kursyWalut
Other rates:
get_current_exchangerate()
,
get_exchangerate_from()
,
get_last_n_exchangerates()
,
get_todays_exchangerate()
tryCatch({ ## Fetch the exchange rate table from the past week response <- get_exchangerate_tables_from_interval("A", Sys.Date() - 7, Sys.Date()) ## Preview response content response$content }, error = function(e) message(e) )
tryCatch({ ## Fetch the exchange rate table from the past week response <- get_exchangerate_tables_from_interval("A", Sys.Date() - 7, Sys.Date()) ## Preview response content response$content }, error = function(e) message(e) )
Retrieves the exchange rate table from a specific date.
get_exchangerate_table_from(table, date)
get_exchangerate_table_from(table, date)
table |
specifies which table should be fetched. |
date |
date from which the exchange rate table should be fetched. |
As exchange rate tables are not published on the weekends fetching values from a weekend date will result in a 404 error. In those cases the function returns an error with an appropriate message.
nbp_api_response object containing the exchange rate table from the specified date.
https://api.nbp.pl/#kursyWalut
Other tables:
get_current_exchangerate_table()
,
get_exchangerate_tables_from_interval()
,
get_last_n_exchangerate_tables()
,
get_todays_exchangerate_table()
tryCatch({ ## Fetch the A exchange rate table from a week ago response <- get_exchangerate_table_from("A", Sys.Date() - 7) ## Preview response content response$content }, error = function(e) message(e) )
tryCatch({ ## Fetch the A exchange rate table from a week ago response <- get_exchangerate_table_from("A", Sys.Date() - 7) ## Preview response content response$content }, error = function(e) message(e) )
Retrieves the exchange rate tables from a specific interval.
get_exchangerate_tables_from_interval(table, from, to)
get_exchangerate_tables_from_interval(table, from, to)
table |
specifies which table should be fetched. |
from |
start day of the interval. |
to |
end day of the interval. |
As exchange rate tables are not published on the weekends fetching values from an interval containing a weekend will result in a response that omits those days.
nbp_api_response object containing the exchange rates tables from the specified interval.
https://api.nbp.pl/#kursyWalut
Other tables:
get_current_exchangerate_table()
,
get_exchangerate_table_from()
,
get_last_n_exchangerate_tables()
,
get_todays_exchangerate_table()
tryCatch({ ## Fetch the exchange rate table from the past week response <- get_exchangerate_tables_from_interval("A", Sys.Date() - 7, Sys.Date()) ## Preview response content response$content }, error = function(e) message(e) )
tryCatch({ ## Fetch the exchange rate table from the past week response <- get_exchangerate_tables_from_interval("A", Sys.Date() - 7, Sys.Date()) ## Preview response content response$content }, error = function(e) message(e) )
Retrieves the gold price from a specific date.
get_goldprice_from(date)
get_goldprice_from(date)
date |
date from which the gold price should be fetched. |
As gold prices are not published on the weekends fetching values from a weekend date will result in a 404 error. In those cases the function returns an error with an appropriate message.
nbp_api_response object containing the gold price from the specified date.
Other goldprice:
get_current_goldprice()
,
get_goldprice_from_interval()
,
get_last_n_goldprices()
,
get_todays_goldprice()
tryCatch({ ## Fetch the gold price from a week ago response <- get_goldprice_from(Sys.Date() - 7) ## Preview response content response$content }, error = function(e) message(e) )
tryCatch({ ## Fetch the gold price from a week ago response <- get_goldprice_from(Sys.Date() - 7) ## Preview response content response$content }, error = function(e) message(e) )
Retrieves the gold prices from a specific interval.
get_goldprice_from_interval(from, to)
get_goldprice_from_interval(from, to)
from |
start day of the interval. |
to |
end day of the interval. |
As gold prices are not published on the weekends fetching values from an interval containing a weekend will result in a response that omits those days.
nbp_api_response object containing the gold prices from the specified interval.
Other goldprice:
get_current_goldprice()
,
get_goldprice_from()
,
get_last_n_goldprices()
,
get_todays_goldprice()
tryCatch({ ## Fetch the gold prices from the past week response <- get_goldprice_from_interval(Sys.Date() - 7, Sys.Date()) ## Preview response content response$content }, error = function(e) message(e) )
tryCatch({ ## Fetch the gold prices from the past week response <- get_goldprice_from_interval(Sys.Date() - 7, Sys.Date()) ## Preview response content response$content }, error = function(e) message(e) )
Retrieves the last n exchange rate tables.
get_last_n_exchangerate_tables(table, n)
get_last_n_exchangerate_tables(table, n)
table |
specifies which table should be fetched. |
n |
number of exchange rate tables to retrieve. |
nbp_api_response object containing the last n exchange rate tables.
https://api.nbp.pl/#kursyWalut
Other tables:
get_current_exchangerate_table()
,
get_exchangerate_table_from()
,
get_exchangerate_tables_from_interval()
,
get_todays_exchangerate_table()
tryCatch({ ## Fetch the last 3 A exchange rate tables response <- get_last_n_exchangerate_tables("A", 3) ## Preview response content response$content }, error = function(e) message(e) )
tryCatch({ ## Fetch the last 3 A exchange rate tables response <- get_last_n_exchangerate_tables("A", 3) ## Preview response content response$content }, error = function(e) message(e) )
Retrieves the last n exchange rates.
get_last_n_exchangerates(table, currency_code, n)
get_last_n_exchangerates(table, currency_code, n)
table |
specifies which from which table the exchange rate should be fetched. |
currency_code |
code of the currency for which the exchange rate should be fetched. |
n |
number of exchange rates to retrieve. |
nbp_api_response object containing the last n exchange rates.
https://api.nbp.pl/#kursyWalut
Other rates:
get_current_exchangerate()
,
get_exchangerate_from_interval()
,
get_exchangerate_from()
,
get_todays_exchangerate()
tryCatch({ ## Fetch the last 3 exhange rates for euros response <- get_last_n_exchangerates("A", "EUR", 3) ## Preview response content response$content }, error = function(e) message(e) )
tryCatch({ ## Fetch the last 3 exhange rates for euros response <- get_last_n_exchangerates("A", "EUR", 3) ## Preview response content response$content }, error = function(e) message(e) )
Retrieves the last n gold prices.
get_last_n_goldprices(n)
get_last_n_goldprices(n)
n |
number of gold prices to retrieve. |
nbp_api_response object containing the last n gold prices.
Other goldprice:
get_current_goldprice()
,
get_goldprice_from_interval()
,
get_goldprice_from()
,
get_todays_goldprice()
tryCatch({ ## Fetch the last 3 gold price values response <- get_last_n_goldprices(3) ## Preview response content response$content }, error = function(e) message(e) )
tryCatch({ ## Fetch the last 3 gold price values response <- get_last_n_goldprices(3) ## Preview response content response$content }, error = function(e) message(e) )
Retrieves the exchange rate that was published today.
get_todays_exchangerate(table, currency_code)
get_todays_exchangerate(table, currency_code)
table |
specifies which from which table the exchange rate should be fetched. |
currency_code |
code of the currency for which the exchange rate should be fetched. |
If today's data is not available the API will return a 404 Not found error. In that case the function will return an error with an appropriate message.
nbp_api_response object containing today's exchange rate.
https://api.nbp.pl/#kursyWalut
Other rates:
get_current_exchangerate()
,
get_exchangerate_from_interval()
,
get_exchangerate_from()
,
get_last_n_exchangerates()
tryCatch({ ## Fetch todays A exchange rate table response <- get_todays_exchangerate("A", "EUR") ## Preview response content response$content }, error = function(e) message(e) )
tryCatch({ ## Fetch todays A exchange rate table response <- get_todays_exchangerate("A", "EUR") ## Preview response content response$content }, error = function(e) message(e) )
Retrieves the exchange rate table that was published today.
get_todays_exchangerate_table(table)
get_todays_exchangerate_table(table)
table |
specifies which table should be fetched. |
If today's data is not available the API will return a 404 Not found error. In that case the function will return an error with an appropriate message.
nbp_api_response object containing today's exchange rate table.
https://api.nbp.pl/#kursyWalut
Other tables:
get_current_exchangerate_table()
,
get_exchangerate_table_from()
,
get_exchangerate_tables_from_interval()
,
get_last_n_exchangerate_tables()
tryCatch({ ## Fetch todays A exchange rate table response <- get_todays_exchangerate_table("A") ## Preview response content response$content }, error = function(e) message(e) )
tryCatch({ ## Fetch todays A exchange rate table response <- get_todays_exchangerate_table("A") ## Preview response content response$content }, error = function(e) message(e) )
Retrieves the gold price that was published today.
get_todays_goldprice()
get_todays_goldprice()
If today's data is not available the API will return a 404 Not found error. In that case the function will return an error with an appropriate message.
nbp_api_response object containing today's gold price.
Other goldprice:
get_current_goldprice()
,
get_goldprice_from_interval()
,
get_goldprice_from()
,
get_last_n_goldprices()
tryCatch({ ## Fetch todays gold price response <- get_todays_goldprice() ## Preview response content response$content }, error = function(e) message(e) )
tryCatch({ ## Fetch todays gold price response <- get_todays_goldprice() ## Preview response content response$content }, error = function(e) message(e) )
Checks if an object is a positive integer.
is_count(x)
is_count(x)
x |
object to be tested. |
TRUE or FALSE depending on whether its argument is a positive integer or not.
Checks if an object is a date object.
is_date(x)
is_date(x)
x |
object to be tested. |
TRUE or FALSE depending on whether its arguments is a date object or not.
Checks if an object is an integer.
is_integer(x)
is_integer(x)
x |
object to be tested. |
TRUE or FALSE depending on whether its argument is an integer or not.
Checks whether the given object is of the class nbp_api_response.
is_nbp_api_response(x)
is_nbp_api_response(x)
x |
object to test if it is of the class nbp_api_response |
TRUE if the object is of the class nbp_api_response
Returns the base url of the nbp api.
nbp_api_base_url()
nbp_api_base_url()