[R-SIG-Finance] Historical FX Data via IBrokers API
Enrico Schumann
enricoschumann at yahoo.de
Wed Mar 14 12:20:06 CET 2012
Hi Glenn,
this works for me:
require("IBrokers")
contr <- twsCurrency(symbol = "GBP", currency = "JPY")
tws <- twsConnect(sample(1e6,1))
results <- reqHistoricalData(tws,
Contract = contr,
endDateTime = "20120301 09:00:00",
barSize = "5 mins",
duration = "5 D",
useRTH = 0,
whatToShow = "MIDPOINT")
twsDisconnect(tws)
head(results, 5)
## should be something like
GBP.JPY.Open GBP.JPY.High GBP.JPY.Low GBP.JPY.Close
2012-02-23 23:15:00 125.9100 125.9100 125.840 125.8825
2012-02-23 23:20:00 125.8825 125.8825 125.815 125.8150
2012-02-23 23:25:00 125.8150 125.8550 125.815 125.8350
2012-02-23 23:30:00 125.8350 125.8800 125.825 125.8350
2012-02-23 23:35:00 125.8350 125.8925 125.825 125.8575
###[...]
Regards,
Enrico
--
Enrico Schumann
Lucerne, Switzerland
http://nmof.net/
Am 14.03.2012 11:32, schrieb Glenn Dunster:
> Greetings,
>
> Is anybody here using the IB API and R to download historical FX data? I
> couldn't find any references to success or failure using RSeek or Googling.
>
> The response my attempts elicit suggest that the data isn't available,
> though I can fetch the same without problem using ActiveX/Excel. As I'm a R
> neophyte, I'd like to check firstly if my code is incorrect in my various
> attempts. Note that I've had no problem retrieving quotes and market data
> for the same currency:
>
> [1] "GBPJPY"
>> GBPJPY<- getContract("GBPJPY")
>> get_quote("GBPJPY")
> 2 -1 2104 Market data farm connection is OK:usfuture
> 2 -1 2104 Market data farm connection is OK:hkfarm
> 2 -1 2104 Market data farm connection is OK:cashfarm
> 2 -1 2104 Market data farm connection is OK:usfarm
> 2 -1 2106 HMDS data farm connection is OK:ushmds2a
> BidSize BidPrice AskPrice AskSize
> GBP.JPY 2e+06 131.275 131.31 1.5e+07
>
> > reqMktData(tws,twsCurrency("GBP"))
> <20120314 18:03:20.843750> id=1 symbol=GBP bidPrice: 1.57055 bidSize:
> 14310000
> <20120314 18:03:20.843750> id=1 symbol=GBP askPrice: 1.57065 askSize:
> 1000000
> <20120314 18:03:20.843750> id=1 symbol=GBP bidSize: 14310000
> <20120314 18:03:20.843750> id=1 symbol=GBP askSize: 1000000
> <20120314 18:03:20.843750> id=1 symbol=GBP highPrice: 1.57460
>
>> reqHistoricalData(tws, Contract=contract)
> TWS Message: 2 -1 2104 Market data farm connection is OK:usfuture
> TWS Message: 2 -1 2104 Market data farm connection is OK:hkfarm
> TWS Message: 2 -1 2104 Market data farm connection is OK:cashfarm
> TWS Message: 2 -1 2104 Market data farm connection is OK:usfarm
> TWS Message: 2 -1 2106 HMDS data farm connection is OK:ushmds2a
> waiting for TWS reply on GBP ....failed.
> NULL
> Warning message:
> In errorHandler(con, verbose, OK = c(165, 300, 366, 2104, 2106, :
> Historical Market Data Service error message:No data of type EODChart is
> available for the exchange 'IDEAL' and the security type 'Forex' and '1 m'
> and '1 day'
>
>> reqHistoricalData(tws,Contract=contract,endDateTime='20120302 17:00:00
> GMT', barSize='1 day', duration='2 W', useRTH="0",
> whatToShow='MIDPOINT',file="")
> waiting for TWS reply on GBP .....failed.
> NULL
> Warning message:
> In errorHandler(con, verbose, OK = c(165, 300, 366, 2104, 2106, :
> Historical Market Data Service error message:No data of type EODChart is
> available for the exchange 'IDEAL' and the security type 'Forex' and '2 W'
> and '1 day'
>
> > reqHistoricalData(tws,twsCurrency("GBP"))
> waiting for TWS reply on GBP ....failed.
> NULL
> Warning message:
> In errorHandler(con, verbose, OK = c(165, 300, 366, 2104, 2106, :
> Historical Market Data Service error message:No historical market data
> for GBP/CASH at IDEALPRO Last 1d
>
> Appreciate corrections or advice, thank you
>
> Glenn
More information about the R-SIG-Finance
mailing list