[R-SIG-Finance] Call to specific IBrokers function never returns - How to catch this error ?
Jeff Ryan
jeff.a.ryan at gmail.com
Sun Oct 10 16:39:40 CEST 2010
This was patched in version on CRAN (0.2-9 - possibly even 0.2-8).
> library(IBrokers)
Loading required package: xts
Loading required package: zoo
IBrokers version 0.2-9: (alpha)
Implementing API Version 9.63
This software comes with NO WARRANTY. Not intended for production use!
See ?IBrokers for details
> tws <- twsConnect()
> contract <- twsEquity('OD7D','SMART',currency="EUR") # Corn ETF
> reqContractDetails(tws, contract)
[[1]]
List of 18
$ version : chr "6"
$ contract :List of 16
..$ conId : chr "41638042"
..$ symbol : chr "OD7D"
..$ sectype : chr "STK"
..$ exch : chr "SMART"
..$ primary : chr "FWB"
..$ expiry : chr ""
..$ strike : chr "0.0"
..$ currency : chr "EUR"
..$ right : chr ""
..$ local : chr "OD7D"
..$ multiplier : chr ""
..$ combo_legs_desc: chr ""
..$ comboleg : chr ""
..$ include_expired: chr ""
..$ secIdType : chr ""
..$ secId : chr ""
..- attr(*, "class")= chr "twsContract"
$ marketName : chr "XETRA"
$ tradingClass : chr "XETRA"
$ conId : chr "41638042"
$ minTick : chr "0.0010"
$ orderTypes : chr [1:35] "ACTIVETIM" "ADJUST" "ALERT" "ALLOC" ...
$ validExchanges: chr [1:5] "SMART" "FWB" "IBIS" "MIBSX" ...
$ priceMagnifier: chr "1"
$ underConId : chr "0"
$ longName : chr "ETFS CORN "
$ contractMonth : chr ""
$ industry : chr "Funds"
$ category : chr "Commodity Fund"
$ subcategory : chr "Commodity"
$ timeZoneId : chr "MET"
$ tradingHours : chr "20101010:CLOSED;20101011:0900-2000"
$ liquidHours : chr "20101010:CLOSED;20101011:0900-1730"
> contract <- twsEquity('OD7D','SMART',currency="USD") # Corn ETF
> reqContractDetails(tws, contract)
list()
Warning message:
In reqContractDetails(tws, contract) : error in contract details
Best,
Jeff
On Sun, Oct 10, 2010 at 4:07 AM, <me at censix.com> wrote:
> Hi to the list
>
> I am having some difficulties with a specific function from the otherwise
> extremely useful "IBrokers" package that connects an R session with a TWS.
> See the example code below.
>
> The "reqContractDetails" function that should return either the contract
> details (if the contract exists) or an error (if it doesnt) is giving me
> problems.
>
> if I run it with
>
> contract <- twsEquity('OD7D','SMART',currency="EUR") # Corn ETF
>
> then reqContractDetails(.....) returns the correct contract details
>
> if instead I misspecify the contract currency as "USD", then
> reqContractDetails(.....) is supposed to return an error, because the ETF
> is denominated in Euro. But the call NEVER returns unless I abort the
> command with crtl+c
>
> Ths behaviour is the same during and outside trading hours.
>
> My question is this:
>
> Is there any quick workaround I can use here, i.e. some kind of timeout
> mechanism within R in order to avoid that my code just stops executing and
> waits ad infinitum ?
>
> Thanks
>
> Soren
>
>
> ############################################################################################################
>
> ########## This requires a running tws or gw that accepts incoming
> connections on the standard port
> ########## Tested with IBrokers 0.2-7.
>
> require(IBrokers)
>
> tws <- twsConnect()
>
> tws #print connection information. for info purposes only
> reqCurrentTime(tws) # check the server's timestamp
>
> contract <- twsEquity('OD7D','SMART',currency="EUR") # Corn ETF
> #contract <- twsEquity('OD7D','SMART',currency="USD") # Corn ETF that
> does not exist
>
> #WARNING the reqContractDetails method will hang (never return!!) if
> contract does not exist or is misspecified. avoid it!
> reqContractDetails(tws,contract) # request contract details.
>
> tmpData<-NULL
> tmpData<-reqHistoricalData(tws,contract, barSize = "1 day", duration =
> "3 M") # request historical data
> (!is.null(tmpData)) && is.xts(tmpData) # did we get something back and
> is it an xts series ?
>
> twsDisconnect(tws) # disconnect from the TWS
>
> _______________________________________________
> 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.
> -- Also note that this is not the r-help list where general R questions should go.
>
--
Jeffrey Ryan
jeff.a.ryan at gmail.com
More information about the R-SIG-Finance
mailing list