Difference between revisions of "Install the Example Quote Source"

From PalOMoney
Jump to navigation Jump to search
Line 1: Line 1:
PalOMoney includes an example external quote source, [[QuoteCSV.py]] that gets quotes from Yahoo Finance and imports them into MS Money. QuoteCSV.py is a very simple python script. Python is a high level computer script-like language that is executed by a python interpreter. You might have python installed already to take advantage of the python solutions for updating MS Money quotes and bank statements, etc. See [[Installing Python]]
+
==== Introduction ====
 +
PalOMoney includes an example external quote source, [[#QuoteCSV.py]] that gets quotes from Yahoo Finance and imports them into MS Money. QuoteCSV.py is a very simple python script. Python is a high level computer script-like language that is executed by a python interpreter. You might have python installed already to take advantage of the python solutions for updating MS Money quotes and bank statements, etc. See [[#Installing Python]].
  
The Yahoo Finance api in the example does not return column headers to identify the fields in the .csv file, the example also includes an accompanying example schema file, [[QuoteCSVSchema.csv]].
+
The Yahoo Finance API in the example does not return column headers to identify the fields in the .csv file, the example also includes an accompanying example schema file, [[#QuoteCSVSchema.csv]].  
Of course, it is trivial to modify the script to include the header line, but then we wouldn't have an example of a schema file to give you. Testers in particular should test using the separate schema file.
 
  
Copy QuoteCSV.py and QuoteCSVSchema.csv to your python folder, and install the new method:
+
External source settings are stored in PalOMoney.ini. PalOMoney.ini is saved in the same folder as each Money file you open. This means that if you are working with many Money files in different folders, you will have to install external quote sources in each folder. If you move your Money file, you can also move your PalOMoney.ini file as well to preserve the PalOMoney settings.
  
 +
<h4>Instructions</h4>
  
 +
* If necessary, download and install python. See [[#Installing Python]].
 +
* Locate and copy QuoteCSV.py and QuoteCSVSchema.csv in the Program Files PalOMoney folder to your python folder (or elsewhere). Please try to keep the original files intact and in place should you need them in the future.
 +
* Launch PalOMoney, and open a Money file. We will install the external quote source into this file's folder for use by all Money files in that folder.
 +
* Click the ''Quote Sources'' button labeled "..." to the right of the ''Quote Source'' selector to open the ''Quote Sources'' dialog.
 +
* Click the ''New'' button to start a new quote source.
 +
* Enter the fields according to the settings in [#YahooExtQuoteCSV Section] below.
 +
* Click ''Ok'' to save the settings and close the dialog. Observe that the new source is displayed in the ''Quote Source'' selector.
 +
* Hit Update now to launch the method and update the quotes. Observe a few windows flash open and close, and then its done. Notice how fast it is -- about a second. This method is fast because it batches symbols together and calls the Yahoo API only once per batch, unlike the internal method that uses the same call for each symbol individually.
  
 +
<h4>Troubleshooting a.k.a. Debugging</h4>
 +
 +
Too bad Siri doesn't work, otherwise we would just ask her to ''Fix it, Siri''.
 +
 +
Try figure out what is going wrong. If you can't, that is a support issue that you should report on the [https://www.palomoney.com/forum/ Support Forum] or [https://www.palomoney.com/support/ Support Ticket System].
 +
 +
* Did a message dialog appear? PalOMoney has built in sanity checking for some common problems. If you get a dialog message, there's usually a simple problem with what you entered.
 +
 +
* To troubleshoot, locate and open PalOMoney.ini and verify that the settings at the end of the file match those in [#PalOMoney.ini with Example] below.
 +
 +
* Did any windows appear? If not, PalOMoney didn't launch the quote source. There could be a problem with your command interpreter. Check your Windows configuration.
 +
 +
* Did the method write its output file (QuoteCSVpy.csv)? Open the folder specified in the Output control, and see if the file exists, and open it with NotePad and look for some quote data.
 +
** If there is no file, or no quotes, make sure you have permission to write to the folder.
 +
** Also make sure your internet connection is working.
 +
** Check and compare PalOMoney.ini [#MoneyPal section] below.
 +
** Hit ''View Logs'' on the Portfolio View window, and see what if anything has been recently written.
 +
 +
* Is the output file (QuoteCSVpy.csv) ok, but nothing changed? Keep in mind that PalOMoney does not update quotes that already have the same price. It should not create an new online quote if there is a correct online or manual quote already.
 +
** Hit ''View Logs'' on the Portfolio View window, and see what if anything has been recently written.
 +
 +
* Report a support issue on the [https://www.palomoney.com/forum/ Support Forum] or [https://www.palomoney.com/support/ Support Ticket System].
 +
 +
<h4>PalOMoney.ini with Example</h4>
 +
 +
Ini files store configuration in a human readable format. Ini files consist of <nowiki>[sections]</nowiki> enclosed in square brackets. Each section contains one or more key=value pairs, stored one per line, with an equals sign separating the key and the value. Section names and keys are case insensitive, so "Settings" matches "settings".
 +
 +
The quote sources are stored in the <nowiki>[Quote Sources]</nowiki> section. The internal quote sources are listed first, followed by any installed external quote sources. The key is the name you have given the quote source. The value is the name of the section header containing the settings for that source.
 +
 +
<h5>Quote Sources Section</h5>
 +
<nowiki>[Quote Sources]
 +
Finance.Yahoo.CSV=Finance.Yahoo.CSV Section
 +
Finance.Yahoo.YQL.XML=Finance.Yahoo.YQL.XML Section
 +
File.CSV=File.CSV Section
 +
File.YQL.XML=File.YQL.XML Section
 +
YahooExtQuoteCSV=YahooExtQuoteCSV Section</nowiki>
 +
 +
In this example, we see that the external source named "YahooExtQuoteCSV" stores its settings in the "YahooExtQuoteCSV Section."
 +
 +
<h5>YahooExtQuoteCSV Section</h5>
 +
 +
External quote sources are typically found the end of the PalOMoney.ini file. Here, we see the <nowiki>[YahooExtQuoteCSV Section]</nowiki>.
 +
 +
<nowiki>[YahooExtQuoteCSV Section]
 +
Name=YahooExtQuoteCSV
 +
AddOn=c:\python27\python
 +
Output File=c:\python27\QuoteCSVpy.csv
 +
Output Format=0
 +
Header Schema=0
 +
Schema=c:\python27\QuoteCSVSchema.csv
 +
URL Template=c:\python27\QuoteCSV.py  "http://finance.yahoo.com/d/quotes.csv?s=%s+&f=sl1d1t1"
 +
Request Tickers=20
 +
Tickers in Output=1
 +
Real Time=1
 +
Historical=0
 +
Login ID=
 +
Password=</nowiki>
 +
 +
The key values closely but not exactly correspond to the labels in the ''Quote Sources'' dialog. Put another way, every setting in the dialog is stored in this section.
  
 
<h4>QuoteCSV.py</h4>
 
<h4>QuoteCSV.py</h4>
<code>
+
<nowiki><code>
 
  import os, urllib2, sys
 
  import os, urllib2, sys
 
  argv = sys.argv
 
  argv = sys.argv
 +
 
  if __name__=="__main__":
 
  if __name__=="__main__":
 
     if len(argv) < 3:
 
     if len(argv) < 3:
Line 27: Line 96:
 
     f.write(csv)
 
     f.write(csv)
 
     f.close()
 
     f.close()
</code>
+
</code></nowiki>
 +
 
 +
<h5>MoneyPal Section</h5>
 +
 
 +
Open PalOMoney.ini in your MS Money folder, and find and compare [#MoneyPal section] with the example below. It contains the Last External Launch and Last Launch keys.
 +
 
 +
<nowiki>[MoneyPal]
 +
Last Launch="C:\Program Files\PalOMoney.com\PalOMoney\MoneyPal.exe" C:\Finance\k2008s.mny -s2 -fc:\python27\QuoteCSVpy.csv -cc:\python27\QuoteCSVSchema.csv
 +
Last External Launch=c:\python27\python c:\python27\QuoteCSV.py  "http://finance.yahoo.com/d/quotes.csv?s=AAPL+GOOG+PSX+COH&f=sl1d1t1" c:\python27\QuoteCSVpy.csv
 +
Quotes Updated=2013/01/24 11:26
 +
Debug Level=0 </nowiki>
  
 
<h4>QuoteCSVSchema.csv</h4>
 
<h4>QuoteCSVSchema.csv</h4>
 +
 +
Of course, it is trivial to modify QuoteCSV.py to include the header line, but then we wouldn't have an example of a schema file to give you. Testers in particular should test using the separate schema file.
 +
 
<code>
 
<code>
 
Ticker, Close, Date, Time
 
Ticker, Close, Date, Time

Revision as of 00:15, 25 January 2013

Introduction

PalOMoney includes an example external quote source, #QuoteCSV.py that gets quotes from Yahoo Finance and imports them into MS Money. QuoteCSV.py is a very simple python script. Python is a high level computer script-like language that is executed by a python interpreter. You might have python installed already to take advantage of the python solutions for updating MS Money quotes and bank statements, etc. See #Installing Python.

The Yahoo Finance API in the example does not return column headers to identify the fields in the .csv file, the example also includes an accompanying example schema file, #QuoteCSVSchema.csv.

External source settings are stored in PalOMoney.ini. PalOMoney.ini is saved in the same folder as each Money file you open. This means that if you are working with many Money files in different folders, you will have to install external quote sources in each folder. If you move your Money file, you can also move your PalOMoney.ini file as well to preserve the PalOMoney settings.

Instructions

  • If necessary, download and install python. See #Installing Python.
  • Locate and copy QuoteCSV.py and QuoteCSVSchema.csv in the Program Files PalOMoney folder to your python folder (or elsewhere). Please try to keep the original files intact and in place should you need them in the future.
  • Launch PalOMoney, and open a Money file. We will install the external quote source into this file's folder for use by all Money files in that folder.
  • Click the Quote Sources button labeled "..." to the right of the Quote Source selector to open the Quote Sources dialog.
  • Click the New button to start a new quote source.
  • Enter the fields according to the settings in [#YahooExtQuoteCSV Section] below.
  • Click Ok to save the settings and close the dialog. Observe that the new source is displayed in the Quote Source selector.
  • Hit Update now to launch the method and update the quotes. Observe a few windows flash open and close, and then its done. Notice how fast it is -- about a second. This method is fast because it batches symbols together and calls the Yahoo API only once per batch, unlike the internal method that uses the same call for each symbol individually.

Troubleshooting a.k.a. Debugging

Too bad Siri doesn't work, otherwise we would just ask her to Fix it, Siri.

Try figure out what is going wrong. If you can't, that is a support issue that you should report on the Support Forum or Support Ticket System.

  • Did a message dialog appear? PalOMoney has built in sanity checking for some common problems. If you get a dialog message, there's usually a simple problem with what you entered.
  • To troubleshoot, locate and open PalOMoney.ini and verify that the settings at the end of the file match those in [#PalOMoney.ini with Example] below.
  • Did any windows appear? If not, PalOMoney didn't launch the quote source. There could be a problem with your command interpreter. Check your Windows configuration.
  • Did the method write its output file (QuoteCSVpy.csv)? Open the folder specified in the Output control, and see if the file exists, and open it with NotePad and look for some quote data.
    • If there is no file, or no quotes, make sure you have permission to write to the folder.
    • Also make sure your internet connection is working.
    • Check and compare PalOMoney.ini [#MoneyPal section] below.
    • Hit View Logs on the Portfolio View window, and see what if anything has been recently written.
  • Is the output file (QuoteCSVpy.csv) ok, but nothing changed? Keep in mind that PalOMoney does not update quotes that already have the same price. It should not create an new online quote if there is a correct online or manual quote already.
    • Hit View Logs on the Portfolio View window, and see what if anything has been recently written.

PalOMoney.ini with Example

Ini files store configuration in a human readable format. Ini files consist of [sections] enclosed in square brackets. Each section contains one or more key=value pairs, stored one per line, with an equals sign separating the key and the value. Section names and keys are case insensitive, so "Settings" matches "settings".

The quote sources are stored in the [Quote Sources] section. The internal quote sources are listed first, followed by any installed external quote sources. The key is the name you have given the quote source. The value is the name of the section header containing the settings for that source.

Quote Sources Section
[Quote Sources]
Finance.Yahoo.CSV=Finance.Yahoo.CSV Section
Finance.Yahoo.YQL.XML=Finance.Yahoo.YQL.XML Section
File.CSV=File.CSV Section
File.YQL.XML=File.YQL.XML Section
YahooExtQuoteCSV=YahooExtQuoteCSV Section

In this example, we see that the external source named "YahooExtQuoteCSV" stores its settings in the "YahooExtQuoteCSV Section."

YahooExtQuoteCSV Section

External quote sources are typically found the end of the PalOMoney.ini file. Here, we see the [YahooExtQuoteCSV Section].

[YahooExtQuoteCSV Section]
Name=YahooExtQuoteCSV
AddOn=c:\python27\python
Output File=c:\python27\QuoteCSVpy.csv
Output Format=0
Header Schema=0
Schema=c:\python27\QuoteCSVSchema.csv
URL Template=c:\python27\QuoteCSV.py  "http://finance.yahoo.com/d/quotes.csv?s=%s+&f=sl1d1t1"
Request Tickers=20
Tickers in Output=1
Real Time=1
Historical=0
Login ID=
Password=

The key values closely but not exactly correspond to the labels in the Quote Sources dialog. Put another way, every setting in the dialog is stored in this section.

QuoteCSV.py

<code>
 import os, urllib2, sys
 argv = sys.argv

 if __name__=="__main__":
    if len(argv) < 3:
        print "Usage:",argv[0], "YahooURLSpec OutputFileName"
        if len(argv) > 0:
            print "1:", argv[1]
        if len(argv) > 1:
            print "2:", argv[2]
        sys.exit()
    #url = "http://finance.yahoo.com/d/quotes.csv?s=%s&f=nl1d1t1" % argv[1]
    url = argv[1]
    csv = urllib2.urlopen(url).read()
    f = file(argv[2],"w")
    f.write(csv)
    f.close()
</code>
MoneyPal Section

Open PalOMoney.ini in your MS Money folder, and find and compare [#MoneyPal section] with the example below. It contains the Last External Launch and Last Launch keys.

[MoneyPal]
Last Launch="C:\Program Files\PalOMoney.com\PalOMoney\MoneyPal.exe" C:\Finance\k2008s.mny -s2 -fc:\python27\QuoteCSVpy.csv -cc:\python27\QuoteCSVSchema.csv
Last External Launch=c:\python27\python c:\python27\QuoteCSV.py  "http://finance.yahoo.com/d/quotes.csv?s=AAPL+GOOG+PSX+COH&f=sl1d1t1" c:\python27\QuoteCSVpy.csv
Quotes Updated=2013/01/24 11:26
Debug Level=0 

QuoteCSVSchema.csv

Of course, it is trivial to modify QuoteCSV.py to include the header line, but then we wouldn't have an example of a schema file to give you. Testers in particular should test using the separate schema file.

Ticker, Close, Date, Time


Installing Python

Windows does not include a python interpreter, but you can download and install one for free. Python comes in a multitude of versions, and the latest version is of course improved, but it does not work with older python scripts. The safest bet is to install version 2.7.3, which you can get at Python.org. Because the command interpreter is frequently used to execute python scripts, it is handy to install python just on your C drive root, say at C:\python27. You will also have to download and install python libraries to extend the python's functionality.