| Author |
Message |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Wed 26 Oct 2011, 11:33 Post subject:
getting stock data from yahoo finance |
|
so here is a little code for a stock quote gui
| Code: | #!/bin/ash
export F='<window title="Pstocks" icon-name="gtk-index" default_height="360" default_width="480">
<tree hover-selection="true">
<label>Name|Symbol|Quote|Opening|Closing</label>
<input>busybox wget -q -O - "http://download.finance.yahoo.com/d/quotes.csv?f=nsl1op&s='`echo ${@// /,}`'" |tr "," "|"</input>
</tree>
</window>
'
gtkdialog -p F |
usage:
pstocks goog msft
it doesn't have any features except displaying them at the moment, but it is fairly light weight
explanation of code
busybox wget -q -O - "http://download.finance.yahoo.com/d/quotes.csv?f=nsl1op&s='`echo ${@// /,}`'"
f=nsl1op this is the format string
n name
s stock symbol
l1 quote (the 1 removes the bold html tags)
o opening price
p previous closing price
s='`echo ${@// /,}`'
this is the list of symbols which must be comma separated
the echo command is to convert a traditional space separated set of inputs to comma separated - it could be replace with just $1 if you required a comma separated input
TODO: here is the format to get a basic stock chart
| Code: | | wget -q -O $1.png http://chart.finance.yahoo.com/z?s=$1 |
there are additional parameters like t= etc... need to look those up
Note: most spreadsheets can use csv format including mtcelledit and gnumeric
Update: there is a great resource for extending this here:
http://code.google.com/p/yahoo-finance-managed/wiki/YahooFinanceAPIs
| Description |
|
| Filesize |
19.62 KB |
| Viewed |
1021 Time(s) |

|
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
Last edited by technosaurus on Wed 26 Oct 2011, 14:27; edited 3 times in total
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Wed 26 Oct 2011, 13:11 Post subject:
|
|
here are some of the format strings:
a:Ask
a2:Average Daily Volume
a5:Ask Size
b :Bid
b2:Ask (Real-time)
b3:Bid (Real-time)
b4:Book Value
b6:Bid Size
c :Change & Percent Change
c1:Change
c3:Commission
c6:Change (Real-time)
c8:After Hours Change (Real-time)
d :Dividend/Share
d1:Last Trade Date
d2:Trade Date
e :Earnings/Share
e1:Error Indication (returned for symbol changed / invalid)
e7:EPS Estimate Current Year
e8:EPS Estimate Next Year
e9:EPS Estimate Next Quarter
f6:Float Shares
g :Day's Low
h :Day's High
j :52-week Low
k :52-week High
g1:Holdings Gain Percent
g3:Annualized Gain
g4:Holdings Gain
g5:Holdings Gain Percent (Real-time)
g6:Holdings Gain (Real-time)
i :More Info
i5:Order Book (Real-time)
j1:Market Capitalization
j3:Market Cap (Real-time)
j4:EBITDA
j5:Change From 52-week Low
j6:Percent Change From 52-week Low
k1:Last Trade (Real-time) With Time
k2:Change Percent (Real-time)
k3:Last Trade Size
k4:Change From 52-week High
k5:Percebt Change From 52-week High
l :Last Trade (With Time)
l1:Last Trade (Price Only)
l2:High Limit
l3:Low Limit
m :Day's Range
m2:Day's Range (Real-time)
m3:50-day Moving Average
m4:200-day Moving Average
m5:Change From 200-day Moving Average
m6:Percent Change From 200-day Moving Average
m7:Change From 50-day Moving Average
m8:Percent Change From 50-day Moving Average
n :Name
n4:Notes
o :Open
p :Previous Close
p1:Price Paid
p2:Change in Percent
p5:Price/Sales
p6:Price/Book
q :Ex-Dividend Date
r /E Ratio
r1:Dividend Pay Date
r2:P/E Ratio (Real-time)
r5:PEG Ratio
r6:Price/EPS Estimate Current Year
r7:Price/EPS Estimate Next Year
s :Symbol
s1:Shares Owned
s7:Short Ratio
t1:Last Trade Time
t6:Trade Links
t7:Ticker Trend
t8:1 yr Target Price
v :Volume
v1:Holdings Value
v7:Holdings Value (Real-time)
w :52-week Range
w1:Day's Value Change
w4:Day's Value Change (Real-time)
x :Stock Exchange
y :Dividend Yield
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2421
|
Posted: Thu 29 Dec 2011, 02:28 Post subject:
|
|
Hey Techno,
Terrific! Thanks for this. Ingenious (as usual).
BTW/ The png reflects "Previous Close" ..not in script. It initially had me wondering
Interesting that this only works as an ash script.
edit. you might add an "ok" button..
| Code: |
<window title ....
<vbox>
<tree......
</tree>
<hbox>
<button ok></button>
</hbox>
</vbox>
</window>
|
for some reason pfe name uses two columns.
|
|
Back to top
|
|
 |
ggg
Joined: 26 Apr 2011 Posts: 48
|
Posted: Thu 29 Dec 2011, 08:39 Post subject:
|
|
Hello,
I would like to know if it is possible to use the above "system(s)" to obtain details of current (and also historic) prices of shares traded on the London Stock Exchange?
Thank you
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2421
|
Posted: Thu 29 Dec 2011, 14:29 Post subject:
|
|
Resolved the "pfe" issue by cleaning up the formatting. I don't how many symbols do the same thing.
edit: simplified
| Code: |
#!/bin/ash
## USAGE: pstocks [symbol]...
## Script by technosauris, revised by jpeps
if [ ! "$1" -o "$1" == "-h" ]; then
echo "Usage: pstocks [sym] [sym] ..."
exit
fi
wget -q -O - "http://download.finance.yahoo.com/d/quotes.csv?f=nsl1opva2&s='`echo ${@// /,}`'" |tr "," "|" >/tmp/list
while read line; do
oldname="$( echo ${line} | cut -d\" -f2)"
newname="$( echo ${line} | cut -d\" -f2 | tr -d "|" )"
sed -i "s/${oldname}/${newname}/g" /tmp/list
done </tmp/list
export F='
<window title="Pstocks" icon-name="gtk-index" default_height="360" default_width="680">
<vbox>
<tree hover-selection="true">
<label>Name|Symbol|Quote|Opening|Prev Close|Vol|Avg Vol|</label>
<input>cat /tmp/list</input>
</tree>
<hbox>
<button ok></button>
</hbox>
</vbox>
</window>
'
gtkdialog -p F
|
Last edited by jpeps on Thu 29 Dec 2011, 21:14; edited 3 times in total
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2421
|
Posted: Thu 29 Dec 2011, 16:18 Post subject:
|
|
| ggg wrote: | Hello,
I would like to know if it is possible to use the above "system(s)" to obtain details of current (and also historic) prices of shares traded on the London Stock Exchange?
Thank you |
Yes. use: "http://uk.finance.yahoo.com" in the wget address and it works.
|
|
Back to top
|
|
 |
ggg
Joined: 26 Apr 2011 Posts: 48
|
Posted: Thu 29 Dec 2011, 17:10 Post subject:
|
|
Hello jpeps,
Thank you very much for your help.
I'll try with some test data next week.
Regards
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2421
|
Posted: Thu 29 Dec 2011, 20:05 Post subject:
|
|
| ggg wrote: | Hello jpeps,
Thank you very much for your help.
I'll try with some test data next week.
Regards |
Markets are open. I tried with LVS SLB
With input from /tmp/file, it's easy to replace volume numbers by vol /1000.
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Thu 29 Dec 2011, 20:37 Post subject:
|
|
I just posted this as an example for others. I don't really follow the market, so I'm probably not really the one to implement additional features aside from helping someone who does know the stock market intricacies to understand the api. I guess it could be fairly trivial to make a separate interface to allow the user to select columns. Let me know which are the most desired, but the formatting may get borked if too many are selected. This reminds me, if I ever write my own GUI the radiolist will just be a checklist with max_selectable set to 1... This would allow an arbitrary max_selectable number.
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2421
|
Posted: Thu 29 Dec 2011, 21:01 Post subject:
|
|
I'm working on it a bit; found some other symbols that didn't work..so edited again.
| Description |
|
| Filesize |
43.56 KB |
| Viewed |
804 Time(s) |

|
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2421
|
Posted: Sat 31 Dec 2011, 18:55 Post subject:
|
|
/bin/ash doesn't allow functions. The edited script works with /bin/sh. For my version, I included a button for editing the quote symbol page. Bash functions work nicely with gtkdialog.
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Sat 31 Dec 2011, 19:22 Post subject:
|
|
Ash does support functions, but cannot "export -f" them so that gtkdialog can use them. That is what gtkdialog's "-e" option is for. There are a couple examples in the gtkdialog documentation.
Anyhow if you rely on exporting functions, you should change the shabang to #!/bin/bash or it won't work in systems where sh is ash or dash. Puppy just happens to use bash as sh; some puplets and many other distros do not.
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2421
|
Posted: Sun 01 Jan 2012, 03:58 Post subject:
|
|
Simple addition of editor & quotepage with option "--q". Quotepage is just list of symbols, eg. "msft bldr nem ...."
note: Create or edit a list with the "edit" button. (root/quotepage)
Trivial addition would be option to view multiple quote pages.
| Code: |
#!/bin/bash
GTKDIALOG="$(which gtkdialog)"
[ "$GTKDIALOG" ] || GTKDIALOG="gtkdialog3"
if [ ! "$1" -o "$1" == "--h" ]; then
echo 'Usage: pstocks [sym] [sym] ...
pstocks --q ##quotepage
'
exit
fi
if [ "$1" == "--q" ]; then
if [ -f "/root/quotepage" ]; then
args="$(cat /root/quotepage)"
else
args=""
fi
else
args="$@"
fi
quoteEdit() {
echo -e "`Xdialog --stdout --no-cancel --editbox /root/quotepage 18 70`" >/root/quotepage
}
export -f quoteEdit
wget -q -O - "http://download.finance.yahoo.com/d/quotes.csv?f=nsl1cova2&s='`echo ${args// /,}`'" |tr "," "|" >/tmp/list
## Remove extra "|" in some names
while read line; do
oldname="$( echo ${line} | cut -d\" -f2)"
newname="$( echo ${line} | cut -d\" -f2 | tr -d "|" )"
sed -i "s/${oldname}/${newname}/g" /tmp/list
done </tmp/list
export F='
<window title="Pstocks" icon-name="gtk-index" default_height="360" default_width="700">
<vbox>
<tree hover-selection="true">
<label>Name|Symbol|Quote|Change|Opening|Vol |Avg Vol</label>
<input>cat /tmp/list</input>
</tree>
<hbox>
<button tooltip-text="Edit the symbols file">
<label>Edit</label>
<action>quoteEdit</action>
</button>
<button ok></button>
</hbox>
</vbox>
</window>
'
"$GTKDIALOG" -p F
|
Last edited by jpeps on Sun 01 Jan 2012, 20:24; edited 10 times in total
|
|
Back to top
|
|
 |
smokey01

Joined: 30 Dec 2006 Posts: 1605 Location: South Australia
|
Posted: Sun 01 Jan 2012, 04:13 Post subject:
|
|
jpeps, why did I get the missing symbols list?
Is the link broken?
| Description |
|
| Filesize |
16.77 KB |
| Viewed |
739 Time(s) |

|
_________________ Puppy Software <-> Distros <-> Puppy Linux Tips
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2421
|
Posted: Sun 01 Jan 2012, 04:31 Post subject:
|
|
no... you need to edit a list
|
|
Back to top
|
|
 |
|