joshuaulrich / IBrokers

R API to Interactive Brokers Trader Workstation
65 stars 54 forks source link

function reqHistoricalData() stalls #25

Open cloudcell opened 4 years ago

cloudcell commented 4 years ago

Description

try downloading adjusted data using symbol "SXC", the function will just hang

Expected behavior

Would be nice to have a timeout, be that even an hour, that's a must. It's the problem with IB, it's trying to retrieve the data but it can't. You can see that when trying to plot a price graph within IB.

Minimal, reproducible example

contract <- twsEquity("SXC")
reqHistoricalData(conn=tws,
                             Contract=contract,
                             endDateTime="",
                             barSize = "1 hour",
                             duration = "10 Y",
                             useRTH = "1",
                             whatToShow = "ADJUSTED_LAST", 
                             timeFormat = "1",
                             tzone = "",
                             verbose = TRUE,
                             tickerId = "1")

Session Info

> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Linux Mint 19.3

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=en_NZ.UTF-8       LC_NUMERIC=C               LC_TIME=en_NZ.UTF-8        LC_COLLATE=en_NZ.UTF-8     LC_MONETARY=en_NZ.UTF-8   
 [6] LC_MESSAGES=en_NZ.UTF-8    LC_PAPER=en_NZ.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_NZ.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] dplyr_0.8.5     quantmod_0.4-16 TTR_0.23-6      plyr_1.8.6      IBrokers_0.9-12 xts_0.12-0      zoo_1.8-7      

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3       rstudioapi_0.11  magrittr_1.5     tidyselect_1.0.0 munsell_0.5.0    colorspace_1.4-1 lattice_0.20-40  R6_2.4.1        
 [9] rlang_0.4.5      fansi_0.4.1      tools_3.4.4      grid_3.4.4       gtable_0.3.0     utf8_1.1.4       cli_2.0.2        assertthat_0.2.1
[17] tibble_2.1.3     lifecycle_0.2.0  crayon_1.3.4     purrr_0.3.3      ggplot2_3.3.0    vctrs_0.2.4      curl_4.3         glue_1.3.2      
[25] compiler_3.4.4   pillar_1.4.3     scales_1.1.0     jsonlite_1.6.1   pkgconfig_2.0.3 
cloudcell commented 4 years ago

I've done some research on the subject by chatting with IB tech support. It turns out that "SMART" option does not work if a user is not subscribed to the data from all the exchanges that have the requested ticker name. Thus, IBroker will keep trying to get data with no success. I still think that some kind of timeout mechanism would be useful.

joshuaulrich commented 4 years ago

Thanks for reporting back! Maybe there's a way to get all the exchanges the ticker is listed on, then check the user's subscriptions?

cloudcell commented 4 years ago

1) As for locations at which the stock is listed, try this page: https://interactivebrokers.github.io/tws-api/classIBApi_1_1ScannerSubscription.html#ab36dca88091096dc2c8b19917f08461f see function "LocationCode". Maybe this function will help.

2) I doubt you can check user subscriptions using API... But you can probably check whether you're subscribed or not using error codes. See error codes "365" and "10090" here: https://interactivebrokers.github.io/tws-api/message_codes.html

PS tried reaching out to helpdesk three times today, but they are in the maintenance mode