From 6a41e1429bb2050594878d1c646cd0728e3408f5 Mon Sep 17 00:00:00 2001 From: Louis-P Lamoureux Date: Fri, 12 Mar 2021 16:01:43 -0500 Subject: [PATCH 1/4] chore: rebase --- setup.py | 3 + src/mercury/extras/datasources/__init__.py | 12 ++ src/mercury/extras/datasources/polygon.py | 125 ++++++++++++++++++++ test/integration/test_datasource_polygon.py | 112 ++++++++++++++++++ 4 files changed, 252 insertions(+) create mode 100644 src/mercury/extras/datasources/polygon.py create mode 100644 test/integration/test_datasource_polygon.py diff --git a/setup.py b/setup.py index e6aa42b..d2ccee9 100644 --- a/setup.py +++ b/setup.py @@ -23,6 +23,9 @@ "extra_datasource_quandl": [ "quandl==3.6.1", ], + "extra_datasource_polygon": [ + "polygon==0.1.9", + ], "extra_broker_ig": [ "requests", ], diff --git a/src/mercury/extras/datasources/__init__.py b/src/mercury/extras/datasources/__init__.py index 8cbe042..c0b7766 100644 --- a/src/mercury/extras/datasources/__init__.py +++ b/src/mercury/extras/datasources/__init__.py @@ -6,6 +6,18 @@ __copyright__ = "Copyright 2019 - 2021 Richard Kemp" __revision__ = "$Id$" +__all__ = [ + "AlphaVantage", + "CSV", + "Polygon", + "Quandl", +] + + +from .alphavantage import AlphaVantage +from .csv import CSV +from .polygon import Polygon +from .quandl import Quandl # TODO: # iex diff --git a/src/mercury/extras/datasources/polygon.py b/src/mercury/extras/datasources/polygon.py new file mode 100644 index 0000000..0d51de1 --- /dev/null +++ b/src/mercury/extras/datasources/polygon.py @@ -0,0 +1,125 @@ +# Copyright (C) 2019 - 2021 Richard Kemp +# $Id$ +# -*- coding: utf-8; py-indent-offset:4 -*- + +"""Polygon DataSource Module. + +Provide: + - Polygon DataSource Class +""" + +__copyright__ = "Copyright 2019 - 2021 Richard Kemp" +__revision__ = "$Id$" +__all__ = [ + "Polygon", +] + +from datetime import datetime +from typing import Dict + +from mercury import TimeFrame, TimeSeries +from mercury.lib import DataSource + +import pandas as pd + +from polygon import RESTClient + + +TIMEFRAME_MAP = { + TimeFrame.M1: {"multiplier": 1, "timestamp": "minute"}, + TimeFrame.M5: {"multiplier": 5, "timestamp": "minute"}, + TimeFrame.M15: {"multiplier": 15, "timestamp": "minute"}, + TimeFrame.M30: {"multiplier": 30, "timestamp": "minute"}, + TimeFrame.H1: {"multiplier": 1, "timestamp": "minute"}, + TimeFrame.H4: {"multiplier": 4, "timestamp": "hour"}, + TimeFrame.D1: {"multiplier": 1, "timestamp": "day"}, + TimeFrame.W1: {"multiplier": 1, "timestamp": "week"}, + TimeFrame.MN: {"multiplier": 1, "timestamp": "month"}, +} + +PolygonInstrumentType = ["stock", "crypto", "forex"] + + +class Polygon(DataSource): + """polygon.io datasource provider. + + Load data from website polygon. + + Attributes: + api_key (str): polygon API key + + Usage:: + + >>> from Mercury_contrib.datasources import Polygon + >>> datasource = Polygon('api_key') + >>> dataframe = datasource.get_timeseries( + from_date=datetime(2019, 12, 1, 9, 00, 00), + to_date=datetime(2019, 12, 15, 23, 00, 00), + instrument="MSFT", + timeframe=TimeFrame.M5, + ) + """ + def __init__(self, api_key: str, + instrument_type: PolygonInstrumentType) -> None: + """Class initialization. + + Args: + api_key: polygon api key, + instrument_type: the Polygon instrument type [forex, crypto, stock] + """ + self.api_key = api_key + self.instrument_type = instrument_type + + @property + def colsmap(self) -> Dict[str, str]: + """Columns mapping dictionary. + + Provide a mapping to translate raw time series columns name + to standardized naming convention. + + Expect standard names like "open", "high", "low", "close", "adj_close" + and "volume". + """ + return { + "1. open": "open", + "2. high": "high", + "3. low": "low", + "4. close": "close", + "5. volume": "volume", + } + + def get_timeseries(self, from_date: datetime, to_date: datetime, + instrument: str, timeframe: TimeFrame) -> TimeSeries: + """Retrieve a given timeseries from the datasource. + + Args: + from_date: timeseries starting date. + to_date: timeseries last date. + instrument: target instrument. + timeframe: target timeframe. + + Returns: + An Mercury TimeSeries. + + Raises: + IndexError: The requested time range cannot be satisfied. + """ + if timeframe is TimeFrame.S: + raise ValueError("S interval not supported") + + if self.instrument_type not in PolygonInstrumentType: + raise ValueError("Unsupported Polygon instrument type") + + multiplier = TIMEFRAME_MAP[timeframe]["multiplier"] + timestamp = TIMEFRAME_MAP[timeframe]["timestamp"] + from_date = datetime.strftime(from_date, "%Y-%m-%d") + to_date = datetime.strftime(to_date, "%Y-%m-%d") + + if self.instrument_type == "stock": + with RESTClient(self.api_key) as client: + resp = client.stocks_equities_aggregates(instrument, + multiplier, timestamp, + from_date, to_date) + data = pd.DataFrame(resp.results) + + return TimeSeries(instrument, timeframe, data) diff --git a/test/integration/test_datasource_polygon.py b/test/integration/test_datasource_polygon.py new file mode 100644 index 0000000..0cbd4ce --- /dev/null +++ b/test/integration/test_datasource_polygon.py @@ -0,0 +1,112 @@ +# Copyright (C) 2019 - 2021 Richard Kemp +# $Id$ +# -*- coding: utf-8; py-indent-offset:4 -*- + +"""Polygon datasource Tests.""" + +__copyright__ = "Copyright 2019 - 2021 Richard Kemp" +__revision__ = "$Id$" + +from datetime import datetime + +from mercury import TimeFrame, TimeSeries + +from mercury.extras.datasources import Polygon + +from pandas import DataFrame + +import pytest + +# API_KEY = os.environ['POLYGON_API_KEY'] +# API_KEY = 'TEST' +API_KEY = '0mEGmDxsPUtn7M8VDEhyYi7D3oQ5OuPh' + + +@pytest.fixture +def datasource(): + return Polygon(API_KEY, "stock") + + +class TestInstanciation(): + def test_valid_key(self, datasource): + assert datasource + +class TestGetMethod(): + @pytest.mark.online + def test_invalid_interval(self, datasource): + with pytest.raises(ValueError) as error: + assert datasource.get_timeseries( + from_date=datetime(2019, 12, 1, 9, 00, 00), + to_date=datetime(2019, 12, 2, 23, 00, 00), + instrument="AAPL", + timeframe=TimeFrame.S) + message = str(error.value) + assert message == "S interval not supported" + + @pytest.mark.online + def test_invalid_instrument_type(self): + with pytest.raises(ValueError) as error: + datasource = Polygon(API_KEY, "stuck") + assert datasource.get_timeseries( + from_date=datetime(2019, 12, 1, 9, 00, 00), + to_date=datetime(2019, 12, 2, 23, 00, 00), + instrument="AAPL", + timeframe=TimeFrame.M5) + message = str(error.value) + assert message == "Unsupported Polygon instrument type" + + @pytest.mark.online + def test_intraday_data(self, datasource): + instrument = "AAPL" + timeframe = TimeFrame.M5 + ts = datasource.get_timeseries( + from_date=datetime(2019, 12, 1, 9, 00, 00), + to_date=datetime(2019, 12, 2, 23, 00, 00), + instrument=instrument, + timeframe=timeframe) + assert isinstance(ts, TimeSeries) + assert ts.instrument is instrument + assert ts.timeframe is timeframe + assert isinstance(ts.data, DataFrame) + + # @pytest.mark.online + # def test_daily_data(self, datasource): + # instrument = "MSFT" + # timeframe = TimeFrame.D1 + # ts = datasource.get_timeseries( + # from_date=datetime(2019, 12, 1, 9, 00, 00), + # to_date=datetime(2019, 12, 15, 23, 00, 00), + # instrument=instrument, + # timeframe=timeframe) + # assert isinstance(ts, TimeSeries) + # assert ts.instrument is instrument + # assert ts.timeframe is timeframe + # assert isinstance(ts.data, DataFrame) + + # @pytest.mark.online + # def test_weekly_data(self, datasource): + # instrument = "MSFT" + # timeframe = TimeFrame.W1 + # ts = datasource.get_timeseries( + # from_date=datetime(2019, 12, 1, 9, 00, 00), + # to_date=datetime(2019, 12, 15, 23, 00, 00), + # instrument=instrument, + # timeframe=timeframe) + # assert isinstance(ts, TimeSeries) + # assert ts.instrument is instrument + # assert ts.timeframe is timeframe + # assert isinstance(ts.data, DataFrame) + + # @pytest.mark.online + # def test_monthly_data(self, datasource): + # instrument = "MSFT" + # timeframe = TimeFrame.MN + # ts = datasource.get_timeseries( + # from_date=datetime(2019, 12, 1, 9, 00, 00), + # to_date=datetime(2019, 12, 15, 23, 00, 00), + # instrument=instrument, + # timeframe=timeframe) + # assert isinstance(ts, TimeSeries) + # assert ts.instrument is instrument + # assert ts.timeframe is timeframe + # assert isinstance(ts.data, DataFrame) From f083264ea5697339b20ee44d65096152dfbb24cd Mon Sep 17 00:00:00 2001 From: Louis-P Lamoureux Date: Fri, 12 Mar 2021 16:25:44 -0500 Subject: [PATCH 2/4] chore: clean up new camel case conventions --- src/mercury/extras/datasources/__init__.py | 15 +------- src/mercury/extras/datasources/polygon.py | 40 ++++++++++----------- test/integration/test_datasource_polygon.py | 28 +++++++-------- 3 files changed, 35 insertions(+), 48 deletions(-) diff --git a/src/mercury/extras/datasources/__init__.py b/src/mercury/extras/datasources/__init__.py index c0b7766..a980c60 100644 --- a/src/mercury/extras/datasources/__init__.py +++ b/src/mercury/extras/datasources/__init__.py @@ -2,25 +2,12 @@ # $Id$ # -*- coding: utf-8; py-indent-offset:4 -*- -"""Mercury Datasources Extras Module.""" +"""Mercury DataSources Extras Module.""" __copyright__ = "Copyright 2019 - 2021 Richard Kemp" __revision__ = "$Id$" -__all__ = [ - "AlphaVantage", - "CSV", - "Polygon", - "Quandl", -] - - -from .alphavantage import AlphaVantage -from .csv import CSV -from .polygon import Polygon -from .quandl import Quandl # TODO: # iex -# polygon.io # quantopian # yahoo diff --git a/src/mercury/extras/datasources/polygon.py b/src/mercury/extras/datasources/polygon.py index 0d51de1..eebf352 100644 --- a/src/mercury/extras/datasources/polygon.py +++ b/src/mercury/extras/datasources/polygon.py @@ -2,23 +2,23 @@ # $Id$ # -*- coding: utf-8; py-indent-offset:4 -*- -"""Polygon DataSource Module. +"""Polygon Datasource Module. Provide: - - Polygon DataSource Class + - Polygon Datasource Class """ __copyright__ = "Copyright 2019 - 2021 Richard Kemp" __revision__ = "$Id$" __all__ = [ - "Polygon", + "Datasource", ] from datetime import datetime from typing import Dict -from mercury import TimeFrame, TimeSeries -from mercury.lib import DataSource +from mercury import Timeframe, Timeseries +from mercury.lib import Datasource as AbcDataSource import pandas as pd @@ -26,21 +26,21 @@ TIMEFRAME_MAP = { - TimeFrame.M1: {"multiplier": 1, "timestamp": "minute"}, - TimeFrame.M5: {"multiplier": 5, "timestamp": "minute"}, - TimeFrame.M15: {"multiplier": 15, "timestamp": "minute"}, - TimeFrame.M30: {"multiplier": 30, "timestamp": "minute"}, - TimeFrame.H1: {"multiplier": 1, "timestamp": "minute"}, - TimeFrame.H4: {"multiplier": 4, "timestamp": "hour"}, - TimeFrame.D1: {"multiplier": 1, "timestamp": "day"}, - TimeFrame.W1: {"multiplier": 1, "timestamp": "week"}, - TimeFrame.MN: {"multiplier": 1, "timestamp": "month"}, + Timeframe.M1: {"multiplier": 1, "timestamp": "minute"}, + Timeframe.M5: {"multiplier": 5, "timestamp": "minute"}, + Timeframe.M15: {"multiplier": 15, "timestamp": "minute"}, + Timeframe.M30: {"multiplier": 30, "timestamp": "minute"}, + Timeframe.H1: {"multiplier": 1, "timestamp": "minute"}, + Timeframe.H4: {"multiplier": 4, "timestamp": "hour"}, + Timeframe.D1: {"multiplier": 1, "timestamp": "day"}, + Timeframe.W1: {"multiplier": 1, "timestamp": "week"}, + Timeframe.MN: {"multiplier": 1, "timestamp": "month"}, } PolygonInstrumentType = ["stock", "crypto", "forex"] -class Polygon(DataSource): +class Datasource(AbcDataSource): """polygon.io datasource provider. Load data from website polygon. @@ -56,7 +56,7 @@ class Polygon(DataSource): from_date=datetime(2019, 12, 1, 9, 00, 00), to_date=datetime(2019, 12, 15, 23, 00, 00), instrument="MSFT", - timeframe=TimeFrame.M5, + timeframe=Timeframe.M5, ) """ def __init__(self, api_key: str, @@ -89,7 +89,7 @@ def colsmap(self) -> Dict[str, str]: } def get_timeseries(self, from_date: datetime, to_date: datetime, - instrument: str, timeframe: TimeFrame) -> TimeSeries: + instrument: str, timeframe: Timeframe) -> Timeseries: """Retrieve a given timeseries from the datasource. Args: @@ -99,12 +99,12 @@ def get_timeseries(self, from_date: datetime, to_date: datetime, timeframe: target timeframe. Returns: - An Mercury TimeSeries. + An Mercury Timeseries. Raises: IndexError: The requested time range cannot be satisfied. """ - if timeframe is TimeFrame.S: + if timeframe is Timeframe.S: raise ValueError("S interval not supported") if self.instrument_type not in PolygonInstrumentType: @@ -122,4 +122,4 @@ def get_timeseries(self, from_date: datetime, to_date: datetime, from_date, to_date) data = pd.DataFrame(resp.results) - return TimeSeries(instrument, timeframe, data) + return Timeseries(instrument, timeframe, data) diff --git a/test/integration/test_datasource_polygon.py b/test/integration/test_datasource_polygon.py index 0cbd4ce..0d620e4 100644 --- a/test/integration/test_datasource_polygon.py +++ b/test/integration/test_datasource_polygon.py @@ -9,9 +9,9 @@ from datetime import datetime -from mercury import TimeFrame, TimeSeries +from mercury import Timeframe, Timeseries -from mercury.extras.datasources import Polygon +from mercury.extras.datasources.polygon import Datasource from pandas import DataFrame @@ -24,7 +24,7 @@ @pytest.fixture def datasource(): - return Polygon(API_KEY, "stock") + return Datasource(API_KEY, "stock") class TestInstanciation(): @@ -39,32 +39,32 @@ def test_invalid_interval(self, datasource): from_date=datetime(2019, 12, 1, 9, 00, 00), to_date=datetime(2019, 12, 2, 23, 00, 00), instrument="AAPL", - timeframe=TimeFrame.S) + timeframe=Timeframe.S) message = str(error.value) assert message == "S interval not supported" @pytest.mark.online def test_invalid_instrument_type(self): with pytest.raises(ValueError) as error: - datasource = Polygon(API_KEY, "stuck") + datasource = Datasource(API_KEY, "stuck") assert datasource.get_timeseries( from_date=datetime(2019, 12, 1, 9, 00, 00), to_date=datetime(2019, 12, 2, 23, 00, 00), instrument="AAPL", - timeframe=TimeFrame.M5) + timeframe=Timeframe.M5) message = str(error.value) assert message == "Unsupported Polygon instrument type" @pytest.mark.online def test_intraday_data(self, datasource): instrument = "AAPL" - timeframe = TimeFrame.M5 + timeframe = Timeframe.M5 ts = datasource.get_timeseries( from_date=datetime(2019, 12, 1, 9, 00, 00), to_date=datetime(2019, 12, 2, 23, 00, 00), instrument=instrument, timeframe=timeframe) - assert isinstance(ts, TimeSeries) + assert isinstance(ts, Timeseries) assert ts.instrument is instrument assert ts.timeframe is timeframe assert isinstance(ts.data, DataFrame) @@ -72,13 +72,13 @@ def test_intraday_data(self, datasource): # @pytest.mark.online # def test_daily_data(self, datasource): # instrument = "MSFT" - # timeframe = TimeFrame.D1 + # timeframe = Timeframe.D1 # ts = datasource.get_timeseries( # from_date=datetime(2019, 12, 1, 9, 00, 00), # to_date=datetime(2019, 12, 15, 23, 00, 00), # instrument=instrument, # timeframe=timeframe) - # assert isinstance(ts, TimeSeries) + # assert isinstance(ts, Timeseries) # assert ts.instrument is instrument # assert ts.timeframe is timeframe # assert isinstance(ts.data, DataFrame) @@ -86,13 +86,13 @@ def test_intraday_data(self, datasource): # @pytest.mark.online # def test_weekly_data(self, datasource): # instrument = "MSFT" - # timeframe = TimeFrame.W1 + # timeframe = Timeframe.W1 # ts = datasource.get_timeseries( # from_date=datetime(2019, 12, 1, 9, 00, 00), # to_date=datetime(2019, 12, 15, 23, 00, 00), # instrument=instrument, # timeframe=timeframe) - # assert isinstance(ts, TimeSeries) + # assert isinstance(ts, Timeseries) # assert ts.instrument is instrument # assert ts.timeframe is timeframe # assert isinstance(ts.data, DataFrame) @@ -100,13 +100,13 @@ def test_intraday_data(self, datasource): # @pytest.mark.online # def test_monthly_data(self, datasource): # instrument = "MSFT" - # timeframe = TimeFrame.MN + # timeframe = Timeframe.MN # ts = datasource.get_timeseries( # from_date=datetime(2019, 12, 1, 9, 00, 00), # to_date=datetime(2019, 12, 15, 23, 00, 00), # instrument=instrument, # timeframe=timeframe) - # assert isinstance(ts, TimeSeries) + # assert isinstance(ts, Timeseries) # assert ts.instrument is instrument # assert ts.timeframe is timeframe # assert isinstance(ts.data, DataFrame) From be855ec7c2200d2a29df2d70f104a6c94dee48f2 Mon Sep 17 00:00:00 2001 From: Louis-P Lamoureux Date: Fri, 19 Mar 2021 08:47:23 -0400 Subject: [PATCH 3/4] feat: add Polygon Datasource --- src/mercury/extras/datasources/polygon.py | 18 ++-- test/integration/test_datasource_polygon.py | 106 +++++++++++++------- 2 files changed, 76 insertions(+), 48 deletions(-) diff --git a/src/mercury/extras/datasources/polygon.py b/src/mercury/extras/datasources/polygon.py index eebf352..9df32a1 100644 --- a/src/mercury/extras/datasources/polygon.py +++ b/src/mercury/extras/datasources/polygon.py @@ -68,6 +68,10 @@ def __init__(self, api_key: str, instrument_type: the Polygon instrument type [forex, crypto, stock] """ self.api_key = api_key + + if instrument_type not in PolygonInstrumentType: + raise ValueError("Unsupported Polygon instrument type") + self.instrument_type = instrument_type @property @@ -107,19 +111,15 @@ def get_timeseries(self, from_date: datetime, to_date: datetime, if timeframe is Timeframe.S: raise ValueError("S interval not supported") - if self.instrument_type not in PolygonInstrumentType: - raise ValueError("Unsupported Polygon instrument type") - multiplier = TIMEFRAME_MAP[timeframe]["multiplier"] timestamp = TIMEFRAME_MAP[timeframe]["timestamp"] from_date = datetime.strftime(from_date, "%Y-%m-%d") to_date = datetime.strftime(to_date, "%Y-%m-%d") - if self.instrument_type == "stock": - with RESTClient(self.api_key) as client: - resp = client.stocks_equities_aggregates(instrument, - multiplier, timestamp, - from_date, to_date) - data = pd.DataFrame(resp.results) + with RESTClient(self.api_key) as client: + resp = client.stocks_equities_aggregates(instrument, + multiplier, timestamp, + from_date, to_date) + data = pd.DataFrame(resp.results) return Timeseries(instrument, timeframe, data) diff --git a/test/integration/test_datasource_polygon.py b/test/integration/test_datasource_polygon.py index 0d620e4..e54c9a1 100644 --- a/test/integration/test_datasource_polygon.py +++ b/test/integration/test_datasource_polygon.py @@ -56,7 +56,7 @@ def test_invalid_instrument_type(self): assert message == "Unsupported Polygon instrument type" @pytest.mark.online - def test_intraday_data(self, datasource): + def test_intraday_stock_data(self, datasource): instrument = "AAPL" timeframe = Timeframe.M5 ts = datasource.get_timeseries( @@ -69,44 +69,72 @@ def test_intraday_data(self, datasource): assert ts.timeframe is timeframe assert isinstance(ts.data, DataFrame) - # @pytest.mark.online - # def test_daily_data(self, datasource): - # instrument = "MSFT" - # timeframe = Timeframe.D1 - # ts = datasource.get_timeseries( - # from_date=datetime(2019, 12, 1, 9, 00, 00), - # to_date=datetime(2019, 12, 15, 23, 00, 00), - # instrument=instrument, - # timeframe=timeframe) - # assert isinstance(ts, Timeseries) - # assert ts.instrument is instrument - # assert ts.timeframe is timeframe - # assert isinstance(ts.data, DataFrame) + @pytest.mark.online + def test_intraday_forex_data(self, datasource): + instrument = "C:EURUSD" + timeframe = Timeframe.M5 + ts = datasource.get_timeseries( + from_date=datetime(2019, 12, 1, 9, 00, 00), + to_date=datetime(2019, 12, 2, 23, 00, 00), + instrument=instrument, + timeframe=timeframe) + assert isinstance(ts, Timeseries) + assert ts.instrument is instrument + assert ts.timeframe is timeframe + assert isinstance(ts.data, DataFrame) - # @pytest.mark.online - # def test_weekly_data(self, datasource): - # instrument = "MSFT" - # timeframe = Timeframe.W1 - # ts = datasource.get_timeseries( - # from_date=datetime(2019, 12, 1, 9, 00, 00), - # to_date=datetime(2019, 12, 15, 23, 00, 00), - # instrument=instrument, - # timeframe=timeframe) - # assert isinstance(ts, Timeseries) - # assert ts.instrument is instrument - # assert ts.timeframe is timeframe - # assert isinstance(ts.data, DataFrame) + @pytest.mark.online + def test_intraday_crypto_data(self, datasource): + instrument = "X:BTCUSD" + timeframe = Timeframe.M5 + ts = datasource.get_timeseries( + from_date=datetime(2019, 12, 1, 9, 00, 00), + to_date=datetime(2019, 12, 2, 23, 00, 00), + instrument=instrument, + timeframe=timeframe) + assert isinstance(ts, Timeseries) + assert ts.instrument is instrument + assert ts.timeframe is timeframe + assert isinstance(ts.data, DataFrame) # @pytest.mark.online - # def test_monthly_data(self, datasource): - # instrument = "MSFT" - # timeframe = Timeframe.MN - # ts = datasource.get_timeseries( - # from_date=datetime(2019, 12, 1, 9, 00, 00), - # to_date=datetime(2019, 12, 15, 23, 00, 00), - # instrument=instrument, - # timeframe=timeframe) - # assert isinstance(ts, Timeseries) - # assert ts.instrument is instrument - # assert ts.timeframe is timeframe - # assert isinstance(ts.data, DataFrame) + def test_daily_data(self, datasource): + instrument = "MSFT" + timeframe = Timeframe.D1 + ts = datasource.get_timeseries( + from_date=datetime(2019, 12, 1, 9, 00, 00), + to_date=datetime(2019, 12, 15, 23, 00, 00), + instrument=instrument, + timeframe=timeframe) + assert isinstance(ts, Timeseries) + assert ts.instrument is instrument + assert ts.timeframe is timeframe + assert isinstance(ts.data, DataFrame) + + @pytest.mark.online + def test_weekly_data(self, datasource): + instrument = "MSFT" + timeframe = Timeframe.W1 + ts = datasource.get_timeseries( + from_date=datetime(2019, 12, 1, 9, 00, 00), + to_date=datetime(2019, 12, 15, 23, 00, 00), + instrument=instrument, + timeframe=timeframe) + assert isinstance(ts, Timeseries) + assert ts.instrument is instrument + assert ts.timeframe is timeframe + assert isinstance(ts.data, DataFrame) + + @pytest.mark.online + def test_monthly_data(self, datasource): + instrument = "MSFT" + timeframe = Timeframe.MN + ts = datasource.get_timeseries( + from_date=datetime(2019, 12, 1, 9, 00, 00), + to_date=datetime(2019, 12, 15, 23, 00, 00), + instrument=instrument, + timeframe=timeframe) + assert isinstance(ts, Timeseries) + assert ts.instrument is instrument + assert ts.timeframe is timeframe + assert isinstance(ts.data, DataFrame) From 571a1b2ec60bc66bef8f37b3da27ce031a6349ad Mon Sep 17 00:00:00 2001 From: Louis-P Lamoureux Date: Sat, 20 Mar 2021 14:34:32 -0400 Subject: [PATCH 4/4] chore: remove api key --- test/integration/test_datasource_polygon.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/integration/test_datasource_polygon.py b/test/integration/test_datasource_polygon.py index e54c9a1..d4c880c 100644 --- a/test/integration/test_datasource_polygon.py +++ b/test/integration/test_datasource_polygon.py @@ -19,7 +19,6 @@ # API_KEY = os.environ['POLYGON_API_KEY'] # API_KEY = 'TEST' -API_KEY = '0mEGmDxsPUtn7M8VDEhyYi7D3oQ5OuPh' @pytest.fixture