module IB::Messages::Incoming

Incoming IB messages (received from TWS/Gateway)

Constants

AccountDownloadEnd
AccountUpdateTime
AccountValue

Define short message classes in-line:

BondContractData
Classes

Container for specific message classes, keyed by their message_ids

CommissionReport
ContractDataEnd
ContractDetails
CurrentTime

Receives the current system time on the server side.

DeltaNeutralValidation

The server sends this message upon accepting a Delta-Neutral DN RFQ

  • see API Reference p. 26

ErrorMessage

Called Error in Java code, but in fact this type of messages also deliver system alerts and additional (non-error) info from TWS.

ExecutionData
ExecutionDataEnd
FundamentalData

Receive Reuters global fundamental market data. There must be a subscription to Reuters Fundamental set up in Account Management before you can receive this data.

HistoricalData

HistoricalData contains following @data: General:

:request_id - The ID of the request to which this is responding
:count - Number of Historical data points returned (size of :results).
:results - an Array of Historical Data Bars
:start_date - beginning of returned Historical data period
:end_date   - end of returned Historical data period

Each returned Bar in @data Array contains this data:

:date - The date-time stamp of the start of the bar. The format is
   determined by the RequestHistoricalData formatDate parameter.
:open -  The bar opening price.
:high -  The high price during the time covered by the bar.
:low -   The low price during the time covered by the bar.
:close - The bar closing price.
:volume - The volume during the time covered by the bar.
:trades - When TRADES historical data is returned, represents number of trades
         that occurred during the time period the bar covers
:wap - The weighted average price during the time covered by the bar.
:has_gaps - Whether or not there are gaps in the data.
ManagedAccounts
MarketDataType
MarketDepth
MarketDepthL2
NewsBulletins
NextValidID

This message is always sent by TWS automatically at connect. The IB::Connection class subscribes to it automatically and stores the order id in its @next_local_id attribute.

OpenOrder

OpenOrder is the longest message with complex processing logics

OpenOrderEnd
OrderStatus

:status - String: Displays the order status. Possible values include:

  • PendingSubmit - indicates that you have transmitted the order, but have not yet received confirmation that it has been accepted by the order destination. NOTE: This order status is NOT sent back by TWS and should be explicitly set by YOU when an order is submitted.

  • PendingCancel - indicates that you have sent a request to cancel the order but have not yet received cancel confirmation from the order destination. At this point, your order cancel is not confirmed. You may still receive an execution while your cancellation request is pending. NOTE: This order status is not sent back by TWS and should be explicitly set by YOU when an order is canceled.

  • PreSubmitted - indicates that a simulated order type has been accepted by the IB system and that this order has yet to be elected. The order is held in the IB system until the election criteria are met. At that time the order is transmitted to the order destination as specified.

  • Submitted - indicates that your order has been accepted at the order destination and is working.

  • Cancelled - indicates that the balance of your order has been confirmed canceled by the IB system. This could occur unexpectedly when IB or the destination has rejected your order.

  • ApiCancelled - canceled via API

  • Filled - indicates that the order has been completely filled.

  • Inactive - indicates that the order has been accepted by the system (simulated orders) or an exchange (native orders) but that currently the order is inactive due to system, exchange or other issues.

:why_held - This property contains the comma-separated list of reasons for

order to be held. For example, when TWS is trying to locate shares for
a short sell, the value used to indicate this is 'locate'.
PortfolioValue
RealTimeBar

RealTimeBar contains following @data:

:request_id - The ID of the *request* to which this is responding
:time - The date-time stamp of the start of the bar. The format is offset in
        seconds from the beginning of 1970, same format as the UNIX epoch time
:bar - received RT Bar
ReceiveFA

Receives previously requested FA configuration information from TWS.

ScannerData

This method receives the requested market scanner data results. ScannerData contains following @data: :request_id - The ID of the request to which this row is responding :count - Number of data points returned (size of :results). :results - an Array of Hashes, each hash contains a set of

data about one scanned Contract:
:contract - a full description of the contract (details).
:distance - Varies based on query.
:benchmark - Varies based on query.
:projection - Varies based on query.
:legs - Describes combo legs when scan is returning EFP.
ScannerParameters

Receives an XML document that describes the valid parameters that a scanner subscription can have (for outgoing RequestScannerSubscription message).

TickEFP
TickGeneric
TickOptionComputation

This message is received when the market in an option or its underlier moves. TWS option model volatilities, prices, and deltas, along with the present value of dividends expected on that options underlier are received. TickOption message contains following @data:

:ticker_id - Id that was specified previously in the call to reqMktData()
:tick_type - Specifies the type of option computation (see TICK_TYPES).
:implied_volatility - The implied volatility calculated by the TWS option
                      modeler, using the specified :tick_type value.
:delta - The option delta value.
:option_price - The option price.
:pv_dividend - The present value of dividends expected on the options underlier
:gamma - The option gamma value.
:vega - The option vega value.
:theta - The option theta value.
:under_price - The price of the underlying.
TickPrice

The IB code seems to dispatch up to two wrapped objects for this message, a tickPrice and sometimes a tickSize, which seems to be identical to the TICK_SIZE object.

Important note from chuckcaplan.com/twsapi/index.php/void%20tickPrice%28%29 :

“The low you get is NOT the low for the day as you'd expect it to be. It appears IB calculates the low based on all transactions after 4pm the previous day. The most inaccurate results occur when the stock moves up in the 4-6pm aftermarket on the previous day and then gaps open upward in the morning. The low you receive from TWS can be easily be several points different from the actual 9:30am-4pm low for the day in cases like this. If you require a correct traded low for the day, you can't get it from the TWS API. One possible source to help build the right data would be to compare against what Yahoo lists on finance.yahoo.com/q?s=ticker under the ”Day's Range“ statistics (be careful here, because Yahoo will use anti-Denial of Service techniques to hang your connection if you try to request too many bytes in a short period of time from them). For most purposes, a good enough approach would start by replacing the TWS low for the day with Yahoo's day low when you first start watching a stock ticker; let's call this time T. Then, update your internal low if the bid or ask tick you receive is lower than that for the remainder of the day. You should check against Yahoo again at time T+20min to handle the occasional case where the stock set a new low for the day in between T-20min (the real time your original quote was from, taking into account the delay) and time T. After that you should have a correct enough low for the rest of the day as long as you keep updating based on the bid/ask. It could still get slightly off in a case where a short transaction setting a new low appears in between ticks of data that TWS sends you. The high is probably distorted in the same way the low is, which would throw your results off if the stock traded after-hours and gapped down. It should be corrected in a similar way as described above if this is important to you.”

IB then emits at most 2 events on eWrapper:

tickPrice( tickerId, tickType, price, canAutoExecute)
tickSize( tickerId, sizeTickType, size)
TickSize
TickSnapshotEnd
TickString