diff --git a/pyEX/__init__.py b/pyEX/__init__.py index 9ac76c2..1435fba 100644 --- a/pyEX/__init__.py +++ b/pyEX/__init__.py @@ -22,6 +22,7 @@ from .files import * from .fx import * from .markets import * +from .metadata import * from .options import * from .points import * from .premium import * diff --git a/pyEX/client.py b/pyEX/client.py index 6414c03..b33a0d8 100644 --- a/pyEX/client.py +++ b/pyEX/client.py @@ -8,6 +8,7 @@ import os import types from functools import partial, wraps +import warnings from .account import messageBudget, metadata, metadataDF, usage, usageDF from .alternative import ceoCompensation, ceoCompensationDF, sentiment, sentimentDF @@ -32,6 +33,7 @@ latestFXDF, ) from .markets import markets, marketsDF +from .metadata import queryMetadata, queryMetadataDF from .options import optionExpirations, options, optionsDF from .points import points, pointsDF from .premium import ( @@ -863,6 +865,10 @@ ("searchDF", searchDF), ("tags", tags), ("tagsDF", tagsDF), + # Metadata + # TODO move? + ("queryMetadata", queryMetadata), + ("queryMetadataDF", queryMetadataDF), ] _INCLUDE_FUNCTIONS_MARKET = [ @@ -1624,9 +1630,10 @@ def __init__(self, api_token=None, version="v1", api_limit=DEFAULT_API_LIMIT): raise PyEXception("Unrecognized api version: {}".format(version)) if self._token.startswith("T") and version != "sandbox": - raise PyEXception( - "Using test key but attempting to connect to non-sandbox environment" + warnings.warn( + "Using test key but attempting to connect to non-sandbox environment. Switching to sandbox" ) + version = "sandbox" self._version = version self._api_limit = api_limit diff --git a/pyEX/metadata/__init__.py b/pyEX/metadata/__init__.py new file mode 100644 index 0000000..d8208da --- /dev/null +++ b/pyEX/metadata/__init__.py @@ -0,0 +1,39 @@ +# ***************************************************************************** +# +# Copyright (c) 2022, the pyEX authors. +# +# This file is part of the pyEX library, distributed under the terms of +# the Apache License 2.0. The full license can be found in the LICENSE file. +# +from functools import wraps +import pandas as pd +from ..common import _get + + +def queryMetadata( + id="", key="", subkey="", token="", version="stable", filter="", format="json" +): + """Get inventory of available time series endpoints + + Args: + id (str): Timeseries ID + key (str): Timeseries Key + subkey (str): Timeseries Subkey + token (str): Access token + version (str): API version + filter (str): https://iexcloud.io/docs/api/#filter-results + format (str): output format + """ + url = "metadata/time-series" + if id: + url += "/{}".format(id) + if key: + url += "/{}".format(key) + if subkey: + url += "/{}".format(subkey) + return _get(url, token=token, version=version, filter=filter, format=format) + + +@wraps(queryMetadata) +def queryMetadataDF(*args, **kwargs): + return pd.DataFrame(queryMetadata(*args, **kwargs)) diff --git a/pyEX/tests/test_api.py b/pyEX/tests/test_api.py index 67ec740..f3a8459 100644 --- a/pyEX/tests/test_api.py +++ b/pyEX/tests/test_api.py @@ -527,6 +527,8 @@ def test_all(self): "productEventsWallStreetHorizon", "productEventsWallStreetHorizonDF", "propane", + "queryMetadata", + "queryMetadataDF", "quote", "quoteDF", "recent", diff --git a/pyEX/tests/test_api_client.py b/pyEX/tests/test_api_client.py index f2385de..3a3985b 100644 --- a/pyEX/tests/test_api_client.py +++ b/pyEX/tests/test_api_client.py @@ -107,6 +107,13 @@ def test_all_markets(self): assert hasattr(self.c, meth) assert hasattr(self.c.market, meth) + def test_all_metadata(self): + for meth in ( + "queryMetadata", + "queryMetadataDF", + ): + assert hasattr(self.c, meth) + def test_all_stats(self): for meth in ( "systemStats",