Description Usage Arguments Details Value Note Author(s) References See Also Examples
Allows for streaming real-time bars to be handled in R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | reqRealTimeBars(conn,
Contract,
whatToShow = "TRADES",
barSize = "5",
useRTH = TRUE,
playback = 1,
tickerId = "1",
file = "",
verbose = TRUE,
eventWrapper=eWrapper(),
CALLBACK=twsCALLBACK,
...)
cancelRealTimeBars(conn, tickerId)
|
conn |
a valid |
Contract |
|
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 |
verbose |
print diagnostics |
eventWrapper |
eventWrapper object |
CALLBACK |
main reciever callback |
... |
additional args to callback |
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.
The real-time bar data requested.
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.
Jeffrey A. Ryan
Interactive Brokers TWS API http://individuals.interactivebrokers.com/php/apiguide/apiguide.htm
twsConnect
,twsContract
,eWrapper
1 2 3 4 5 6 7 8 9 10 11 | ## Not run:
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)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.