[R-SIG-Finance] IBrokers : quotes from futures combo and reqIds
Stergios Marinopoulos
stergios_marinopoulos at yahoo.com
Thu Jul 19 17:09:11 CEST 2012
In Java, if you create a proper BAG Contract you can use it with reqMktData() or
reqHistoricalData(). I imagine the same holds true in R as well. (I can send Java examples if interested.)
Try using IBrokers twsBAG() function to create a combo contract, and use the returned object as the contract to IBrokers's equivalent of reqMktData() and data should start streaming.
--
Stergios Marinopoulos
________________________________
From: G See <gsee000 at gmail.com>
To: omerle <omerle at laposte.net>
Cc: r-sig-finance at r-project.org
Sent: Thursday, July 19, 2012 10:37 AM
Subject: Re: [R-SIG-Finance] 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:
> Dear,
>
> 1 - Quotes from futures combo
>
> I need quotes from futures combo but I cant find how to find these quotes.
> I can place combo orders but I can't find how to get the quotes. For instance, I would
> like to have the quotes of the combo between ECO AUG12 (83617918) and ECO NOV12
> (87689647).
> Do you have any idea ?
> Which part of the IB API documentation should I check ?
> That's quite important for me !
>
> 2 - reqIds
>
> If I understand well reqIds, it doesnt give the next iDs from Interactive Broker but the
> last iDs + 1 of the R session or TWS. Sometimes it doesn't work for me because when I
> relaunch R or TWS it forgets the real last iDs.
> When the iDs count is relaunch ? How can I relaunch it ?
>
>
> Thanks a lot,
>
> Olivier MERLE
>
> Une messagerie gratuite, garantie à vie et des services en plus, ça vous tente ?
> Je crée ma boîte mail www.laposte.net
>
> _______________________________________________
> R-SIG-Finance at 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.
_______________________________________________
R-SIG-Finance at 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.
More information about the R-SIG-Finance
mailing list