reqMktData {IBrokers}R Documentation

Request Market Data Feed from TWS

Description

Allows for streaming market data to be handled in R.

Usage

reqMktData(conn, 
           Contract,
           tickGenerics = "100,101,104,106,165,221,225,236",
           snapshot = FALSE,
           tickerId = "1",
           timeStamp = TRUE,
           playback = 1,
           file = "",
           verbose = TRUE,
           eventTickPrice,
           eventTickSize,
           eventTickOption,
           eventTickGeneric,
           eventTickString,
           eventTickEFP,
           CALLBACK, ...)

cancelMktData(conn,tickerId)

Arguments

conn a valid twsConnection or twsPlayback connection
Contract twsContract object(s) requested data for
tickGenerics a comman delimited string of generic tick types
snapshot should snapshot data be returned
tickerId the ticker id to associate with the returned data
timeStamp include R time stamps
playback playback speed adjustment
file passed to internal cat calls. See associated help
verbose print diagnostics?
eventTickPrice callback function, if any
eventTickSize callback function, if any
eventTickOption callback function, if any
eventTickGeneric callback function, if any
eventTickString callback function, if any
eventTickEFP callback function, if any
CALLBACK main reciever callback, if any
... additional args

Details

This function provides R level access to market data streams as returned by the TWS API. The Interactive Brokers documentation should be reference for the exact meaning of the returned data.

timeStamps is unique to the R API in that each incoming signal will be marked with a (potentially) unique timestamp. Alternatively it is possible to pass a formatting string for use in format(Sys.time()). To suppress the time stamp set the argument to NULL. This is not sent by the TWS - merely prepended to the output by R.

Callbacks, via eventTickPrice, eventTickSize, eventTickOption, eventTickGeneric, eventTickString, eventTickEFP, or CALLBACK are designed to allow for R level processing of the real-time data stream.

The first six correspond to actions based upon the actual signal recieved. These may be user-defined functions taking the appropriate arguments. Each message recieved (each update to the market data) will invoke one of these callbacks, depending on the message type. 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 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.

Value

The book depth.

Note

As R is single threaded - this request will run until interupted by an error or by user action. Both will clean up after themselves when appropriate.

Author(s)

Jeffrey A. Ryan

References

Interactive Brokers API: http://individuals.interactivebrokers.com/php/apiguide/apiguide.htm

See Also

twsConnect,twsContract

Examples

## Not run: 
tws <- twsConnect()
contract <- twsEquity("QQQQ","SMART","ISLAND")
reqMktData(tws, contract)

# write to an open file connection
fh <- file('out.dat',open='a')
reqMktData(tws, contract, file=fh)
close(fh)
## End(Not run)

[Package IBrokers version 0.1-3 Index]