Dave Cohen -
Alleycat Software

Web Development

Capital Gainz Price Retrieval
In a hurry and don't want to sort through options yourself? I suggest trying the following in order, until one works for you:
  1. Yahoo Program API
  2. Yahoo Web Pages
  3. Yahoo Portfolio Download Fix
And, please alert me of any problems or changes.
In the battle to get free stock quotes, I've learned a few things:
  • Companies don't want to provide free quotes.
  • Those that do limit the number you can retrieve.
  • An exception is Yahoo.
  • Unfortunately, Yahoo messes with their APIs periodically, breaking app that use them to get prices.
This is the story, and instructions, on how to get current prices for Capital Gainz.
  1. Yahoo URL API: Initially, Yahoo provided a simple URL based interface to retrieve quotes. Capital Gainz used this to add quote retrieval from the internet. Then, Yahoo stopped support for that interface, and prices could not longer be retrieved in Capital Gainz. This option will not be discussed here since it is no longer viable.
  2. Yahoo Portfolio Download: I figured out that an investor could build their Yahoo portfolio, use the Export to CSV option, then read the result into Capital Gainz using Get Prices from File. This method is discussed here.
  3. Yahoo Portfolio Download Fix: Yahoo Portfolio Download failed when Yahoo tweaked the format of their CSV file. This resulted in 0 prices being retrieved. However, I developed a workaround that added one simple step, after a few setup steps. This method is solid, works, and is very unlikely to break in the future. This method is discussed here.
  4. Yahoo Program API: I stumbled on a new Yahoo Finance API, and built software to use it, replacing the prior program. Thus, investors could use Get Prices from Internet again. Not long after this started working, it started failing for me. Presumably, all my testing must have triggered some form of blocking by Yahoo. This method is discussed here, and may work for you. However, Yahoo may decide to block you at some point.
  5. Yahoo Web Pages: Doggedly, I decided to use brute force and grab Yahoo finance pages and parse them. This is slower than other methods, but does work for Get Prices from Internet. This method is discussed here.
  6. Troubleshooting: This is discussed here.
Yahoo Portfolio Download
Setup:
  1. Yahoo: Go to finance.yahoo.com. If you have a Yahoo account, login. Otherwise, create an account. Then Create a new portfolio with all of the symbols you want to retrieve. To see which symbols you are getting now, go to Capital Gainz, select Prices, Get Prices From Internet, then choose the Global Sec button. As you change your holdings, you will need to update the Yahoo portfolio.
  2. Capital Gainz: choose Prices, Update Prices from File. Click the Format button, and erase all fields except for Field #1 SYMBOL and Field #2 PRICE. Save your format by clicking OK.
Price Retrieval from Yahoo Finance (finance.yahoo.com):
  1. Login if necessary and go to My Portfolio, then select the portfolio you want.
  2. Click the download icon at the top of the portfolio listing.
  3. Yahoo Finance will popup a dialog box "Download Portfolio". Choose the "Save this portfolio as a CSV" button.
  4. Windows will ask where to save the CSV file to. To stick with defaults, choose C:\CAPGNZ\QUOTES.TXT.
  5. Yahoo may alter things at times. If these screenshots are different from what you see, just find the option to download or export prices to a CSV file.
Import into Capital Gainz:
  1. From Prices, Update Prices from File: Filename: is the name of the converted price file, C:\CAPGNZ\QUOTES.TXT by default. Date to Use if Not Found: should be set to date of that price file.
  2. Click Ok to read the file in. You will see how many prices were found, and any errors (usually quotes for stocks in Yahoo Finance that you do not have in Capital Gainz). You can use View button to see the prices read in. Use Ok to apply the prices.
Unfortunately, you will likely get a message that no prices were found. If so, check out the Yahoo Portfolio Download Fix. below.

While this seems all a bit wieldy, after setup and first execution, it is typically just a few steps and clicks:
  1. Download prices from Yahoo Finance. This may already be up and running in your browser.
  2. Choose Prices, Update Prices from File in Capital Gainz, which will prefill the Filename and Date to Use if Not Found fields.
Yahoo Portfolio Download Fix
Setup:
  1. Yahoo: Go to finance.yahoo.com. If you have a Yahoo account, login. Otherwise, create an account. Then Create a new portfolio with all of the symbols you want to retrieve. To see which symbols you are getting now, go to Capital Gainz, select Prices, Get Prices From Internet, then choose the Global Sec button. As you change your holdings, you will need to update the Yahoo portfolio.
  2. Capital Gainz: choose Prices, Update Prices from File. Click the Format button, and erase all fields except for Field #1 SYMBOL and Field #2 PRICE. Save your format by clicking OK.
After setting up Yahoo, you will need to use a batch file to fix price data. Since Yahoo altered the way files are stored, you need to fix the file that will be downloaded from Yahoo Finance before importing into Capital Gainz.
  1. Click here to download the ZIP archive containing CGFIXPRICES.BAT to your Capital Gainz folder: C:\CAPGNZ\CGFIXPRICES.ZIP.
  2. Extract CGFIXPRICES.BAT by right clicking on the downloaded CGFIXPRICES.ZIP in Windows Explorer and choosing to Extract All to C:\CAPGNZ.
  3. By default this conversion assumes the price file downloaded from Yahoo Finance is C:\CAPGNZ\QUOTES.CSV and the file to be imported into Capital Gainz is C:\CAPGNZ\QUOTES.TXT. However, this can be changed in two ways (this is optional):
    • Specify the file names to use when the program is executed, as described later:
      C:\CAPGNZ\CGFIXPRICES.BAT MY-YAHOO-PRICES.CSV MY-CAPGNZ-PRICES.TXT
    • Edit CGFIXPRICES.BAT. This file is just a plain text batch file that can be edited by Notepad.
Price Retrieval from Yahoo Finance (finance.yahoo.com):
  1. Login if necessary and go to My Portfolio, then select the portfolio you want.
  2. Click the download icon at the top of the portfolio listing.
  3. Yahoo Finance will popup a dialog box "Download Portfolio". Choose the "Save this portfolio as a CSV" button.
  4. Windows will ask where to save the CSV file to. To stick with defaults, choose C:\CAPGNZ\QUOTES.TXT.
  5. Yahoo may alter things at times. If these screenshots are different from what you see, just find the option to download or export prices to a CSV file.
With the downloaded Yahoo Finance price file ready to go, you need to fix it up:
  1. Right click the Windows icon in the bottom left of screen (next to the "Type here to search" box).
  2. Choose Run.
  3. In the Open: field, enter:
    C:\CAPGNZ\CGFIXPRICES.BAT C:\CAPGNZ\QUOTES.CSV
  4. If you downloaded Yahoo Finance prices to a different named CSV file, you can specify that:
    C:\CAPGNZ\CGFIXPRICES.BAT MY-YAHOO-PRICES.CSV
  5. If you want to convert to a different named file for import into Capital Gainz, you can specify that:
    C:\CAPGNZ\CGFIXPRICES.BAT MY-YAHOO-PRICES.CSV MY-CAPGNZ-PRICES.TXT
Import into Capital Gainz:
  1. From Prices, Update Prices from File: Filename: is the name of the converted price file, C:\CAPGNZ\QUOTES.TXT by default. Date to Use if Not Found: should be set to date of that price file.
  2. Click Ok to read the file in. You will see how many prices were found, and any errors (usually quotes for stocks in Yahoo Finance that you do not have in Capital Gainz). You can use View button to see the prices read in. Use Ok to apply the prices.
While this seems all a bit wieldy, after setup and first execution, it is typically just a few steps and clicks:
  1. Download prices from Yahoo Finance. This may already be up and running in your browser.
  2. Choose Run in Windows, which remembers and prefills the CGFIXPRICES.BAT command.
  3. Choose Prices, Update Prices from File in Capital Gainz, which will prefill the Filename and Date to Use if Not Found fields.
Yahoo Program API
Setup:
  1. Download CGINET-API.ZIP
  2. Right click on the ZIP file and choose Extract All. Extract the files to your C:\CAPGNZ directory. This will overwrite:
    C:\CAPGNZ\CGINET.DLL
    and create:
    C:\CAPGNZ\DNLD\CGINET-ACTUAL.EXE
Price retrieval:
  1. Use Capital Gainz Get Prices from Internet. All of the fields listed on that screen are ignored.
  2. A command line window will pop up and show prices being retrieved.
  3. When you return to Capital Gainz, you can use View button to see the prices read in. Use Ok to apply the prices.
Yahoo Web Pages
Setup:
  1. Download CGINET-WEB.ZIP
  2. Right click on the ZIP file and choose Extract All. Extract the files to your C:\CAPGNZ directory. This will overwrite:
    C:\CAPGNZ\CGINET.DLL
    and create:
    C:\CAPGNZ\DNLD\CGINET-ACTUAL.EXE
Price retrieval:
  1. Use the Capital Gainz Get Prices from Internet. All of the fields listed on that screen are ignored.
  2. A command line window will pop up and show prices being retrieved.
  3. When you return to Capital Gainz, you can use View button to see the prices read in. Use Ok to apply the prices.
Troubleshooting