Learn R Programming

IBrokers (version 0.10-2)

reqRealTimeBars: Request Real Time Bars from TWS

Description

Allows for streaming real-time bars to be handled in R

Usage

reqRealTimeBars(conn,
                Contract,
                whatToShow = "TRADES", 
                barSize = "5",
                useRTH = TRUE,
                playback = 1,
                tickerId = "1",
                file = "",
                verbose = TRUE,
                eventWrapper=eWrapper(),
                CALLBACK=twsCALLBACK,
                ...) 

cancelRealTimeBars(conn, tickerId)

Value

The real-time bar data requested.

Arguments

conn

a valid twsConnection or twsPlayback object

Contract

twsContract object(s) requested

tickerId

the ticker id to associate with the returned bars

whatToShow

what to show

barSize

bar size - currently on 5 secs is TWS supported

playback

playback speed adjustment

useRTH

regular trading hours (logical)

file

passed to internal cat calls. See associated help.

verbose

print diagnostics

eventWrapper

eventWrapper object

CALLBACK

main reciever callback

...

additional args to callback

Author

Jeffrey A. Ryan

Details

This function provides R level access to real time (5 second) bars returned by the TWS API. The Interactive Brokers documentation should be reference for the exact meaning of the returned data.

If the conn is a connection of data to be played back all other arguments are ignores, except for playback, which is a multiplier of the bar size in seconds. To force all data to be read without pause set this to 0.

Callbacks, via eventRealTimeBars and CALLBACK are designed to allow for R level processing of the real-time data stream.

eventWrapper allows for direct manipulation of the actual signal recieved. These may be user-defined functions taking the appropriate arguments. Each message recieved (each new bar) will invoke one of this callback. By default when nothing is specified, the code will call the default method for printing the results to the screen via 'cat'.

Note that the use of the argument 'file' will be passed to these 'cat' calls, and therefore it will be possible to use the functionality of 'cat' directly - e.g. piping output or writing to a connection. The simplest use of file would be to specify the name of a file, or open connection to append the output of the stream to.

The 'CALLBACK' argument is used for more control of the incoming results. This requires user-level error checking as well as TWS API interaction. It is here for advanced use and until documented should be left alone.

References

Interactive Brokers TWS API https://interactivebrokers.github.io/tws-api/index.html

See Also

twsConnect,twsContract,eWrapper

Examples

Run this code
if (FALSE) {
tws <- twsConnect()
contract <- twsEquity("QQQQ","SMART","ISLAND")
reqRealTimeBars(tws, contract)

# write to an open file connection
fh <- file('out.dat',open='a')
reqRealTimeBars(tws, contract, file=fh)
close(fh)
}

Run the code above in your browser using DataLab