forked from gbeced/pyalgotrade
-
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.
Using requests library for HTTP requests.
- Loading branch information
Showing
10 changed files
with
42 additions
and
49 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
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
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 |
---|---|---|
|
@@ -20,33 +20,25 @@ | |
.. moduleauthor:: Maciej Żok <[email protected]> | ||
""" | ||
|
||
import urllib2 | ||
import os | ||
import datetime | ||
|
||
import pyalgotrade.logger | ||
from pyalgotrade import bar | ||
from pyalgotrade.barfeed import googlefeed | ||
from pyalgotrade.utils import csvutils | ||
|
||
|
||
def download_csv(instrument, begin, end): | ||
url = "http://www.google.com/finance/historical" | ||
url += "?q={quote}".format(quote=instrument) | ||
url += "&startdate={date}".format(date=begin.strftime("%b+%d,+%Y")) | ||
url += "&enddate={date}".format(date=end.strftime("%b+%d,+%Y")) | ||
url += "&output=csv" | ||
|
||
f = urllib2.urlopen(url) | ||
if f.headers['Content-Type'] != 'application/vnd.ms-excel': | ||
raise Exception("Failed to download data: %s" % f.getcode()) | ||
buff = f.read() | ||
f.close() | ||
|
||
# Remove the BOM | ||
while not buff[0].isalnum(): | ||
buff = buff[1:] | ||
|
||
return buff | ||
params = { | ||
"q": instrument, | ||
"startdate": begin.strftime("%Y-%m-%d"), | ||
"enddate": end.strftime("%Y-%m-%d"), | ||
"output": "csv", | ||
} | ||
|
||
return csvutils.download_csv(url, url_params=params, content_type="application/vnd.ms-excel") | ||
|
||
|
||
def download_daily_bars(instrument, year, csvFile): | ||
|
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 |
---|---|---|
|
@@ -18,20 +18,20 @@ | |
.. moduleauthor:: Gabriel Martin Becedillas Ruiz <[email protected]> | ||
""" | ||
|
||
import urllib | ||
import urllib2 | ||
import datetime | ||
import os | ||
from pyalgotrade import bar | ||
from pyalgotrade.barfeed import quandlfeed | ||
|
||
from pyalgotrade.utils import dt | ||
from pyalgotrade.utils import csvutils | ||
import pyalgotrade.logger | ||
|
||
|
||
# http://www.quandl.com/help/api | ||
|
||
def download_csv(sourceCode, tableCode, begin, end, frequency, authToken): | ||
url = "http://www.quandl.com/api/v1/datasets/%s/%s.csv" % (sourceCode, tableCode) | ||
params = { | ||
"trim_start": begin.strftime("%Y-%m-%d"), | ||
"trim_end": end.strftime("%Y-%m-%d"), | ||
|
@@ -40,20 +40,7 @@ def download_csv(sourceCode, tableCode, begin, end, frequency, authToken): | |
if authToken is not None: | ||
params["auth_token"] = authToken | ||
|
||
url = "http://www.quandl.com/api/v1/datasets/%s/%s.csv" % (sourceCode, tableCode) | ||
url = "%s?%s" % (url, urllib.urlencode(params)) | ||
|
||
f = urllib2.urlopen(url) | ||
if f.headers['Content-Type'] != 'text/csv': | ||
raise Exception("Failed to download data: %s" % f.getcode()) | ||
buff = f.read() | ||
f.close() | ||
|
||
# Remove the BOM | ||
while not buff[0].isalnum(): | ||
buff = buff[1:] | ||
|
||
return buff | ||
return csvutils.download_csv(url, params) | ||
|
||
|
||
def download_daily_bars(sourceCode, tableCode, year, csvFile, authToken=None): | ||
|
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 |
---|---|---|
|
@@ -18,14 +18,14 @@ | |
.. moduleauthor:: Gabriel Martin Becedillas Ruiz <[email protected]> | ||
""" | ||
|
||
import urllib2 | ||
import os | ||
import datetime | ||
|
||
import pyalgotrade.logger | ||
from pyalgotrade import bar | ||
from pyalgotrade.barfeed import yahoofeed | ||
from pyalgotrade.utils import dt | ||
from pyalgotrade.utils import csvutils | ||
|
||
|
||
def __adjust_month(month): | ||
|
@@ -37,18 +37,7 @@ def __adjust_month(month): | |
|
||
def download_csv(instrument, begin, end, frequency): | ||
url = "http://ichart.finance.yahoo.com/table.csv?s=%s&a=%d&b=%d&c=%d&d=%d&e=%d&f=%d&g=%s&ignore=.csv" % (instrument, __adjust_month(begin.month), begin.day, begin.year, __adjust_month(end.month), end.day, end.year, frequency) | ||
|
||
f = urllib2.urlopen(url) | ||
if f.headers['Content-Type'] != 'text/csv': | ||
raise Exception("Failed to download data: %s" % f.getcode()) | ||
buff = f.read() | ||
f.close() | ||
|
||
# Remove the BOM | ||
while not buff[0].isalnum(): | ||
buff = buff[1:] | ||
|
||
return buff | ||
return csvutils.download_csv(url) | ||
|
||
|
||
def download_daily_bars(instrument, year, csvFile): | ||
|
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
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 |
---|---|---|
|
@@ -54,6 +54,7 @@ | |
"numpy", | ||
"pytz", | ||
"python-dateutil", | ||
"requests", | ||
], | ||
extras_require={ | ||
'Scipy': ["scipy"], | ||
|
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
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
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