[R-SIG-Finance] retrieving option info from IB

Wind windspeedo99 at gmail.com
Thu Jun 4 19:43:59 CEST 2009


I have figured out how to get market data for future options with IBrokers.

>oc<-reqContractDetails(tws, twsContract("GC","FOP",exch="NYMEX",primary="",expiry="",
				strike="",currency="USD",right="",local="",multiplier="100",NULL,NULL,"0"))
>length(oc)
[1] 1480

>temp<-lapply(oc,function(x){if ((x$contract$strike=="1000.0") & (substr(x$contract$expiry,1,6)=="200909")) x else NULL  })
>temp1<-temp[!sapply(temp, is.null)]
>temp2<-temp1[[1]]
>reqMktData(tws, temp2$contract)

<20090605 01:39:56.089000> id=1 symbol= Volume: 41
<20090605 01:39:56.091000> id=1 symbol= highPrice: 55.5
<20090605 01:39:56.093000> id=1 symbol= lowPrice: 51.4
<20090605 01:39:56.094000> id=1 symbol= bidOption: 0.2925249666770512
0.49009769315987844
<20090605 01:39:56.097000> id=1 symbol= askOption: 0.30040373020930494
0.49204912017993013
<20090605 01:39:56.098000> id=1 symbol= lastOption: 0.2930042176111911
0.49021807490565755
<20090605 01:39:56.606000> id=1 symbol= bidOption: 0.2925249666770512 -2
<20090605 01:39:56.607000> id=1 symbol= askOption: 0.30040373020930494 -2
<20090605 01:39:56.610000> id=1 symbol= lastOption: 0.2930042176111911 -2

I guess my codes could be optimized furthur.

Now there is only one issue to be settled: how to get only the current
bid, ask and size for one time instead of the continuous data feed.



On Thu, Jun 4, 2009 at 10:28 PM, Jeff Ryan <jeff.a.ryan at gmail.com> wrote:
> Hi Wind,
>
> Most of IBrokers behaves 1:1 with the "official" API from Interactive
> Brokers.  That is meant to provide a smaller learning curve when
> coming off the official API, but at the cost of being forced to deal
> with some of the quirks of the platform as well.
>
> That said, it is *not* a simple wrapper to the API though.  Many
> design decisions were made to make it more productive for an R user,
> as well as more productive from a trading perspective than the
> standard API.  The eWrapper structure and using R in general makes it
> more productive than all the other APIs in my opinion.
>
> With respect to the contract information, that is really hit or miss.
> I'll look into creating a 'best practices' or FAQ to help pool our
> collective wisdom --- maybe a simple wiki would be a good start.
>
> For getting snapshot information, IB's interface (API) is lacking.  I
> have that on a list of things to try and put together from what the
> API *can* do (it can't do what you want per se), and will be looking
> to incorporate that into a future release.
>
> The newest quantmod has a function called "getOptionChain" which pulls
> from Yahoo.  Obviously yahoo data caveats apply, but it is a decent
> start to getting snapshots.
>
> More documentation for IBrokers and quantmod is coming, as well as a
> presentation at the upcoming Rmetrics conference in Switzerland.  For
> those not signed up yet, take a look at www.rmetrics.org for more
> information.
>
> HTH,
> Jeff
>
> On Thu, Jun 4, 2009 at 9:10 AM, Wind <windspeedo99 at gmail.com> wrote:
>> I have successfully retrieved price info from IB via IBrokers for stocks and
>> simple options.  The package is very efficient.Yet I could not get info on
>> future option.
>>
>>> oc<-reqContractDetails(tws, twsOption(local="", right="",symbol="QQQQ"))
>>> length(oc)
>> [1] 1018
>>> oc<-reqContractDetails(tws, twsOption(local="",right="",symbol="GC"))
>> Error in reqContractDetails(tws, twsOption(local = "", right = "", symbol =
>> "GC")) :
>>  Unable to complete ContractDetails request
>>> oc<-reqContractDetails(tws,
>> twsOption(local="",right="",exch="NYMEX",symbol="GC"))
>> Error in reqContractDetails(tws, twsOption(local = "", right = "", exch =
>> "NYMEX",  :
>>  Unable to complete ContractDetails request
>>
>> By the way, how could we retrieving the option chain,  just the current bid,
>> ask, and size.  A snap shot only.
>>  I have only find functions for data feed and historical data download.
>>
>> Any suggestion would be appreciated.
>>
>> Wind
>>
>>        [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-SIG-Finance at 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.
>>
>
>
>
> --
> Jeffrey Ryan
> jeffrey.ryan at insightalgo.com
>
> ia: insight algorithmics
> www.insightalgo.com
>



More information about the R-SIG-Finance mailing list