[ts-gen] possible different use for trading shim

Bill Pippin pippin at owlriver.net
Tue Jan 15 17:28:47 EST 2008


John Tran asks:

> HI All, I am interested in getting data from IB and the print the
> stock, price volume and bid to stdout instead of dumping it into
> mysql.  Is this possible out of the box or will we need to make
> extensive surgery?

If you've installed both the IB tws and the shim, it should then be straight
forward.  Note that installation of the shim presently requires that you
set up a mysql database for it to use, and that there are scripts for this
included in the distribution, as well as directions for their use in the
tutorial/reference.

Once given an installed shim, you need to determine the contract number.
To do this, you may, from within the mysql interpreter, query the table
Symbol to determine the value of the symbol id, or sid, attribute, and
then use that to look for a contract number.  That value is needed in many
of the shim commands, in particular to request market tick data, market
depth, and history data.

E.g., for the NYSE-listed stock with symbol AIG, which currently has contract
number 15 in the default load file for the Contract table, the following
script will enable you to collect tick and market depth data for an hour:

#!../shim -f
tick add  15 1;
book add  15 3;
past add  15 6;
wait 3600;
quit;

Or, e.g., for the ECBOT Ym 200803 contract, number 181 in the default
load file for the Contract table, the following script will enable you
to download some history data, given that the IB tws accepts at most one
history query per 10 seconds, and the default setting for the shim waits 11
seconds for each query:

#!../shim -f
past add 181 6 Ymd_T(20080110  16:00:00);
past add 181 6 now;
wait 22;
quit;

The command line options file and cout will dump output to the default log
file (currently ShimText) and the stdout, respectively.  Note that, for the
cout option, you will have to use a shell that allows you to filter the stderr
from the stdout, as the shim uses the stderr freely for developer-focused
trace information.

So, given that the scripts above are in subdirectory bin as tick.tsd and
past.tsd, (they're now included with tarballs as examples, so if you have
a new release, you should find them there) and you've compiled the shim in
the current directory, then for the examples above, you would need command
lines such as the following:

bin/tick.tsd --data file
bin/past.tsd --data file

For the first command above, and with a tail'ing script running:

konsole -e bash -c bin/log.filter ShimText 2

I get, in part, the following (after-hours) data from bin/tick.tsd:

3| 1| 5|        15|4|    57.9|     0| |price.summary.last. |STK.SMART.AIG.
3| 2| 5|        15|5|              0|0|size.last.          |STK.SMART.AIG.
3| 2| 5|        15|8|         148600|0|size.volume.        |STK.SMART.AIG.
3| 1| 5|        15|6|   58.89|     0| |price.summary.high. |STK.SMART.AIG.
3| 1| 5|        15|7|   57.17|     0| |price.summary.low.  |STK.SMART.AIG.
3| 1| 5|        15|9|   59.32|     0| |price.summary.close.|STK.SMART.AIG.
3| 1| 5|        15|1|    55.0|     1| |price.outcry.bid.   |STK.SMART.AIG.
3| 1| 5|        15|2|    60.0|    12| |price.outcry.ask.   |STK.SMART.AIG.
3| 2| 5|        15|0|              1|0|size.bid.           |STK.SMART.AIG.
3| 2| 5|        15|3|             12|0|size.ask.           |STK.SMART.AIG.
3|12| 1|        15| 0|insert|bid|    55.0|     1|bid|insert|STK.SMART.AIG.
3|12| 1|        15| 0|insert|ask|    60.0|    12|ask|insert|STK.SMART.AIG.

In the above, there are price and volume ticks of 57.9 and 148600 respectively,
and (wildly divergent) offhours bid and ask prices from the market depth
subscription of 55.0 and 60.0.  During regular trading hours the market
data subscription should, by itself, provide the closest bid and ask prices.

Thanks,

Bill


More information about the ts-general mailing list