stock quotes off the web, py style
Friedrich Rentsch
anthra.norell at bluewin.ch
Wed May 16 08:33:23 EDT 2018
On 05/16/2018 02:23 AM, Mike McClain wrote:
> Initially I got my quotes from a broker daily to plug into a
> spreadsheet, Then I found Yahoo and wrote a perl script to grab them.
> When Yahoo quit supplying quotes I found AlphaVantage.co and rewrote
> the perl script.
> AlphaVantage.co has been down since last week and I found
> iextrading.com has a freely available interface. Since it needs
> a rewrite and I'm trying to get a handle on python this seems
> like a good opportunity to explore.
> If someone would please suggest modules to explore. Are there any
> upper level modules that would allow me to do something like:
>
> from module import get
> def getAquote(symbol):
> url = 'https://api.iextrading.com/1.0/stock/()/quote'.format(symbol)
> reply = module.get(url)
> return my_parse(reply)
>
> Thanks,
> Mike
> --
> Men occasionally stumble over the truth, but most of them pick
> themselves up and hurry off as if nothing ever happened.
> - Churchill
I didn't know the site you mention. I've been getting quotes from Yahoo
daily. The service they discontinued was for up to 50 symbols per page.
I now parse a separate page of some 500K of html for each symbol! This
site is certainly more concise and surely a lot faster. It serves a
naked set of data, which happens to conform to the python source code
specification for dictionaries and consequently can be compiled into a
dictionary with 'eval', like so:
>>> ibm = urllib2.urlopen
("https://api.iextrading.com/1.0/stock/IBM/quote").read()
>>> ibm = eval (ibm)
>>> for item in sorted (ibm.items()): print '%-24s%s' % item
avgTotalVolume 5331869
calculationPrice close
change -0.56
changePercent -0.00388
close 143.74
closeTime 1526414517398
companyName International Business Machines Corporation
delayedPrice 143.74
delayedPriceTime 1526414517398
high 143.99
iexAskPrice 0
iexAskSize 0
iexBidPrice 0
iexBidSize 0
iexLastUpdated 0
iexMarketPercent 0
iexRealtimePrice 0
iexRealtimeSize 0
iexVolume 0
latestPrice 143.74
latestSource Close
latestTime May 15, 2018
latestUpdate 1526414517398
latestVolume 4085996
low 142.92
marketCap 131948764304
open 143.5
openTime 1526391000646
peRatio 10.34
previousClose 144.3
primaryExchange New York Stock Exchange
sector Technology
symbol IBM
week52High 171.13
week52Low 139.13
ytdChange -0.0485148849103
You would do multiple symbols in a loop which you enter with an open
urllib object, rather than opening a new one for each symbol inside the
loop.
Frederic
More information about the Python-list
mailing list