Somebody posted similar question some time back. For historical prices, free, you can get from many sites: Yahoo, Google, Investopia, MSN, etc.
To do it automatically, you can program Perl, Java (I do both), C++, etc.
Java on IB only goes back one year; with Perl, I can get as far as the...