Skip to content
This repository has been archived by the owner on Jun 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #237 from iexcloud/metadata
Browse files Browse the repository at this point in the history
add metadata
  • Loading branch information
timkpaine authored Mar 28, 2021
2 parents e994991 + d314321 commit 5782aeb
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
1 change: 1 addition & 0 deletions pyEX/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
11 changes: 9 additions & 2 deletions pyEX/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 (
Expand Down Expand Up @@ -863,6 +865,10 @@
("searchDF", searchDF),
("tags", tags),
("tagsDF", tagsDF),
# Metadata
# TODO move?
("queryMetadata", queryMetadata),
("queryMetadataDF", queryMetadataDF),
]

_INCLUDE_FUNCTIONS_MARKET = [
Expand Down Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions pyEX/metadata/__init__.py
Original file line number Diff line number Diff line change
@@ -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))
2 changes: 2 additions & 0 deletions pyEX/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ def test_all(self):
"productEventsWallStreetHorizon",
"productEventsWallStreetHorizonDF",
"propane",
"queryMetadata",
"queryMetadataDF",
"quote",
"quoteDF",
"recent",
Expand Down
7 changes: 7 additions & 0 deletions pyEX/tests/test_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 5782aeb

Please sign in to comment.