[R-SIG-Finance] Call to specific IBrokers function never returns - How to catch this error ?

me at censix.com me at censix.com
Sun Oct 10 11:07:46 CEST 2010


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



More information about the R-SIG-Finance mailing list