forked from aleksb/candlesticks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/API' into team-1
- Loading branch information
Showing
1 changed file
with
26 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,31 @@ | ||
|
||
#!/usr/bin/env python3 | ||
import requests | ||
|
||
def import_stock_prices(company, start_date, end_date): | ||
"""Imports a range of stock prices from an API. | ||
* company - string company name (must be uppercase) | ||
* start_date - datetime.date object | ||
* end_date - datetime.date object | ||
Returns stock data formatted as described in README.md. | ||
""" | ||
* company - string company name (must be uppercase) | ||
* start_date - e.g year-date-month | ||
* end_date - e.g year-date-month | ||
Returns stock data formatted as described in README.md. | ||
""" | ||
|
||
URL = 'https://financialmodelingprep.com/api/v3/historical-price-full/' | ||
stock_data = requests.get(URL + company + "?from=" + start_date + '-01' + "&to=" + end_date + '-31') | ||
return stock_data.json() | ||
|
||
dump = import_stock_prices('AAPL', '2018-03', '2018-04') | ||
count = 0 | ||
lowsum = [] | ||
|
||
#testing averaging lows | ||
for data in dump: | ||
for key in data: | ||
try: | ||
lowsum.append(dump['historical'][count]['low']) | ||
count += 1 | ||
print(sum(lowsum) / count) | ||
except: | ||
break | ||
|