Skip to content

Commit

Permalink
Merge pull request #6 from dalenguyen/dev
Browse files Browse the repository at this point in the history
Get all historical data since 01/01/2000
  • Loading branch information
Dale Nguyen authored Feb 28, 2021
2 parents c4dad43 + 192fea2 commit 3878355
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 29 deletions.
12 changes: 12 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
---

## [1.4.0] - 2021-02-27

#### - :bug: [Bug Fix]

- Get all historical data since 01/01/2000

## [1.3.0] - 2021-02-27

#### - :nail_care: [Polish]

- Use unix timestamp for date

## [1.2.0] - 2021-02-27

#### - :rocket: [New Feature]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setup(
name="stockai",
version="1.2.0",
version="1.4.0",
author="Dale Nguyen",
author_email="[email protected]",
description="Get stock info from Yahoo! Finance",
Expand Down
2 changes: 1 addition & 1 deletion stockai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Stockai - get stock information from Yahoo! Finance
"""

__version__ = '1.2.0'
__version__ = '1.4.0'
__author__ = 'Dale Nguyen'
__name__ = 'stockai'

Expand Down
33 changes: 18 additions & 15 deletions stockai/utils.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
from time import mktime
from time import mktime, time
from ciso8601 import parse_datetime
from datetime import datetime

def date_to_timestamp(date):
"""
Convert date to timestamp
"""
Convert date to timestamp
:param date: date string '2019-04-30'
:return: timestamp int 1546318800
"""
ts = parse_datetime(date)
# to get time in seconds:
return int(mktime(ts.timetuple()))
:param date: date string '2019-04-30'
:return: timestamp int 1546318800
"""
ts = parse_datetime(date)
# to get time in seconds:
return int(mktime(ts.timetuple()))

def timestamp_to_date(timestamp):
"""
Convert timestamp to readable date
"""
Convert timestamp to readable date
:param timestamp: timestamp string '1546318800'
:return: date string '2019-04-30'
"""
return datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d')
:param timestamp: timestamp string '1546318800'
:return: date string '2019-04-30'
"""
return datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d')

def get_current_timestamp():
return int(time())
2 changes: 1 addition & 1 deletion stockai/wealthsimple/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
StockAI v1.2.0
StockAI
Copyright (c) Dale Nguyen
"""
Expand Down
2 changes: 1 addition & 1 deletion stockai/yahoo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
StockAI v1.2.0
StockAI
Copyright (c) Dale Nguyen
"""
Expand Down
16 changes: 7 additions & 9 deletions stockai/yahoo/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from requests import get
from ..utils import timestamp_to_date
from ..utils import timestamp_to_date, get_current_timestamp

class Base(object):
def __init__(self, symbol):
Expand Down Expand Up @@ -38,12 +38,10 @@ def get_historical(self, start_date, end_date):
return self.__process_historical_result(data)

def get_all_historical(self):
url = 'https://query1.finance.yahoo.com/v8/finance/chart/{symbol}?range=max'.format(
symbol = self.symbol
)

data = get(url)
return self.__process_historical_result(data)
# Start from 01/01/2000
start_date = 946702800
end_date = get_current_timestamp()
return self.get_historical(start_date, end_date)

def refresh(self):
"""
Expand All @@ -63,7 +61,7 @@ def __process_historical_result(self, data):
result['adjclose'] = data.json()['chart']['result'][0]['indicators']['adjclose'][0]['adjclose']
result['meta'] = data.json()['chart']['result'][0]['meta']

for index, date in enumerate(result['date']):
result['date'][index] = timestamp_to_date(result['date'][index])
# for index, date in enumerate(result['date']):
# result['date'][index] = timestamp_to_date(result['date'][index])

return result
2 changes: 1 addition & 1 deletion tests/yahoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def setUp(self):
self.td = Stock('TD.TO')

def test_td_summary_profile(self):
print(self.td.get_summary_profile())
# print(self.td.get_summary_profile())
self.assertEqual(self.td.get_summary_profile()['city'], 'Toronto')

def test_td_financial_data(self):
Expand Down

0 comments on commit 3878355

Please sign in to comment.