Gday,
I have now added two buttons to my spreadsheet called "Run Cmd" and "Update Last Prices". As can be seen in the following image:
As you can see, above the buttons is a non editable cell labelled "Shell Cmd" and next to it is an editable cell containing the words "python.exe lpasx.py".
When you click on the "Run Cmd button", the following takes place:
First, all the symbols from the open trades you have added are written to a file called "Symbols.csv" (One symbol per line).
Next, the VBA macro/code executes a shell command containing the text in the above editable cell (if cell empty, no shell command is executed) which looks like this:
Shell("python.exe lpasx.py", 1)
So basically what happens next is python script "lpasx.py" gets executed asynchronously, which means that excel does not wait for script to finish. This is okay because we can simply wait for script to finish before continuing on with the next part of the process. Now what script "lpasx.py" actually does is reads the symbols in from file "Symbols.csv" (created above) and stores them in a list. The list of symbols is then iterated through to get their corresponding Last Prices from the asx web site (20 minute delayed data). The script then creates the file "LPrices.csv" and on each line, writes the symbol and the last price separated by a comma. You can easily check this by opening the file "LPrices.csv" with a simple text editor. Hopefully script works! For now anyway!
When you click on "Update Last Prices" button, the VBA code reads the file "LPrices.csv" line by line and tries to update all the Prices in the Last Price column corresponding to each case sensitive symbol and also updates the corresponding Last Date cell with today's date. If the case sensitive symbol does not match any of the symbols read in from file or it's corresponding last price is invalid (i.e. not numeric or non-positive), it will ignore that symbol's price and date and continue on with the next cell's symbol.
At the moment, if ASX website can't find symbol, then this is a problem for script "lpasx.py" as each troubled symbol's data is discarded hence stuffing up which price belongs to which symbol. This can be fixed by looking for the symbol in the downloaded web page as well, but if ASX change their web page html then that would be a waste of time. That seems to be the problem these days with using html web page data. Constantly updating scripts!
Attached are files TTS20190325.zip and lpasx20190325.zip which contain the following files:
TTS.xls - Clean Version of Trade Tracking Spreadsheet
TTSSample.xls - Trade Tracking Spreadsheet with sample ASX trades from Official March 2019 Stock Tipping Competition.
lpasx.py - Python script for downloading symbols from ASX website (Requires installation of any standard python).
The extracted files are to be all stored in the same directory location.
I might also have a look at some alternative websites for getting last prices. There seems to be some good recommendations in thread "Full ASX Excel Spreadsheet" like "Alpha Vantage" and "BigCharts".
Cheers,
Andrew.