Skip to content

Commit b265342

Browse files
author
Matthew Hall
committed
Add av-forex-daily endpoint for historical currency exchange rates from AlphaVantange.
1 parent c60ea8a commit b265342

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

pandas_datareader/av/time_series.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class AVTimeSeriesReader(AlphaVantage):
3939
"TIME_SERIES_MONTHLY": "Monthly Time Series",
4040
"TIME_SERIES_MONTHLY_ADJUSTED": "Monthly Adjusted Time Series",
4141
"TIME_SERIES_INTRADAY": "Time Series (1min)",
42+
"FX_DAILY": "Time Series FX (Daily)",
4243
}
4344

4445
def __init__(
@@ -77,6 +78,10 @@ def function(self):
7778
def intraday(self):
7879
return True if self.function == "TIME_SERIES_INTRADAY" else False
7980

81+
@property
82+
def forex(self):
83+
return True if self.function == "FX_DAILY" else False
84+
8085
@property
8186
def output_size(self):
8287
""" Used to limit the size of the Alpha Vantage query when
@@ -92,13 +97,17 @@ def data_key(self):
9297
@property
9398
def params(self):
9499
p = {
95-
"symbol": self.symbols,
96100
"function": self.function,
97101
"apikey": self.api_key,
98102
"outputsize": self.output_size,
99103
}
100104
if self.intraday:
101105
p.update({"interval": "1min"})
106+
if self.forex:
107+
p.update({"from_symbol": self.symbols.split("/")[0]})
108+
p.update({"to_symbol": self.symbols.split("/")[1]})
109+
else:
110+
p.update({"symbol": self.symbols})
102111
return p
103112

104113
def _read_lines(self, out):

pandas_datareader/data.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ def DataReader(
361361
"yahoo-actions",
362362
"yahoo-dividends",
363363
"av-forex",
364+
"av-forex-daily",
364365
"av-daily",
365366
"av-daily-adjusted",
366367
"av-weekly",
@@ -567,6 +568,18 @@ def DataReader(
567568
api_key=api_key,
568569
).read()
569570

571+
elif data_source == "av-forex-daily":
572+
return AVTimeSeriesReader(
573+
symbols=name,
574+
function="FX_DAILY",
575+
start=start,
576+
end=end,
577+
retry_count=retry_count,
578+
pause=pause,
579+
session=session,
580+
api_key=api_key,
581+
).read()
582+
570583
elif data_source == "av-daily":
571584
return AVTimeSeriesReader(
572585
symbols=name,

0 commit comments

Comments
 (0)