joshuaulrich / TTR

Technical analysis and other functions to construct technical trading rules with R
GNU General Public License v2.0
326 stars 102 forks source link

stockSymbols times out #66

Closed joshuaulrich closed 4 years ago

joshuaulrich commented 6 years ago
symbols <- TTR::stockSymbols()
# Fetching AMEX symbols...
# Error in file(file, "rt") : cannot open the connection
# In addition: Warning message:
# In file(file, "rt") : InternetOpenUrl failed: 'The operation timed out'

Thanks to @f40lms for reporting the issue in https://github.com/joshuaulrich/quantmod/issues/240.

ethanbsmith commented 6 years ago

Hi Josh, Just posting, since i figured once you were poking around, you might find this useful:

I had no idea this function existed, so I already rolled my own. you may find using this ftp site easier than screen scraping html. other than a trailer row with metadata, the file is pretty easy to parse and make sense of. It also does not have sub-sector data. Obviously i use data.table, but should be fairly straight forward to convert to just base classes

tab = fread("ftp://ftp.nasdaqtrader.com/symboldirectory/nasdaqtraded.txt", sep = "|", header = T, fill = T, showProgress = F)
if (NROW(tab) > 1 && startsWith(trimws(tab[.N, 1]), "File Creation Time")) {tab <- tab[1:(.N-1)]]

Also, i used to pull data from https://www.otcmarkets.com/research/stock-screener for OTC, but they recently moved around links and broke my code. I have now moved to a paid vendor for that, so i don't have anything working on that now. It does look like they have a download link, if you're feeling masochistic ;)

rochefort2010 commented 5 years ago

Howdy

I would like to politely ask whether it is still possible to retrieve a comprehensive list of Top 6,000+ U.S. stocks on NYSE, NASDAQ, and AMEX in the rank order of market capitalization. The prior TTR function stockSymbols() seems to be dysfunctional. Is there a similar alternative? Many thanks in advance.

Kind regards!!

Andy

martin1007 commented 4 years ago

Hello,

Has this bug been fixed?

Thanks, Martin

joshuaulrich commented 4 years ago

Hi @martin1007. I just ran the code using the latest version of TTR on CRAN (0.23-4) and it worked for me. Did you try it and have an issue?

R> symbols <- TTR::stockSymbols()
Fetching AMEX symbols...
Fetching NASDAQ symbols...
Fetching NYSE symbols...
R> str(symbols)
'data.frame':   6957 obs. of  8 variables:
 $ Symbol   : chr  "AAMC" "AAU" "ACU" "ACY" ...
 $ Name     : chr  "Altisource Asset Management Corp" "Almaden Minerals, Ltd." "Acme United Corporation." "AeroCentury Corp." ...
 $ LastSale : num  10 0.728 19.66 6.319 30.34 ...
 $ MarketCap: chr  "$15.91M" "$81.3M" "$65.9M" "$9.77M" ...
 $ IPOyear  : int  NA 2015 1988 NA NA NA 2018 NA 2014 NA ...
 $ Sector   : chr  "Finance" "Basic Industries" "Capital Goods" "Technology" ...
 $ Industry : chr  "Real Estate" "Precious Metals" "Industrial Machinery/Components" "Diversified Commercial Services" ...
 $ Exchange : chr  "AMEX" "AMEX" "AMEX" "AMEX" ...
clarchoi commented 4 years ago

cannot run the stockSymbols()

R>symbols <- TTR::stockSymbols() Fetching AMEX symbols... Error in names(x) <- value : 'names' attribute [8] must be the same length as the vector [1]

joshuaulrich commented 4 years ago

@clarchoi that is because of #83, which has been fixed and is on CRAN. The Windows binaries have not been built for the new version yet, so you either need to build from source or wait for CRAN to build them. It usually takes a couple days.

joshuaulrich commented 4 years ago

I'm closing this because I can't replicate the timeout now, though I could initially replicate it.

@ethanbsmith sorry I never responded to your comment. Thanks for the suggestion to use that nasdaq ftp file. Others have suggested it too. I like the idea, but it would break existing functionality. As you noted, some of the fields returned by the current function are not in the ftp file.

clarchoi commented 4 years ago

@joshuaulrich The issue is solved. Thank you very much!

wilmeragsgh commented 4 years ago

@clarchoi Hey how are you? We're currently having the same issue of

Error in names(x) <- value : 'names' attribute [8] must be the same length as the vector [1]

If you don't mind, what was your solution for it?

clarchoi commented 4 years ago

Just update R as 3.6.1 and TTR package

rezar362 commented 4 years ago

Hi, I have a similar issue on AWS, all of the firewall rules are whitelisted:

stockSymbols() Fetching AMEX symbols...

It halts and looks like nothing is happening, here are my session Info:

sessionInfo() R version 4.0.2 (2020-06-22) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 18.04.4 LTS

Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1 LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

locale: [1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8
[4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8
[7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] dplyr_1.0.0 reshape2_1.4.4 lubridate_1.7.9 quantmod_0.4.17 [5] TTR_0.23-6 xts_0.12-0 zoo_1.8-8

loaded via a namespace (and not attached): [1] Rcpp_1.0.5 magrittr_1.5 tidyselect_1.1.0 lattice_0.20-41 [5] R6_2.4.1 rlang_0.4.7 stringr_1.4.0 plyr_1.8.6
[9] tools_4.0.2 grid_4.0.2 ellipsis_0.3.1 tibble_3.0.3
[13] lifecycle_0.2.0 crayon_1.3.4 purrr_0.3.4 vctrs_0.3.2
[17] curl_4.3 glue_1.4.1 stringi_1.4.6 compiler_4.0.2
[21] pillar_1.4.6 generics_0.0.2 pkgconfig_2.0.3