Re-Routing CFDs

View as MarkdownOpen in Claude

IB does not provide market data for certain types of instruments, such as stock CFDs and forex CFDs. If a stock CFD or forex CFD is entered into a TWS watchlist, TWS will automatically display market data for the underlying ticker and show a ‘U’ icon next to the instrument name to indicate that the data is for the underlying instrument.

From the API, when level 1 or level 2 market data is requested for a stock CFD or a forex CFD, a callback is made to the functions EWrapper.rerouteMktDataReq or EWrapper.rerouteMktDepthReq respectively with details about the underlying instrument in IB’s database which does have market data.

EWrapper.rerouteMktDataReq (

reqId: int. Request identifier used to track data.

conId: int. Contract identifier of the underlying instrument which has market data.

exchange: int. Primary exchange of the underlying.
)

Returns conid and exchange for CFD market data request re-route.

1def rerouteMktDataReq(self, reqId: int, conId: int, exchange: str):
2 print("Re-route market data request. ReqId:", reqId, "ConId:", conId, "Exchange:", exchange)

EWrapper.rerouteMktDepthReq (

reqId: int. Request identifier used to track data.

conId: int. Contract identifier of the underlying instrument which has market data.

exchange: int. Primary exchange of the underlying.
)

Returns the conId and exchange for an underlying contract when a request is made for level 2 data for an instrument which does not have data in IB’s database. For example stock CFDs and index CFDs.

1def rerouteMktDepthReq(self, reqId: int, conId: int, exchange: str):
2 print("Re-route market depth request. ReqId:", reqId, "ConId:", conId, "Exchange:", exchange)