Skip to content

Commit

Permalink
fix: closes #15
Browse files Browse the repository at this point in the history
  • Loading branch information
aravindhebbali committed Nov 14, 2024
1 parent 121b44b commit d11884a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 162 deletions.
156 changes: 0 additions & 156 deletions R/ticker.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,162 +246,6 @@ Ticker <- R6::R6Class(

},

#' @field option_chain Option chain data for all expiration dates for a given symbol
option_chain = function() {

path <- 'v7/finance/options/'
end_point <- paste0(path, self$symbol)
url <- modify_url(url = private$base_url, path = end_point)
qlist <- list(getAllData = 'True', corsDomain = private$cors_domain)

if (!curl::has_internet()) {
message("No internet connection.")
return(invisible(NULL))
}

resp <- GET(url, query = qlist)
parsed <- fromJSON(content(resp, "text", encoding = "UTF-8"),
simplifyVector = FALSE)

if (http_error(resp)) {

message(
cat(
"Yahoo Finance API request failed", '\n',
paste('Status:', status_code(resp)), '\n',
paste('Type:', http_status(resp)$category), '\n',
paste('Mesage:', parsed$quoteSummary$error$code), '\n',
paste('Description:', parsed$quoteSummary$error$description, '\n'),
sep = ''
)
)

return(invisible(NULL))
} else {

data <-
parsed %>%
use_series(optionChain) %>%
use_series(result) %>%
extract2(1) %>%
use_series(options)

calls <-
data %>%
map_dfr('calls')

calls$option_type <- 'call'

puts <-
data %>%
map_dfr('puts')

puts$option_type <- 'put'

result <- rbind(calls, puts)
names(result) <- str_replace_all(names(result), '[A-Z]', private$snake_case)

result$expiration <- as_datetime(result$expiration)
result$last_trade_date <- as_datetime(result$last_trade_date)

col_order <- c('expiration', 'option_type', 'contract_symbol', 'strike', 'currency', 'last_price', 'change', 'percent_change', 'open_interest', 'bid', 'ask', 'contract_size', 'last_trade_date', 'implied_volatility', 'in_the_money', 'volume')

option_chain <- result[, col_order]
return(option_chain)
}

},

#' @field option_expiration_dates Option expiration dates
option_expiration_dates = function() {

path <- 'v7/finance/options/'
end_point <- paste0(path, self$symbol)
url <- modify_url(url = private$base_url, path = end_point)
qlist <- list(getAllData = 'True', corsDomain = private$cors_domain)

if (!curl::has_internet()) {
message("No internet connection.")
return(invisible(NULL))
}

resp <- GET(url, query = qlist)
parsed <- fromJSON(content(resp, "text", encoding = "UTF-8"),
simplifyVector = FALSE)

if (http_error(resp)) {

message(
cat(
"Yahoo Finance API request failed", '\n',
paste('Status:', status_code(resp)), '\n',
paste('Type:', http_status(resp)$category), '\n',
paste('Mesage:', parsed$quoteSummary$error$code), '\n',
paste('Description:', parsed$quoteSummary$error$description, '\n'),
sep = ''
)
)

return(invisible(NULL))
} else {

parsed %>%
use_series(optionChain) %>%
use_series(result) %>%
extract2(1) %>%
use_series(expirationDates) %>%
map_dbl(extract) %>%
as_datetime() %>%
date()

}

},

#' @field option_strikes Option strikes
option_strikes = function() {

path <- 'v7/finance/options/'
end_point <- paste0(path, self$symbol)
url <- modify_url(url = private$base_url, path = end_point)
qlist <- list(getAllData = 'True', corsDomain = private$cors_domain)

if (!curl::has_internet()) {
message("No internet connection.")
return(invisible(NULL))
}

resp <- GET(url, query = qlist)
parsed <- fromJSON(content(resp, "text", encoding = "UTF-8"),
simplifyVector = FALSE)

if (http_error(resp)) {

message(
cat(
"Yahoo Finance API request failed", '\n',
paste('Status:', status_code(resp)), '\n',
paste('Type:', http_status(resp)$category), '\n',
paste('Mesage:', parsed$quoteSummary$error$code), '\n',
paste('Description:', parsed$quoteSummary$error$description, '\n'),
sep = ''
)
)

return(invisible(NULL))
} else {

parsed %>%
use_series(optionChain) %>%
use_series(result) %>%
extract2(1) %>%
use_series(strikes) %>%
map_dbl(extract)

}

},

#' @field recommendations Recommended symbols
recommendations = function() {

Expand Down
6 changes: 0 additions & 6 deletions man/Ticker-class.Rd

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

0 comments on commit d11884a

Please sign in to comment.