How to connect Interactive Brokers to R?

To connect Interactive Brokers to R you can use make use of the IBrokers package by Joshua Ulrich.

First, you have to log into your Trader Work Station (TWS) and change the Settings of your API.

Go to Edit -> Global Configurations -> API -> Settings and change them as in the picture below and save them.



To use the TWS and R togeather both programs need to be running simultaneously. Now start your R-Studio or any other program with which you can run R code. And insert the following chunk of code.

# IBrokers 

# Connect IB to R and check server version
tws <- twsConnect()

# Now you can work with IB in R
# For more functions check out the
# IBrokers documentation

# Disconnect IB from R

You should now be able to run commands for the TWS API through R.



This content is purely informative in nature and does not constitute any offer, inducement, recommendation, or legal or financial advice by the author. In particular, the published information is not to be understood to be an offer of sale of any registered or unregistered securities or an investment proposal of any kind. It is general information provided purely for information purposes and is based on proprietary knowledge, information furnished by third parties, and publicly accessible sources considered reliable by the author.



Leave a Reply

Your email address will not be published. Required fields are marked *