Within IBrokers you would simply extend the eWrapper.MktDepth.CSV eWrapper
method to save what you would like (and how you would like, csv in this
instance).

Note that the reqMktDepth call won't return Last prices, as that is within
the reqMktData (IB API) call. You will instead need to have both requests
running and collecting the data required.  I don't have example code for
this, but it wouldn't be hard to do.  You could effectively share one data
object within R (and the eWrappers) and update this object at each new
message.

You could also [more easily] use the prebuilt *.CSV methods in the package
to save the incoming messages to individual files, and then use standard
R/xts tools to rebuild the book at whatever granularity you wanted.

In short, the tools are all there, you just need to cut/paste/borrow/extend
to convert the messages into whatever form you want.

With respect to timestamps, you are 100% correct that they are not provided
by the API for most data. I do think Last has something of a timestamp
attached, though I don't think the default wrappers are using it. Instead
the timestamps are getting created when the message is processed. This
gives a more realistic view into when you can act on the data anyway, but
clearly isn't the only solution you could desire - especially for the Last
value.

If I get a chance to provide a working example, I will pass along.

HTH
Jeff

P.S.  As John's follow-up mentions, the shim is a pretty neat bit of code.
Russ is a regular at the R/Finance conferences as well, and a stellar
resource on the topic.  Take a look at both of these set-ups to figure out
how you can solve your problem.

ex (not tested, and probably missing something since I am writing this
quickly from memory - though it is all documented in the package and/or
slide decks I've given):

tws <- twsConnect()
reqMktDepth(tws, twsSTK("AAPL"), eventWrapper=eWrapper.MktDepth.CSV(),
file='aapl.mkdepth.csv')


Calls ===>
> eWrapper.MktDepth.CSV
function ()
{
    eW <- eWrapper(NULL)
    eW$updateMktDepth <- function(curMsg, msg, timestamp, file,
        ...) {
        e_update_mkt_depth_csv(NULL, msg, timestamp, file, ...)
    }
    eW
}
<environment: namespace:IBrokers>

### at each new message.
> IBrokers:::e_update_mkt_depth
function (msg, contents, timeStamp, file, ...)
{
    id <- as.numeric(contents[2])
    file <- file[[id]]
    if (!is.null(timeStamp))
        cat("<", as.character(timeStamp), ">,", sep = "", file = file,
            append = TRUE)
    position <- contents[3]
    operation <- switch(contents[4], `0` = "insert", `1` = "update",
        `2` = "delete")
    side <- ifelse(contents[5] == "1", "bid", "ask")
    price <- contents[6]
    size <- contents[7]
    cat(paste("id=", id, ",", sep = ""), file = file, append = TRUE)
    cat(paste("pos=", position, ",", sep = ""), file = file,
        append = TRUE)
    cat(paste("operation=", operation, ",", sep = ""), file = file,
        append = TRUE)
    cat(paste("side=", side, ",", sep = ""), file = file, append = TRUE)
    cat(paste("price=", price, ",", sep = ""), file = file, append = TRUE)
    cat(paste("size=", size, sep = ""), "\n", file = file, append = TRUE)
}
<environment: namespace:IBrokers>
>





On Sat, Jul 20, 2013 at 11:38 PM, ganesha0701 <ganesha0701@gmail.com> wrote:

> I came across IBrokers, and was impressed. My goal is to save real time
> data through the Interactive Brokers API and am looking to use it.
>
> The data I need should be in the following format
>
> timestamp, product, bid1Price, bid1Size, ask1Price, ask1Size,bid2Price,
> bid2Size, ask2Price, ask2Size,bid3Price, bid3Size, ask3Price,
> ask3Size,bid4Price, bid4Size, ask4Price, ask4Size,bid5Price, bid5Size,
> ask5Price, ask5Size, last Trade Price, last Trade Size
>
> So basically I am looking for all the 5 levels and the last trade
> information if there was any.
>
> I understand their API and know that I need to call the reqMarketDepth
> method. The problem is that they don't really give any time stamp
> information.
>
> So my question is can I use this package to do the above, if yes, how do
> you generate the time stamp info? How do I get the last trade info?
>
> I would be grateful to you if you could offer any light on the matter.
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>



-- 
Jeffrey Ryan
jeffrey.ryan@lemnica.com

www.lemnica.com

	[[alternative HTML version deleted]]

