Hi Olivier/everyone,

Comments inline:

On Tue, Nov 2, 2010 at 11:06 AM, Olivier MERLE <omerle@agritel.com> wrote:

>  Hi everyone,
>
>
>
> 1st question :
>
> I am currently working on IBrokers and I don't understant how the data are
> assigned in the eWrapper environment.
>
> For instance, you have eventWrapper$get.Data("bidPrice"). I don't
> understant in which part of the code bidPrice is assigned to the
> environment.
>

You'll have to do a bit of digging to really understand what is happening.
 I've outlined this in quite a few talks and slides are available in
numerous places.  In short, the eWrapper creates a .Data environment.  This
environment is _in_ the eWrapper (closure).  The .Data can be anything you
want/need, but in the default case for eWrapper.MktData.CSV or eWrapper.data
it is an xts object (or list of them, if more than one symbol is being
pulled).

e.g.
> eWrapper.data
function (n)
{
    eW <- eWrapper(NULL)
    eW$assign.Data("data", rep(list(structure(.xts(matrix(rep(NA_real_,
        7), nc = 7), 0), .Dimnames = list(NULL, c("BidSize",
        "BidPrice", "AskPrice", "AskSize", "Last", "LastSize",
        "Volume")))), n))
    eW$tickPrice <- function(curMsg, msg, timestamp, file, ...) {
        tickType = msg[3]
        msg <- as.numeric(msg)
        id <- msg[2]
        data <- eW$get.Data("data")
        attr(data[[id]], "index") <- as.numeric(Sys.time())
        nr.data <- NROW(data[[id]])
        if (tickType == .twsTickType$BID) {
            data[[id]][nr.data, 1:2] <- msg[5:4]
 ...

2 nd question :
>
> I would like to save bid/ask quotes for multiple underlying in a SQL
> Database in real time. What is the best way to implement this thing ?
>
Don't.  Use eWrapper.MktData.CSV() to dump to multiple text files on the
fly.  This will be the fastest way to handle the data - as you'll have no
SQL/db overhead.  If you want to be fancier you can delve into my
indexing/mmap packages.  I also do fee-based consulting to help clients
accomplish there individual goals.  If you want it in SQL for another
program, I'd again point to my services or going the route of pipes, mmap,
etc.

> I know that I have to modify eWrapper to save data in the environment as I
> like and then take these data and save it in my SQL Database (but where).
>

See above comment.


> 3 rd question :
>
> Why I cant see the function `e_open_order`in my R environment even its called inside IBrokers function ?
> This function can be found on http://ibrokers.googlecode.com/svn-history/r91/trunk/R/eventHandlers.R
>
>
Basic R.  If the package has a NAMESPACE, objects may not be exported.  To
access you need to add in the package name:

> IBrokers:::e_open_order
function (msg, contents, ...)
{
    eoo <- list(contract = twsContract(conId = contents[3], symbol =
contents[4],
        sectype = contents[5], expiry = contents[6], strike = contents[7],
        right = contents[8], exch = contents[9], currency = contents[10],
        local = contents[11], combo_legs_desc = contents[66],
        primary = NULL, include_expired = NULL, comboleg = NULL,
        multiplier = NULL), order = twsOrder(orderId = contents[2],
        action = contents[12], totalQuantity = contents[13],
        orderType = contents[14], lmtPrice = contents[15], auxPrice =
contents[16],
        tif = contents[17], ocaGroup = contents[18], account =
contents[19],
        openClose = contents[20], origin = contents[21], orderRef =
contents[22],
        clientId = contents[23], permId = contents[24], outsideRTH =
contents[25],
        hidden = contents[26], discretionaryAmt = contents[27],
        goodAfterTime = contents[28], faGroup = contents[30],
        faMethod = contents[31], faPercentage = contents[32],
        faProfile = contents[33], goodTillDate = contents[34],
        rule80A = contents[35], percentOffset = contents[36],
        settlingFirm = contents[37], shortSaleSlot = contents[38],
        designatedLocation = contents[39], auctionStrategy = contents[40],
        startingPrice = contents[41], stockRefPrice = contents[42],
        delta = contents[43], stockRangeLower = contents[44],
        stockRangeUpper = contents[45], displaySize = contents[46],
        blockOrder = contents[47], sweepToFill = contents[48],
        allOrNone = contents[49], minQty = contents[50], ocaType =
contents[51],
        eTradeOnly = contents[52], firmQuoteOnly = contents[53],
        nbboPriceCap = contents[54], parentId = contents[55],
        triggerMethod = contents[56], volatility = contents[57],
        volatilityType = contents[58], deltaNeutralOrderType =
contents[59],
        deltaNeutralAuxPrice = contents[60], continuousUpdate =
contents[61],
        referencePriceType = contents[62], trailStopPrice = contents[63],
        basisPoints = contents[64], basisPointsType = contents[65],
        scaleInitLevelSize = contents[67], scaleSubsLevelSize =
contents[68],
        scalePriceIncrement = contents[69], clearingAccount = contents[70],
        clearingIntent = contents[71], notHeld = contents[72],
        whatIf = contents[75]), orderstate = twsOrderState(status =
contents[76],
        initMargin = contents[77], maintMargin = contents[78],
        equityWithLoan = contents[79], commission = contents[80],
        minCommission = contents[81], maxCommission = contents[82],
        commissionCurrency = contents[83], warningText = contents[84]))
    eoo <- structure(eoo, class = "eventOpenOrder")
    cat("TWS OpenOrder:", paste("orderId=", eoo$order$orderId,
        sep = ""), paste("conId=", eoo$contract$conId, sep = ""),
        paste("symbol=", eoo$contract$symbol, sep = ""), paste("status=",
            eoo$orderstate$status, sep = ""), "\n")
    eoo
}
<environment: namespace:IBrokers>

wowser --- thats quite a chunk of code!

> 4 th question :
>
> I feel that I lack some theoritical background in computer science. Do you
> any advice or book for upgrading my knowledge in this field ?
>

I'll be offering classes on IBrokers etc. via lemnica.com (new name, same
company) early next year, but that isn't _now_.  For now, reading the list
is an absolutely brilliant way to learn.  Of course, all of the R books now
available are also great to have/read - "R in a Nutshell" and Chamber's
recent "Software for Data Analysis" are good bookshelf fodder. The former is
big enough to be a paperweight if you don't find it useful as a reference.

Best,
Jeff

>
>
> Thanks,
>
>
>
> Olivier
>
> _______________________________________________
> R-SIG-Finance@stat.math.ethz.ch 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
jeff.a.ryan@gmail.com

	[[alternative HTML version deleted]]

