[ts-gen] ibc contract expressions and options data

Bill Pippin pippin at owlriver.net
Fri Feb 27 21:52:23 EST 2009

The focus of this series so far has been on adding contract
expressions to the command language, and as part of this, providing
access to options.

The contract info command now accepts security-type specific
filter expressions for indices, stocks, cash, futures, options, and
options on futures.  The script exs/info provides examples of the
various forms of filter query that may be used.

For commands other than the contract data command, where specific
contracts must be provided, the command language now includes two
forms of contract expression, both of which are tagged numbers
followed by routes, where the numbers are IB contract ids, or
trading-shim product ids, and the tags distinguish the two cases.
E.g., for market data subscriptions to AMAT share prices, either
of the following works:

            select tick pid:    2846 at SMART 1;
            select tick ibc:  266093 at SMART 1;

Once you have obtained options info as explained below, and loaded
it into the database, you may use this new form to refer to options
contracts.  E.g., the contract expression ibc:52752149 at SMART
refers to OPT:SMART:GOOG:20090320:P:350.0 .

Loading options products into the database:

There is a script sql/bin/fill.rb to filter options data from
contract data messages to database load tables, and it takes as
input logfiles that include the results of contract info queries
on options, using the enhanced command noted above.  Since we
can't distribute options info obtained via contract info queries
to the api, due to restrictions in IB's license, you will need to:
make the contract info queries yourself; use the fill.rb script
in order to obtain options data load files for the database; add
the file names for those load files to sql/load.sql or a child
script; and finally rerun sql/create.sql to ensure that the new
options data is added to the database.

For now, it's up to you how many options contracts you load; as
it stands, the shim reads in all of them.  You'll probably want to
stick with a relative handful of symbols, since there are a lot
of options contracts to choose from.  E.g., for google I added
about 700 products to the database.  By the way, the [trivial]
script exs/goog shows how I collected the google options data
to start with.

The current roadmap for options support:

In a previous post, I described a partial roadmap for options
support, and the list below expands on those steps; the goals
marked with an x below have now been completed:

    x 1.  fix contract info for options;
    x 2.  add OptSrc table to the database;
    x 3.  add fill.rb script, to collect option contract info via
          the IB tws, and create load files for the OptSrc table;
    * 4.  add OPT:route:sym:curr:expiry:right:strike expressions
          to the command language;
    * provide user control over contract loading for options:
        + add (user-controlled) shim load command, and store the
          results of option load queries in the option map;
        + fix Product input for the shim to ignore option products,
          lest it be overwhelmed;
        + fix symbol lookup to dispatch on security type, so that while
          non-option products are looked up in the (vector-based)
          Product table, option products are looked up in the option
          symbol map;
        + add (automatic) demand loading of option products that occur
          in the command side of the journal, to allow the shim to read
          open order messages for options that need to be written into
          the message side of the journal.
    * upgrade the shim to higher client version numbers of the
      IB tws api, to provide access to important options-related
      features, e.g., option-specific market data.
    ? add bag contracts to directly support option spreads via
      IB contract combos.

There will be additional work on the 3rd goal, the fill.rb script,
to collect and update contract info for other security types, e.g.,
cash and futures.

The 4th goal, for symbolic options expressions, is complete
for contract info as noted above, though not yet finished for
other contract-specific commands, e.g. market data; there you
must use the ibc:12345678 form for now.

Note that much of the work above is to enable user-controlled
selection of options data from the database.  Once users have
begun to accumulate options data, I'll be interested in comments 
to the list about the relative urgency of this feature.

Note also that the last goal in the options milestone list, combo
contracts, is very much speculative; I'm not certain at this point
if or when bags will be added to the shim.  As always, I'll be
interested in mailing list feedback.



More information about the ts-general mailing list