Search code examples
ryahoo-financequantmod

Why getSymbols from quantmod keeps fail to connect in R?


I am using getSymbols from quantmod package in R quite a long now but the last several days when i try to download some data i get the same error:

 library(quantmod)
> getSymbols("TSLA", from = "2011-01-01", to = "2022-01-31",auto.assign = TRUE)
Warning: TSLA download failed; trying again.
Error in getSymbols.yahoo(Symbols = "TSLA", env = <environment>, verbose = FALSE,  : 
  Unable to import “TSLA”.
TSLA download failed after two attempts. Error message:
Failed to connect to query2.finance.yahoo.com port 443: Timed out
> getSymbols("TSLA", from = "2021-01-01", to = "2022-01-31",auto.assign = TRUE)
Warning: TSLA download failed; trying again.
Error in getSymbols.yahoo(Symbols = "TSLA", env = <environment>, verbose = FALSE,  : 
  Unable to import “TSLA”.
TSLA download failed after two attempts. Error message:
Failed to connect to query1.finance.yahoo.com port 443: Timed out

Why is that happening ? I am not under firewall protection or proxy limitation.


Solution

  • If you are not able to fix quantmod, theres also tidyquant

    library(tidyquant)
    
    tq_get("TSLA", 
           from = "2011-01-01", 
           to = "2022-01-31")
    
    # A tibble: 2,788 x 8
       symbol date        open  high   low close  volume
       <chr>  <date>     <dbl> <dbl> <dbl> <dbl>   <dbl>
     1 TSLA   2011-01-03  5.37  5.4   5.18  5.32  6.42e6
     2 TSLA   2011-01-04  5.33  5.39  5.20  5.33  5.94e6
     3 TSLA   2011-01-05  5.30  5.38  5.24  5.37  7.23e6
     4 TSLA   2011-01-06  5.37  5.6   5.36  5.58  1.03e7
     5 TSLA   2011-01-07  5.6   5.72  5.58  5.65  1.12e7
     6 TSLA   2011-01-10  5.63  5.74  5.61  5.69  6.71e6
     7 TSLA   2011-01-11  5.72  5.74  5.38  5.39  8.55e6
     8 TSLA   2011-01-12  5.40  5.48  5.30  5.39  4.82e6
     9 TSLA   2011-01-13  5.39  5.39  5.23  5.24  3.62e6
    10 TSLA   2011-01-14  5.23  5.32  5.12  5.15  5.96e6
    # ... with 2,778 more rows, and 1 more variable:
    #   adjusted <dbl>