Learn R Programming

IBrokers (version 0.10-2)

twsConnect: Establish, Check or Terminate a Connection to TWS or IBG

Description

Functions to initiate, check, or disconnect from the Trader Workstation (TWS) or IB Gateway (IBG).

Usage

twsConnect(clientId = 1, host = 'localhost', 
           port = 7496, verbose = TRUE, timeout = 5,
           filename = NULL, blocking=.Platform$OS.type=="windows")
ibgConnect(clientId = 1, host = 'localhost', 
           port = 4001, verbose = TRUE, timeout = 5,
           filename = NULL, blocking=.Platform$OS.type=="windows")

twsDisconnect(twsconn)

isConnected(twsconn) is.twsConnection(x) is.twsPlayback(x)

Value

A twsconn object.

Arguments

clientId

the unique client id to associate with

host

the host server

port

the port that the TWS is listening on

verbose

should the connection attempt be verbose

timeout

length in seconds before aborting attempt

filename

file containing recorded TWS data

blocking

should a blocking connection be established. See details.

twsconn

a valid twsConnection object

x

a connection to be checked

Author

Jeffrey A. Ryan

Details

Returns a twsConnection object for use in subsequent TWS API calls. Attempting to create another connection to the server with the same clientId will result in an error.

If filename is set to a file containing data recorded in the standard TWS format - calls using this connection will playback the recorded data.

While the IBrokers package is fully cross-platform, the behavior of sockets varies by operating system implementation. In general, setting blocking=TRUE on Windows (the default on Windows) results in more consistent and reliable connections. This option is only exposed to enable debugging of platform differences and optimization - and is not intended to be altered except in those cases.

References

Interactive Brokers: https://www.interactivebrokers.com

Examples

Run this code
if (FALSE) {
tws <- twsConnect()
twsDisconnect(tws)
}

Run the code above in your browser using DataLab