Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions ystockquote.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@
# Requires: Python 2.7/3.3+


__version__ = '0.2.5dev'
__version__ = '0.2.6dev'

try:
# py3
import datetime
from urllib.request import Request, urlopen
from urllib.parse import urlencode
except ImportError:
# py2
from urllib2 import Request, urlopen
import datetime
from urllib import urlencode
from urllib2 import Request, urlopen

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup.. thanks for that.


def _request(symbol, stat):
Expand Down Expand Up @@ -464,11 +466,19 @@ def get_short_ratio(symbol):
def get_historical_prices(symbol, start_date, end_date):
"""
Get historical prices for the given ticker symbol.
Date format is 'YYYY-MM-DD'
Date format is 'YYYY-MM-DD'. Also accepts datetime
in addition to strings.

Returns a nested dictionary (dict of dicts).
outer dict keys are dates ('YYYY-MM-DD')
"""
try:
start_date = start_date.strftime('%Y-%m-%d')
end_date = end_date.strftime('%Y-%m-%d')
except AttributeError:
start_date = str(start_date)
end_date = str(end_date)

params = urlencode({
's': symbol,
'a': int(start_date[5:7]) - 1,
Expand Down