Search code examples
c#ib-api

Interactive Brokers IBAPI - Cannot get tick-by-tick data for ForEx contract


I am using Interactive Brokers IBAPI to connect to a running instance of TWS.

I am wanting to obtain tick-by-tick data for the forex pair EUR/USD. (The particular pair does really not matter.)

I am using the following API function to request the tick-by-tick data:

_ibClient.ClientSocket.reqTickByTickData(tickerId, contract, "Last", 0, false);

This call works fine for a stock contract like, say, TSLA.

The error message being returned in the case of a ForEx contract is:

Error. Id: 2, Code: 10189, Msg: Failed to request tick-by-tick data:No historical market data for EUR/CASH@FXSUBPIP Last 0

I am not requesting historical data.

Here is the contract object:

contract = new Contract
{
    Symbol = "EUR",
    SecType = "CASH",
    Exchange = "IDEALPRO",
    PrimaryExch = "IDEALPRO",
    Currency = "USD",
};

Here are the contents of the log file:

Next Valid Id: 1
Account list: *********
Market data farm connection is OK:cashfarm
Market data farm connection is OK:usfarm
HMDS data farm connection is OK:euhmds
HMDS data farm connection is OK:cashhmds
HMDS data farm connection is OK:fundfarm
HMDS data farm connection is OK:ushmds
Sec-def data farm connection is OK:secdefil
Error. Id: 2, Code: 10189, Msg: Failed to request tick-by-tick data:No historical market data for EUR/CASH@FXSUBPIP Last 0

Can anyone help me understand why I am not able to obtain tick-by-tick data for a ForEx contract?


Solution

  • Last is not available for forex, only midpoint. It doesn't trade on an exchange.

    _ibClient.ClientSocket.reqTickByTickData(tickerId, contract, "MidPoint", 0, false);

    http://interactivebrokers.github.io/tws-api/tick_data.html

    n.b. It will come in public void tickByTickMidPoint(int reqId, long time, double midPoint)