-
Notifications
You must be signed in to change notification settings - Fork 679
Add OANDA RestV20 Historical Instrument Reader #257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 44 commits
64e7e2a
0fbc6a9
5d38d59
c66ba1c
230d755
6d3bc7f
0c385aa
cf31164
ee0c561
d1afab7
23e44e9
2543d81
7a20979
772cf49
ef9f80e
a89aca1
1cef148
dcf86ff
2ed216f
784831a
a5a3d39
35036f6
ffeec50
76f8e4b
a6b8fa6
2c866a6
e659844
a650368
005bbbc
3b55fe4
9db2f72
1b7aa0f
57d17f5
dba0b05
cadfd8e
55aee1d
526f4bb
dbe0d98
b4a5de6
b7b62b1
0cb0572
d26ed90
e720ba4
228f743
4a692a3
29b0615
2fe4b2c
15cb182
7bf72c0
210d0c9
57957ec
257d108
0dfb503
e6f01d8
2b53d24
d063ab6
56c28cf
0830029
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ Currently the following sources are supported: | |
- :ref:`Eurostat<remote_data.eurostat>` | ||
- :ref:`Thrift Savings Plan<remote_data.tsp>` | ||
- :ref:`Oanda currency historical rate<remote_data.oanda_curr_hist>` | ||
- :ref:`Oanda REST currency historical rate<remote_data.oandarest_curr_hist>` | ||
- :ref:`Nasdaq Trader symbol definitions<remote_data.nasdaq_symbols` | ||
|
||
It should be noted, that various sources support different kinds of data, so not all sources implement the same methods and the data elements returned might also differ. | ||
|
@@ -542,6 +543,42 @@ Download currency historical rate from `Oanda <https://www.oanda.com/>`__. | |
|
||
[153 rows x 3 columns] | ||
|
||
.. _remote_data.oandarest_curr_hist | ||
|
||
Oanda REST currency historical rate | ||
============================== | ||
|
||
Download currency historical rate from `Oanda <https://www.oanda.com/>`__. | ||
|
||
.. code-block:: python | ||
|
||
In [1]: import pandas_datareader.data as web | ||
In [2]: start, end = "2016-01-01", "2016-06-01" | ||
In [3]: currency = ["EUR_USD"] | ||
In [4]: credential["accountType"]="practise" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
In [5]: credential["apiToken"]="Your OANDA API token" | ||
In [6]: pn = web.DataReader( | ||
symbols, data_source="oanda_historical_currency", | ||
start=start, end=end, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might be able to pass the |
||
access_key=credentials) | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this closing parenthesis is useless There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
|
||
In [7]: ipdb> pn.transpose(2,1,0)["EUR_USD"].head(5) | ||
|
||
Ask Bid Mid Ask Bid | ||
Close High Low Open Close High Low Open Close High Low Open Volume Complete Volume Complete Volume Complete | ||
Date | ||
2014-03-19 09:00:00 1.39146 1.39148 1.39146 1.39146 1.39138 1.39140 1.39136 1.39136 1.39142 1.39144 1.39141 1.39141 5 True 5 True 5 True | ||
2014-03-19 09:00:05 1.39147 1.39148 1.39147 1.39147 1.39138 1.39138 1.39137 1.39137 1.39142 1.39142 1.39142 1.39142 4 True 4 True 4 True | ||
2014-03-19 09:00:10 1.39149 1.39149 1.39148 1.39149 1.39138 1.39141 1.39138 1.39141 1.39143 1.39145 1.39143 1.39145 3 True 3 True 3 True | ||
2014-03-19 09:00:15 1.39153 1.39153 1.39149 1.39151 1.39143 1.39143 1.39139 1.39140 1.39148 1.39148 1.39144 1.39146 6 True 6 True 6 True | ||
2014-03-19 09:00:20 1.39150 1.39154 1.39150 1.39154 1.39140 1.39144 1.39139 1.39143 1.39145 1.39149 1.39145 1.39148 10 True 10 True 10 True | ||
|
||
[15438 rows x 18 columns] | ||
|
||
In [8]: pn["Ask","Close"]["EUR_USD"][pandas._to_datetime("2014-03-19 09:00:00")] | ||
Out[8]: 1.39147 | ||
|
||
.. _remote_data.nasdaq_symbols | ||
|
||
Nasdaq Trader Symbol Definitions | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ | |
from pandas_datareader.oanda import get_oanda_currency_historical_rates | ||
from pandas_datareader.nasdaq_trader import get_nasdaq_symbols | ||
|
||
from pandas_datareader.oandarest import OANDARestHistoricalInstrumentReader | ||
|
||
|
||
def get_data_fred(*args, **kwargs): | ||
return FredReader(*args, **kwargs).read() | ||
|
@@ -57,7 +59,8 @@ def get_quote_google(*args, **kwargs): | |
|
||
|
||
def DataReader(name, data_source=None, start=None, end=None, | ||
retry_count=3, pause=0.001, session=None, access_key=None): | ||
retry_count=3, pause=0.001, session=None, | ||
access_key=None): | ||
""" | ||
Imports data from a number of online sources. | ||
|
||
|
@@ -67,11 +70,11 @@ def DataReader(name, data_source=None, start=None, end=None, | |
Parameters | ||
---------- | ||
name : str or list of strs | ||
the name of the dataset. Some data sources (yahoo, google, fred) will | ||
the name of the dataset. Some data sources (yahoo, google, fred, oanda_historical_currency) will | ||
accept a list of names. | ||
data_source: {str, None} | ||
the data source ("yahoo", "yahoo-actions", "yahoo-dividends", | ||
"google", "fred", "ff", or "edgar-index") | ||
"google", "fred", "ff", or "edgar-index", oanda_historical_currency) | ||
start : {datetime, None} | ||
left boundary for range (defaults to 1/1/2010) | ||
end : {datetime, None} | ||
|
@@ -83,6 +86,8 @@ def DataReader(name, data_source=None, start=None, end=None, | |
single value given for symbol, represents the pause between retries. | ||
session : Session, default None | ||
requests.sessions.Session instance to be used | ||
access_key: dict of object | ||
Reader specific credentials | ||
|
||
Examples | ||
---------- | ||
|
@@ -108,6 +113,13 @@ def DataReader(name, data_source=None, start=None, end=None, | |
# Data from EDGAR index | ||
ed = DataReader("full", "edgar-index") | ||
ed2 = DataReader("daily", "edgar-index") | ||
|
||
# OANDA REST | ||
oa = DataReader("EUR_USD", data_source="oanda_rest_historical_currency", | ||
access_key={ "accountType"="practice", | ||
"accountVersion="0" | ||
"apiToken":"Your private API token" }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oa = DataReader("EUR_USD", data_source="oanda_rest_historical_currency",
custom = {
"accountType": "practice",
"accountVersion": "0",
"apiToken": "Your private API token"
}) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @femtotrader Fixed |
||
|
||
""" | ||
if data_source == "yahoo": | ||
return YahooDailyReader(symbols=name, start=start, end=end, | ||
|
@@ -167,6 +179,12 @@ def DataReader(name, data_source=None, start=None, end=None, | |
raise ValueError("Only the string 'symbols' is supported for " | ||
"Nasdaq, not %r" % (name,)) | ||
return get_nasdaq_symbols(retry_count=retry_count, pause=pause) | ||
elif data_source == "oanda_historical_currency": | ||
return OANDARestHistoricalInstrumentReader( | ||
symbols=name, symbolsTypes=None, | ||
start=start, end=end, | ||
reader_compatible=True, | ||
access_credential=access_key, session=session).read() | ||
else: | ||
msg = "data_source=%r is not implemented" % data_source | ||
raise NotImplementedError(msg) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be a good idea to put a shorter duration (to avoid too much request by people who just run doc example)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed