Site Sponsors:
Python Stock Market 
Today we are hosting yet another "meetup." Designed for those who have been taking our Python 1000, 2000, and 3000 training, our goal is to build-up the resumes of our students.

Targeting a REAL WORLD game-play scenario that would impress would-be employers, we have set our sights upon a simple strategy.... Whoever can make the most "money" in the stock market, wins?

Anticipating the need, we decided to demonstrate how to get closing quotes from a particularly favorite quotation service:

# pip install urllib, first!
import urllib.request

class Stocks01:

def __init__(self, endpoint="", key="demo"):
self.end = endpoint.strip()
self.key = key.strip()

def get_history(self, token):
url = self.end + '&symbol=' + token.strip().upper() + "&apikey=" + self.key

response = urllib.request.urlopen(url)
except Exception as ex:
return None

stocks = Stocks01()
data = stocks.get_history("msft")

if data is not None:
import json
info = json.loads(str(data, "utf8"))
for row in info:
print("*" * 10, "KEY:", row)
if row != "Time Series (Daily)":
for ss, val in enumerate(sorted(info[row])):
print(ss, val)
for rec in sorted(info[row][val]):
print("\t\t", rec, info[row][val][rec])

Rather than using "demo," the link below will tell you how to get a free API key.

Hope you find it useful!

[ view entry ] ( 52 views )   |  permalink  |  related link

<Back | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Next> Last>>