Something like:
require(dplyr)
require(plyer)
require(data.table)
require(jsonlite)
require(httr)
require(rvest)
require(XML)
require(plyr)
COLORDER = c("symbol", "code", "type", "expiry", "strike", "premium", "bid", "ask", "volume", "open.interest", "retrieved")
# AUSTRALIAN OPTIONS --------------------------------------------------------------------------------------------------
# ASX is the Australian Securities Exchange.
URLASX = 'http://www.asx.com.au/asx/markets/optionPrices.do?by=underlyingCode&underlyingCode=%s&expiryDate=&optionType=B'
getOptionChainAsx <- function(symbol) {
url = sprintf(URLASX, symbol)
html <- read_html(url)
# Use the second element in the list (the first element gives data on the underlying stock)
#
options = (html %>% html_nodes("table.options") %>% html_table(header = TRUE))[[2]] %>%
plyr::rename(c("Bid" = "bid", "Offer" = "ask", "Openinterest" = "open.interest", "Volume" = "volume", "Expirydate" = "expiry",
"P/C" = "type", "Margin Price" = "premium", "Exercise" = "strike", "Code" = "code")) %>%
transform(
symbol = symbol,
code = code,
retrieved = Sys.time(),
open.interest = suppressWarnings(as.integer(gsub(",", "", open.interest))),