module IB::Messages::Outgoing

Outgoing IB messages (sent to TWS/Gateway)

Constants

CancelCalculateImpliedVolatility
CancelCalculateOptionPrice
CancelFundamentalData

Data format is: @data = { :id => request_id }

CancelHistoricalData
CancelMarketData

Data format is: @data = { :id => ticker_id}

CancelMarketDepth
CancelNewsBulletins
CancelOrder

Data format is: @data ={ :id => local_id of order to cancel }

CancelRealTimeBars
CancelScannerSubscription
Classes

Container for specific message classes, keyed by their message_ids

ExerciseOptions

data = { :id => ticker_id (int),

:contract => IB::Contract,
:exercise_action => int, 1 = exercise, 2 = lapse
:exercise_quantity => int, The number of contracts to be exercised
:account => string,
:override => int: Specifies whether your setting will override the
             system's natural action. For example, if your action
             is "exercise" and the option is not in-the-money, by
             natural action the option would not exercise. If you
             have override set to "yes" the natural action would be
             overridden and the out-of-the money option would be
             exercised. Values are:
                    - 0 = do not override
                    - 1 = override
PlaceOrder

Data format is { :id => int: local_id,

:contract => Contract,
:order => Order }
ReplaceFA

data = { :fa_data_type => int, :xml => String }

RequestAccountUpdates

@data = { :subscribe => boolean,

:account_code => Advisor accounts only. Empty ('') for a standard account. }
RequestAllOpenOrders

Request the open orders placed from all clients and also from TWS. Each open order will be fed back through the OpenOrder and OrderStatus messages ONCE. Note this does not re-bind those Orders to requesting Client! Use RequestAutoOpenOrders to request such re-binding.

RequestAutoOpenOrders

Request that newly created TWS orders be implicitly associated with this client. When a new TWS order is created, the order will be associated with this client and automatically fed back through the OpenOrder and OrderStatus messages. It is a 'continuous' request such that it gets turned 'on' when called with a TRUE auto_bind parameter. When it's called with FALSE auto_bind, new TWS orders will not bind to this client going forward. Note that TWS orders can only be bound to clients with a client_id of 0. TODO: how to properly test this? data = { :auto_bind => boolean }

RequestCalculateImpliedVolatility

data = { :request_id => int, :contract => Contract,

:option_price => double, :under_price => double }
RequestCalculateOptionPrice

data = { :request_id => int, :contract => Contract,

:volatility => double, :under_price => double }
RequestContractDetails

data => { :id => request_id (int), :contract => Contract }

Special case for options: “wildcards” in the Contract fields retrieve Option chains

strike = 0 means all strikes
right = "" meanns both call and put
expiry = "" means all expiries
expiry = "2013" means all expiries in 2013
expiry = "201311" means all expiries in Nov 2013

You'll get several ContractData (10) messages back if there is more than one match. When all the matches are delivered you'll get ContractDataEnd (52) message.

RequestCurrentTime
RequestExecutions

When this message is sent, TWS responds with ExecutionData messages, each containing the execution report that meets the specified criteria. @data={:id => int: :request_id,

:client_id => int: Filter the results based on the clientId.
:acct_code => Filter the results based on based on account code.
              Note: this is only relevant for Financial Advisor accts.
:sec_type =>  Filter the results based on the order security type.
:time =>      Filter the results based on execution reports received
              after the specified time - format "yyyymmdd-hh:mm:ss"
:symbol   =>  Filter the results based on the order symbol.
:exchange =>  Filter the results based on the order exchange
:side =>  Filter the results based on the order action: BUY/SELL/SSHORT
RequestFA

data = { :fa_data_type => int }

RequestFundamentalData

Send this message to receive Reuters global fundamental data. There must be a subscription to Reuters Fundamental set up in Account Management before you can receive this data. data = { :id => int: :request_id,

:contract => Contract,
:report_type => String: one of the following:
         'estimates' - Estimates
         'finstat'   - Financial statements
          'snapshot' - Summary   }
RequestGlobalCancel
RequestHistoricalData

Messages that request bar data have special processing of @data

RequestIds

Request the next valid ID that can be used when placing an order. Responds with NextValidId message, and the id returned is that next valid Id for orders. That ID will reflect any autobinding that has occurred (which generates new IDs and increments the next valid ID therein). @data = { :number of ids requested => int } NB: :number option is ignored by TWS!

RequestManagedAccounts
RequestMarketData

@data={:id => int: ticker_id - Must be a unique value. When the market data

                          returns, it will be identified by this tag,
:contract => IB::Contract, requested contract.
:tick_list => String: comma delimited list of requested tick groups:
  Group ID - Description - Requested Tick Types
  100 - Option Volume (currently for stocks) - 29, 30
  101 - Option Open Interest (currently for stocks) - 27, 28
  104 - Historical Volatility (currently for stocks) - 23
  106 - Option Implied Volatility (currently for stocks) - 24
  162 - Index Future Premium - 31
  165 - Miscellaneous Stats - 15, 16, 17, 18, 19, 20, 21
  221 - Mark Price (used in TWS P&L computations) - 37
  225 - Auction values (volume, price and imbalance) - 34, 35, 36
  233 - RTVolume - 48
  236 - Shortable - 46
  256 - Inventory - ?
  258 - Fundamental Ratios - 47
  411 - Realtime Historical Volatility - 58
:snapshot => bool: Check to return a single snapshot of market data and
             have the market data subscription canceled. Do not enter any
             :tick_list values if you use snapshot. }
RequestMarketDataType

The API can receive frozen market data from Trader Workstation. Frozen market data is the last data recorded in our system. During normal trading hours, the API receives real-time market data. If you use this function, you are telling TWS to automatically switch to frozen market data AFTER the close. Then, before the opening of the next trading day, market data will automatically switch back to real-time market data. :market_data_type = 1 for real-time streaming, 2 for frozen market data

RequestMarketDepth

data = { :id => ticker_id (int), :contract => Contract, :num_rows => int }

RequestNewsBulletins

data = { :all_messages => boolean }

RequestOpenOrders

Request the open orders that were placed from THIS client. Each open order will be fed back through the OpenOrder and OrderStatus messages ONCE. NB: Client with a client_id of 0 will also receive the TWS-owned open orders. These orders will be associated with the client and a new orderId will be generated. This association will persist over multiple API and TWS sessions.

RequestRealTimeBars

Messages that request bar data have special processing of @data

RequestScannerParameters

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

RequestScannerSubscription

Start receiving market scanner results through the ScannerData messages. @data = { :id => ticker_id (int),

:number_of_rows => int: number of rows of data to return for a query.
:instrument => The instrument type for the scan. Values include
                              'STK', - US stocks
                              'STOCK.HK' - Asian stocks
                              'STOCK.EU' - European stocks
:location_code => Legal Values include:
                         - STK.US - US stocks
                         - STK.US.MAJOR - US stocks (without pink sheet)
                         - STK.US.MINOR - US stocks (only pink sheet)
                         - STK.HK.SEHK - Hong Kong stocks
                         - STK.HK.ASX - Australian Stocks
                         - STK.EU - European stocks
:scan_code => The type of the scan, such as HIGH_OPT_VOLUME_PUT_CALL_RATIO.
:above_price => double: Only contracts with a price above this value.
:below_price => double: Only contracts with a price below this value.
:above_volume => int: Only contracts with a volume above this value.
:market_cap_above => double: Only contracts with a market cap above this
:market_cap_below => double: Only contracts with a market cap below this value.
:moody_rating_above => Only contracts with a Moody rating above this value.
:moody_rating_below => Only contracts with a Moody rating below this value.
:sp_rating_above => Only contracts with an S&P rating above this value.
:sp_rating_below => Only contracts with an S&P rating below this value.
:maturity_date_above => Only contracts with a maturity date later than this
:maturity_date_below => Only contracts with a maturity date earlier than this
:coupon_rate_above => double: Only contracts with a coupon rate above this
:coupon_rate_below => double: Only contracts with a coupon rate below this
:exclude_convertible => Exclude convertible bonds.
:scanner_setting_pairs => Used with the scan_code to help further narrow your query.
                          Scanner Setting Pairs are delimited by slashes, making
                          this parameter open ended. Example is "Annual,true" -
                          when used with 'Top Option Implied Vol % Gainers' scan
                          would return annualized volatilities.
:average_option_volume_above =>  int: Only contracts with average volume above this
:stock_type_filter => Valid values are:
                        'ALL' (excludes nothing)
                        'STOCK' (excludes ETFs)
                        'ETF' (includes ETFs) }

To learn all valid parameter values that a scanner subscription can have, first subscribe to ScannerParameters and send RequestScannerParameters message. Available scanner parameters values will be listed in received XML document.

SetServerLoglevel

data = { :log_level => int }