Module: IB::Messages::Incoming

Extended by:
IB::Messages
Defined in:
lib/ib/messages/incoming.rb,
lib/ib/messages/incoming/alert.rb,
lib/ib/messages/incoming/ticks.rb,
lib/ib/messages/incoming/open_order.rb,
lib/ib/messages/incoming/order_status.rb,
lib/ib/messages/incoming/scanner_data.rb,
lib/ib/messages/incoming/contract_data.rb,
lib/ib/messages/incoming/market_depths.rb,
lib/ib/messages/incoming/next_valid_id.rb,
lib/ib/messages/incoming/real_time_bar.rb,
lib/ib/messages/incoming/execution_data.rb,
lib/ib/messages/incoming/historical_data.rb,
lib/ib/messages/incoming/portfolio_value.rb,
lib/ib/messages/incoming/abstract_message.rb,
lib/ib/messages/incoming/delta_neutral_validation.rb

Overview

Incoming IB messages (received from TWS/Gateway)

Defined Under Namespace

Modules: ContractAccessors Classes: AbstractMessage, AbstractTick, Alert, ContractData, DeltaNeutralValidation, ExecutionData, HistoricalData, MarketDepth, NextValidId, OpenOrder, OrderStatus, PortfolioValue, RealTimeBar, ScannerData

Constant Summary collapse

AccountValue =

Define short message classes in-line:

def_message([6, 2], [:key, :string],
                           [:value, :string],
                           [:currency, :string],
                           [:account_name, :string]) do
  "<AccountValue: #{}, #{key}=#{value} #{currency}>"
end
AccountUpdateTime =
def_message 8, [:time_stamp, :string]
NewsBulletins =
def_message 14, [:request_id, :int], # unique incrementing bulletin ID.
[:type, :int], # Type of bulletin. Valid values include:
#     1 = Regular news bulletin
#     2 = Exchange no longer available for trading
#     3 = Exchange is available for trading
[:text, :string], # The bulletin's message text.
[:exchange, :string]
ManagedAccounts =
def_message 15, [:accounts_list, :string]
ReceiveFA =

Receives previously requested FA configuration information from TWS.

def_message 16, [:type, :int], # type of Financial Advisor configuration data
#                    being received from TWS. Valid values include:
#                    1 = GROUPS, 2 = PROFILE, 3 = ACCOUNT ALIASES
[:xml, :string]
ScannerParameters =

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

def_message 19, [:xml, :string]
CurrentTime =

Receives the current system time on the server side.

def_message 49, [:time, :int]
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.

def_message 51, [:request_id, :int], [:xml, :string]
ContractDataEnd =
def_message 52, [:request_id, :int]
OpenOrderEnd =
def_message 53
AccountDownloadEnd =
def_message 54, [:account_name, :string]
ExecutionDataEnd =
def_message 55, [:request_id, :int]
MarketDataType =
def_message 58, [:request_id, :int], [:market_data_type, :int]
CommissionReport =
def_message 59, [:exec_id, :string],
[:commission, :decimal], # Commission amount.
[:currency, :string], # Commission currency
[:realized_pnl, :decimal_max],
[:yield, :decimal_max],
[:yield_redemption_date, :int]
ErrorMessage =

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

Error = Alert = def_message([4, 2],
[:error_id, :int],
[:code, :int],
[:message, :string])
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)
def_message [1, 6], AbstractTick,
[:ticker_id, :int],
[:tick_type, :int],
[:price, :decimal],
[:size, :int],
[:can_auto_execute, :int]
TickSize =
def_message [2, 6], AbstractTick,
[:ticker_id, :int],
[:tick_type, :int],
[:size, :int]
TickGeneric =
def_message [45, 6], AbstractTick,
[:ticker_id, :int],
[:tick_type, :int],
[:value, :decimal]
TickString =
def_message [46, 6], AbstractTick,
[:ticker_id, :int],
[:tick_type, :int],
[:value, :string]
TickEFP =
def_message [47, 6], AbstractTick,
[:ticker_id, :int],
[:tick_type, :int],
[:basis_points, :decimal],
[:formatted_basis_points, :string],
[:implied_futures_price, :decimal],
[:hold_days, :int],
[:dividend_impact, :decimal],
[:dividends_to_expiry, :decimal]
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.
TickOption =
def_message([21, 6], AbstractTick,
            [:ticker_id, :int],
            [:tick_type, :int],
            #                       What is the "not yet computed" indicator:
            [:implied_volatility, :decimal_limit_1], # -1 and below
            [:delta, :decimal_limit_2], #              -2 and below
            [:option_price, :decimal_limit_1], #       -1   -"-
            [:pv_dividend, :decimal_limit_1], #        -1   -"-
            [:gamma, :decimal_limit_2], #              -2   -"-
            [:vega, :decimal_limit_2], #               -2   -"-
            [:theta, :decimal_limit_2], #              -2   -"-
            [:under_price, :decimal_limit_1]) do

  "<TickOption #{type} for #{:ticker_id}: underlying @ #{under_price}, "+
      "option @ #{option_price}, IV #{implied_volatility}%, delta #{delta}, " +
      "gamma #{gamma}, vega #{vega}, theta #{theta}, pv_dividend #{pv_dividend}>"
end
TickSnapshotEnd =
def_message 57, [:ticker_id, :int]
ContractDetails =
ContractData =
        def_message([10, [6, 8]],
[:request_id, :int], # request id
[:contract, :symbol, :string],
[:contract, :sec_type, :string],
[:contract, :expiry, :string],
[:contract, :strike, :decimal],
[:contract, :right, :string],
[:contract, :exchange, :string],
[:contract, :currency, :string],
[:contract, :local_symbol, :string],

[:contract_detail, :market_name, :string], # extended
[:contract_detail, :trading_class, :string],
[:contract, :con_id, :int],
[:contract_detail, :min_tick, :decimal],
[:contract, :multiplier, :string],
[:contract_detail, :order_types, :string],
[:contract_detail, :valid_exchanges, :string],
[:contract_detail, :price_magnifier, :int],
[:contract_detail, :under_con_id, :int],
[:contract_detail, :long_name, :string],
[:contract, :primary_exchange, :string],
[:contract_detail, :contract_month, :string],
[:contract_detail, :industry, :string],
[:contract_detail, :category, :string],
[:contract_detail, :subcategory, :string],
[:contract_detail, :time_zone, :string],
[:contract_detail, :trading_hours, :string],
[:contract_detail, :liquid_hours, :string],
[:contract_detail, :ev_rule, :decimal],
[:contract_detail, :ev_multipler, :string],
[:sec_id_list_count, :int])
BondContractData =

ContractData

def_message [18, [4, 6]], ContractData,
[:request_id, :int],
[:contract, :symbol, :string],
[:contract, :sec_type, :string],
[:contract_detail, :cusip, :string],
[:contract_detail, :coupon, :decimal],
[:contract_detail, :maturity, :string],
[:contract_detail, :issue_date, :string],
[:contract_detail, :ratings, :string],
[:contract_detail, :bond_type, :string],
[:contract_detail, :coupon_type, :string],
[:contract_detail, :convertible, :boolean],
[:contract_detail, :callable, :boolean],
[:contract_detail, :puttable, :boolean],
[:contract_detail, :desc_append, :string],
[:contract, :exchange, :string],
[:contract, :currency, :string],
[:contract_detail, :market_name, :string], # extended
[:contract_detail, :trading_class, :string],
[:contract, :con_id, :int],
[:contract_detail, :min_tick, :decimal],
[:contract_detail, :order_types, :string],
[:contract_detail, :valid_exchanges, :string],
[:contract_detail, :valid_next_option_date, :string],
[:contract_detail, :valid_next_option_type, :string],
[:contract_detail, :valid_next_option_partial, :string],
[:contract_detail, :notes, :string],
[:contract_detail, :long_name, :string],
[:contract_detail, :ev_rule, :decimal],
[:contract_detail, :ev_multipler, :string],
[:sec_id_list_count, :int]
MarketDepthL2 =
def_message 13, MarketDepth, # Fields descriptions - see above
[:request_id, :int],
[:position, :int],
[:market_maker, :string], # The exchange hosting this order.
[:operation, :int],
[:side, :int],
[:price, :decimal],
[:size, :int]
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.

NextValidId = def_message(9, [:local_id, :int])
Classes =

Container for specific message classes, keyed by their message_ids

{}

Constants included from IB::Messages

CLIENT_VERSION, SERVER_VERSION

Method Summary

Methods included from IB::Messages

def_message