Skip to content
Prev 10519 / 15274 Next

IBrokers : quotes from futures combo and reqIds

I don't have a complete answer, but I don't think you directly request
a quote for a twsBAG.  You could get a quote for each leg and
calculate it yourself.  Below is an example.  I hope you don't mind if
I use the get_quote function from my twsInstrument package
(https://r-forge.r-project.org/R/?group_id=1113).  I don't know how IB
calculates the BidSize and AskSize of a combo, but you can look at how
I calculated it and see if it makes sense.

[I don't trade subscribe to market data for MATIF, so below I'll make
a combo between SPY and DIA.  Note that the ratio I chose is by no
means a recommendation -- I just picked a number that would make the
spread close to dollar neutral]

require("twsInstrument")
bag <- twsBAG(
    twsComboLeg(
        conId = "756733", #conId("SPY"),
        ratio = "1",
        action = "BUY",
        exchange = "SMART"
    )   ,
    twsComboLeg(
        conId = "73128548", #conId("DIA"),
        ratio = "1.06",
        action = "SELL",
        exchange = "SMART"
    )
)

## Get a quote for both legs

(tmp <- get_quote(c(bag$comboleg[[1]]$conId, bag$comboleg[[2]]$conId)))
#    BidSize BidPrice AskPrice AskSize   Last LastSize Volume
#SPY     108   137.45   137.46     138 137.45        3 385111
#DIA      25   129.10   129.11      23 129.09        1  10656

data.frame(BidSize=min(c(as.numeric(bag$comboleg[[1]]$ratio) * tmp$BidSize[1],
                   as.numeric(bag$comboleg[[2]]$ratio) * tmp$AskSize[2])),
           BidPrice=as.numeric(bag$comboleg[[1]]$ratio) * tmp$BidPrice[1] -
                    as.numeric(bag$comboleg[[2]]$ratio) * tmp$AskPrice[2],
           AskPrice=as.numeric(bag$comboleg[[1]]$ratio) * tmp$AskPrice[1] -
                    as.numeric(bag$comboleg[[2]]$ratio) * tmp$BidPrice[2],
           AskSize=min(c(as.numeric(bag$comboleg[[1]]$ratio) * tmp$AskSize[1],
                   as.numeric(bag$comboleg[[2]]$ratio) * tmp$BidSize[2])),
           row.names=paste(rownames(tmp), collapse="."))

#        BidSize BidPrice AskPrice AskSize
#SPY.DIA   24.38   0.5934    0.614    26.5

HTH,
Garrett
On Thu, Jul 19, 2012 at 8:18 AM, omerle <omerle at laposte.net> wrote: