joshuaulrich / IBrokers

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

same day and historical intraday prices #29

Open Courvoisier13 opened 3 years ago

Courvoisier13 commented 3 years ago

Description

I've posted on stack this issue 2 weeks ago: https://stackoverflow.com/questions/66603261/ibrokers-r-api-and-same-day-intraday-prices

I am using reqHistoricalData to get 1 minutes intraday historical data. The market is open and I am not getting the same day's data. I only get previous trading day's data.

Is it possible to get the same day intraday bar data?

Expected behavior

I am expecting bars for the same day

Minimal, reproducible example

here is the code I am using, it only gives data for the previous day, not same day.

library(tidyverse)
library(IBrokers)
tws = twsConnect()
contract <- twsEquity('VOD','SMART')
VOD_intraday = IBrokers::reqHistoricalData(tws, Contract = contract, barSize = "1 min", duration = "1 D")
VOD_intraday %>% as.data.frame() %>% rownames_to_column(var = "time") %>% arrange(desc(time)) %>% head()

It's 10:28 GMT on 2021-03-29 and London is open. And here is the response - it only gives data from 2020-03-26:

> contract <- twsEquity('VOD','SMART')
> VOD_intraday = IBrokers::reqHistoricalData(tws, Contract = contract, barSize = "1 min", duration = "1 D")
waiting for TWS reply on VOD .... done.
> VOD_intraday %>% as.data.frame() %>% rownames_to_column(var = "time") %>% arrange(desc(time)) %>% head()
                 time VOD.Open VOD.High VOD.Low VOD.Close VOD.Volume VOD.WAP VOD.hasGaps VOD.Count
1 2021-03-26 19:59:00    18.86    18.88   18.85     18.88        281  18.866           0       165
2 2021-03-26 19:58:00    18.86    18.86   18.84     18.86        688  18.850           0       192
3 2021-03-26 19:57:00    18.86    18.86   18.85     18.86        132  18.855           0        62
4 2021-03-26 19:56:00    18.85    18.86   18.84     18.86        144  18.849           0        98
5 2021-03-26 19:55:00    18.84    18.85   18.83     18.85        101  18.839           0        66
6 2021-03-26 19:54:00    18.81    18.84   18.81     18.84        331  18.823           0       134

Instead of VOD, you can use SPY, MSFT or any US security while the US market is open

Session Info

R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

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

other attached packages:
 [1] IBrokers_0.9-12            tidyquant_1.0.2            PerformanceAnalytics_2.0.4 lubridate_1.7.9.2          timetk_2.6.0               quantmod_0.4.17           
 [7] TTR_0.24.2                 xts_0.12.1                 zoo_1.8-8                  forcats_0.5.0              stringr_1.4.0              dplyr_1.0.2               
[13] purrr_0.3.4                readr_1.4.0                tidyr_1.1.2                tibble_3.0.4               ggplot2_3.3.2              tidyverse_1.3.0           

loaded via a namespace (and not attached):
 [1] fs_1.5.0           DiceDesign_1.8-1   httr_1.4.2         tools_4.0.3        backports_1.2.0    utf8_1.1.4         R6_2.5.0           rpart_4.1-15       DBI_1.1.0         
[10] colorspace_2.0-0   yardstick_0.0.7    nnet_7.3-14        withr_2.3.0        tidyselect_1.1.0   curl_4.3           compiler_4.0.3     cli_2.2.0          rvest_0.99.0.9000 
[19] xml2_1.3.2         scales_1.1.1       quadprog_1.5-8     tune_0.1.2         digest_0.6.27      pkgconfig_2.0.3    parallelly_1.21.0  lhs_1.1.1          dbplyr_2.0.0      
[28] rlang_0.4.10       readxl_1.3.1       rstudioapi_0.13    generics_0.1.0     jsonlite_1.7.2     magrittr_2.0.1     tbl2xts_1.0.4      Matrix_1.2-18      Quandl_2.10.0     
[37] Rcpp_1.0.6         munsell_0.5.0      fansi_0.4.1        GPfit_1.0-8        lifecycle_0.2.0    furrr_0.2.1        pROC_1.16.2        stringi_1.5.3      yaml_2.2.1        
[46] MASS_7.3-53        plyr_1.8.6         recipes_0.1.15     grid_4.0.3         parallel_4.0.3     listenv_0.8.0      crayon_1.3.4       fortunes_1.5-4     lattice_0.20-41   
[55] haven_2.3.1        splines_4.0.3      hms_0.5.3          pillar_1.4.7       dials_0.0.9        codetools_0.2-16   parsnip_0.1.4      reprex_0.3.0       glue_1.4.2        
[64] rsample_0.0.8      modelr_0.1.8       vctrs_0.3.6        foreach_1.5.1      cellranger_1.1.0   gtable_0.3.0       future_1.20.1      assertthat_0.2.1   gower_0.2.2       
[73] prodlim_2019.11.13 broom_0.7.2        class_7.3-17       survival_3.2-7     timeDate_3043.102  iterators_1.0.13   lava_1.6.8.1       workflows_0.2.1    globals_0.14.0    
[82] ellipsis_0.3.1     ipred_0.9-9