0

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.

Duck
  • 39,058
  • 13
  • 42
  • 84
  • Yes, my TWS is open and is running. I am not sure what "IB gateway" is, though. – Bear Bile Farming is Torture Aug 19 '20 at 11:19
  • Have you set the trusted IP's at the bottom of the API settings? 127.0.0.1 needs to be created to be able to run the api code. And Enable ActiveX and Socket Clients. IB gateway is a version you can use if you don't want TWS to be open. Uses less resources, and is only for using with the API. But first get it working with TWS. You can read up on the other stuff later. – phiver Aug 19 '20 at 16:20
  • Under "API - Settings", There is a check box labeled "Allow connections from localhost only". This box was checked by default. the twsConnect function has a parameter called "host" which defaults to "localhost". That was the original setup that did not work. Using your advice, I unchecked that box and added the "127.0.0.1" as a trusted IP. then I ran twsConnect with the "host" parameter set to "127.0.0.1". It also did not work. Same error message except "localhost" was replaced with "127.0.0.1". As I understand it, "127.0.0.1" is just "localhost"? – Bear Bile Farming is Torture Aug 19 '20 at 20:16
  • The Read Only box was initially checked. I unchecked it again got the same error. – Bear Bile Farming is Torture Aug 20 '20 at 16:31
  • That did not work either. But as it turns out my account doesn't even have permissions to trade on IK yet. I just requested permissions. And one of the options were"United States (Algorithmic Trading Venue)". Maybe that's the reason. I'd report back – Bear Bile Farming is Torture Aug 21 '20 at 15:43
  • My account now has the permission to trade. I can confirm this as I performed an actual trade with my TWS. However, the issues persist. I cannot connect. Furthermore, I also tried using my Ubuntu machine, same error message. – Bear Bile Farming is Torture Aug 24 '20 at 20:11
  • 3
    It finally worked!. Turns out the "Enable ActiveX and Socket Clients" checkbox was unchecked. I checked it and it worked. – Bear Bile Farming is Torture Aug 29 '20 at 15:58

2 Answers2

4

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

1

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

File/ Global Configuration/ API/ Settings

and chek the ActiveX box

Mario
  • 11
  • 1