[R-SIG-Finance] Historical FX Data via IBrokers API

G See gsee000 at gmail.com
Wed Mar 14 15:20:32 CET 2012


You have given us code that uses an object called "contract," but you
have not shown us what "contract" is.

If I define contract like this (using the twsInstrument package as you have)

contract <- getContract("GBPJPY")

then your code works for me.

1> contract <- getContract("GBPJPY")
Connected with clientId 100.
Request complete: GBP CASH JPY.
Disconnected.
> tws <- ibgConnect()  ## or twsConnect() or ConnectIB()
> 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 ....... done.
1329717600,126.5975,126.840,125.785,126.225,-1,-1.000,0,-1
1329804000,126.2375,126.660,125.6575,125.820,-1,-1.000,0,-1
1329890400,125.780,126.6275,125.605,125.800,-1,-1.000,0,-1
1329976800,125.775,126.210,125.475,125.955,-1,-1.000,0,-1
1330063200,125.910,128.980,125.815,128.885,-1,-1.000,0,-1
1330322400,129.4025,129.785,126.9625,127.5425,-1,-1.000,0,-1
1330408800,127.5275,128.245,126.6925,127.935,-1,-1.000,0,-1
1330495200,127.925,129.6225,127.825,129.1475,-1,-1.000,0,-1
1330581600,129.2475,129.6025,128.7575,129.4375,-1,-1.000,0,-1
1330668000,129.395,130.110,129.1525,129.530,-1,-1.000,0,-1
NULL

Garrett

On Wed, Mar 14, 2012 at 5:32 AM, Glenn Dunster <glenn at aligncapital.com> wrote:
> 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
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> 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