简体   繁体   中英

Cannot connect to TWS using IBrokers with R

The output of my code:

library(IBrokers)
tws <- twsConnect(port=7496)

Error in socketConnection(host = host, port = port, open = "ab", blocking = blocking) : 
  cannot open the connection
In addition: Warning message:
In socketConnection(host = host, port = port, open = "ab", blocking = blocking) :
  localhost:7496 cannot be opened

I have checked my Global Configurations in the TWS. The port is in fact 7496.

> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Linux Mint 20

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

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

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

other attached packages:
[1] IBrokers_0.9-12 xts_0.12-0      zoo_1.8-8      

loaded via a namespace (and not attached):
[1] compiler_3.6.3  tools_3.6.3     grid_3.6.3      lattice_0.20-40

I am using the latest of Linux Mint. My IB account has been approved and funded.

It finally worked.. Turns out the "Enable ActiveX and Socket Clients" checkbox was unchecked. I checked it and it worked.

It also worked for me! Log in to TWS and go to

File/ Global Configuration/ API/ Settings

and chek the ActiveX box

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM