Volatil3
Volatil3

Reputation: 14988

Interactive Brokers: Unable to fetch Forex Historical data

I am trying IB very the first time. I am trying to fetch historical data of $EUR but I am getting an error:

Error 162, reqId 3: Historical Market Data Service error message:No historical market data for EUR/CASH@FXSUBPIP Last 1800, contract: Contract(secType='CASH', symbol='EUR', exchange='IDEALPRO', currency='USD')

Below is my code:

import datetime

from ib_insync import *

if __name__ == '__main__':
    ib = IB()
    r = ib.connect('127.0.0.1', port=7497, clientId=1)
    contract = Contract()
    contract.symbol = "EUR"
    contract.secType = "CASH"
    contract.currency = "USD"
    contract.exchange = "IDEALPRO"

    data = ib.reqHistoricalData(
        contract=contract,
        endDateTime='',
        durationStr='100 D',
        barSizeSetting='30 mins',
        useRTH=True,
        whatToShow='ADJUSTED_LAST'
    )

Upvotes: 3

Views: 1743

Answers (2)

A_Trader
A_Trader

Reputation: 26

The issue here is not on the definition of the FOREX contract itself, but the bar settings requested.

durationStr='100 D',
barSizeSetting='30 mins',

The barSizeSetting is not available for the durationStr selected. If you check the TWS GUI and pull the historical data chart for the FX contract you'll see the lowest bar size available for 100 Day duration is 2 hours.

You should always check if the functionality you are demanding from the API is available through the TWS GUI. IBKR's API talks to either TWS or IBGateway which in turn send the request to IBKR. If the functionality is not available through the GUI it most likely is not available through the API.

Upvotes: 1

brian
brian

Reputation: 10979

https://interactivebrokers.github.io/tws-api/historical_bars.html#available_products_hd

You can see that whatToShow='ADJUSTED_LAST' needs to be something available for forex like MIDPOINT. Obviously there are no dividends to adjust for.

Also, there is no real forex exchange and comprehensive data, all you get is what is happening at IB.

Upvotes: 1

Related Questions