For a specific socket connection, set the market data type to one of REALTIME (initial setting for all new sockets), FROZEN, DELAYED, or DELAYED_FROZEN. In InteractiveTradeR, this function should not be called on its own. Rather, it is used internally by other req_ functions, such as req_mkt_data. req_market_data_type() is included in InteractiveTradeR to cover the hypothetical case in which the user might need it.

req_market_data_type(mktDataType, channel = NULL)

Arguments

mktDataType

Either:

  1. String having one of the following values: "REALTIME", "FROZEN", "DELAYED", or "DELAYED_FROZEN".

  2. Integer from 1 to 4, inclusive, corresponding respectively to each of the above choices (e.g., mktDataType = 3 will set the market data type to "DELAYED").

channel

One of the following:

  • Not Specified (Default): Opens a new connection to IB, uses it to issue the request and retrieve the response, and closes connection behind itself upon completion.

  • The Name of a Sock: Character vector, length 1. The name of an open, connected socket in the sock_drawer; e.g., "master", "tws", or "sock_123"

  • Numeric Client ID: Numeric, length 1. The client ID for which open orders are to be retrieved; e.g., 0, 874, 123. If a client ID is passed, and no socket in the sock_drawer is connected on that ID, then a new socket will be opened on that ID, and closed upon function exit.

  • A sockconn Connection: An open connection object of class "sockconn", connected to the IB API; e.g., sock_drawer$tws

The Market Data Types

The type of market data retrieved on a given sock can be set to one of the values below. Note that the difference between REALTIME, FROZEN and DELAYED_REALTIME, DELAYED_FROZEN is that the DELAYED data may be obtained for free on an IB paper account without a data subscription and with no actual funds deposited.

REALTIME:

Streaming market data (live), fed to the socket in real time. Market Data Subscriptions are required to make use of this setting.

FROZEN:

Also requires Market Data Subscriptions. If utilized, this mode will send the last quote available for an asset in the event that there is no REALTIME price available at the time of of a call to req_mkt_data(); for example, if the call is made outside of trading hours.

DELAYED:

Does not require any data subscriptions, but will return data delayed by 15 to 20 minutes.

DELAYED_FROZEN:

Same behavior as FROZEN, except applies to DELAYED data as opposed to REALTIME and does not require any data subscriptions.

Market data types are described in IB's official documentation here: Market Data Types.

By setting up subscriptions on sockets set to different market types, you may have multiple market data subscriptions running simultaneously on different market types. This can be handy in use cases for which REALTIME market data is needed for a certain data stream, but DELAYED market data will suffice for a different stream for which a subscription is not available/desired.

See also

Other market data: cancel_mkt_data(), req_mkt_data()