knitr::opts_chunk$set( collapse = TRUE)
The Overseas-Chinese Banking Corporation Limited (OCBC) is a Singapore-based bank that has operations spanning 17 countries. OCBC bank provides developers with more than 250 APIs to work with. The APIs fall under the category of Informational and Transactional, with the informational APIs requiring an access token for authorization, and the Transactional APIs requiring OAuth2.0 Authentication.
However the OCBCR package only includes the Informational APIs. All Informational API calls require an access token, which is basically a password through which you can access the API and it helps the OCBC developers to identify who is using their API. Hence please keep your API confidential and do not share it or post it online! In order to use the OCBCR package, please sign up for an API Access Token through this link. You will receive an API Key, an API Secret and an Access Token. You will mostly need the access token to use this package.
In many of the examples in the OCBCR package, the API access token is stored as Sys.getenv("ACC_TOKEN_OCBC")
. This means that the API access token is stored in the Renvironment file which keeps it private. You can do this through usethis::edit_r_environ()
and assigning your access token like this MY_ACCESS_TOKEN = (your access token)
. ALL API functions in the OCBCR package require the argument acctoken
which is the user's account token.
After acquring your access token, you then need to subscribe to the OCBC API(s) that you would like to use. This is quite repetitive, but is very simple to do. For example, if you would like to use the ocbc_accounts function included in this OCBCR package, you would need to subscribe to all the APIs in the 'Accounts' category on [this page] (https://api.ocbc.com/store/api_products). You can do this through the API console tab. This way you will be able to these APIs with the same access token. In order to use the full OCBCR package, please subscribe to all the APIs in the "Informational" section.
This package is not available on CRAN. Please use the following code to install OCBCR on RStudio.
install.packages('devtools') devtools::install_github('racheltlw/OCBCR', build_vignettes = TRUE)
This will download the OCBCR
package from my Github repository into your RStudio. Then you can load the package by calling library(OCBCR)
.
The OCBC API is rate limited at 10 API calls per minute, hence Sys.sleep(6)
has been included after the GET
API calls.
There are numberous OCBC Informational APIs available and these APIs are grouped into categories based on the information they provide. Usually, an R-package make these APIs accessible individually, with one function corresponding to one API. However, with many of the API calls being very similar, this process can be made more efficient. Each OCBCR function accesses a whole category of APIs, with the individual APIs being accessed by specifying the first argument of the function, the "type". (e.g By changing the argument account_type
in the ocbc_accounts
function, the user can access 6 different APIs.)
In total the OCBCR package makes 38 APIs accessible through 7 functions. The Locators and Rates functions also have more interesting functionalities such as plotting interactive maps and graphs.
This function makes the Locators API category easily accessible in R. The API allows the user to retrieve a list containing a dataframe of information about a specified type of loan, as well as a map (of Singapore or Malaysia) marking out all the locators in that dataframe, plotted according to latitude and longitude.
Here is an example of what you can expect when using ocbc_locators
The dataframe:
library(OCBCR) locators_example <- ocbc_locator(locator_type = "ATM", acctoken = Sys.getenv("ACC_TOKEN_OCBC"), category = 1, country = "SG") knitr::kable(head(locators_example[[1]])[ , 1:7]) #some formatting for display sake
And the map:
locators_example[[2]]
This function makes the Rates API category easily accessible in R. The API allows the user to retrieve a dataframe of information about the specified type of rate. Specifically for rate_type = "fixed deposit"
, the function returns a list containing a dataframe of information, as well as a graph of the fixed deposit interest rates by duration (month) of deposit.
local_currency
(Singapore or Malaysia), and for rate_ty[e = "forex"
they may also filter by foreign_currency
and hence find the specific exchange rate. Here is an example of what you can expect when using ocbc_rates
rates_example <- ocbc_rates("fixed deposit", acctoken = Sys.getenv("ACC_TOKEN_OCBC")) knitr::kable(head(rates_example[[1]])) rates_example[[2]]
This function makes the Accounts API category easily accessible in R. The API allows the user to retrieve a dataframe of information about a specified account.
?ocbc_accounts
Here is an example of what you can expect when using ocbc_accounts
accounts_example <- ocbc_accounts("Children", acctoken = Sys.getenv("ACC_TOKEN_OCBC"), country = "SG", productName = "Mighty Savers") accounts_example
This function makes the Cards API category easily accessible in R. There are 2 main types of information - advisory (card_type = "Credit Advisor
or "Debit Advisor"
) and rewards (card_type = "Credit Promotions"
or "Rewards"
).
card_type = "Credit"
) does not yield information about Credit Card products as the API currently does not return data. limit
(default is 10) to increase or decrease the number of items returned. This is applicable to promotions and rewards. Here is an example of what you can expect when using ocbc_cards
cards_example <- ocbc_cards("Rewards", acctoken = Sys.getenv("ACC_TOKEN_OCBC"), limit = "1") cards_example
This function makes the Insurance API category easily accessible in R. The API allows the user to retrieve a dataframe of information about a specified type of insurance.
Here is an example of what you can expect when using ocbc_insurance
insurance_example <- ocbc_insurance("Travel", acctoken = Sys.getenv("ACC_TOKEN_OCBC")) insurance_example
This function makes the Investments API category easily accessible in R. The API allows the user to retrieve a dataframe of information about a specified type of investment.
Here is an example of what you can expect when using ocbc_investments
investment_example <- ocbc_investments("Bonds", acctoken = Sys.getenv("ACC_TOKEN_OCBC")) investment_example
This function makes the Loans API category easily accessible in R. The API allows the user to retrieve a dataframe of information about a specified type of loan.
Here is an example of what you can expect when using ocbc_loans
loan_example <- ocbc_loans("Car", acctoken = Sys.getenv("ACC_TOKEN_OCBC")) loan_example
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.