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 #160 from timkpaine/options_date
Browse files Browse the repository at this point in the history
Fixes #157 - options date and time fields
  • Loading branch information
timkpaine authored Dec 5, 2020
2 parents 2591994 + 5916215 commit 564c612
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 37 deletions.
59 changes: 34 additions & 25 deletions pyEX/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,51 +138,53 @@
]

_STANDARD_DATE_FIELDS = [
"consensusEndDate",
"consensusStartDate",
"DailyListTimestamp",
"date",
"datetime",
"declaredDate",
"EPSReportDate",
"fiscalEndDate",
"endDate",
"exDate",
"declaredDate",
"paymentDate",
"recordDate",
"reportDate",
"datetime",
"expectedDate",
"expirationDate",
"fiscalEndDate",
"latestTime",
"DailyListTimestamp",
"RecordUpdateTime",
"settlementDate",
"lastTradeDate",
"lastUpdated",
"paymentDate",
"processedTime",
"expirationDate",
"recordDate",
"RecordUpdateTime",
"reportDate",
"settlementDate",
"startDate",
"endDate",
"consensusEndDate",
"consensusStartDate",
]

_STANDARD_TIME_FIELDS = [
"closeTime",
"close.time",
"delayedPriceTime",
"extendedPriceTime",
"highTime",
"iexCloseTime",
"iexLastUpdated",
"iexOpenTime",
"lastTradeTime",
"lastUpdated",
"latestTime",
"latestUpdate",
"lowTime",
"oddLotDelayedPriceTime",
"openTime",
"open.time",
"processedTime",
"report_date",
"reportDate",
"time",
"timestamp",
"lastUpdated",
"reportDate",
"report_date",
"iexOpenTime",
"iexCloseTime",
"lastTradeTime",
"highTime",
"lowTime",
"latestUpdate",
"oddLotDelayedPriceTime",
"updated",
]

_INDICATORS = [
Expand Down Expand Up @@ -794,8 +796,15 @@ def _reindex(df, col):

def _toDatetime(df, cols=None, tcols=None):
"""internal"""
cols = cols if cols is not None else _STANDARD_DATE_FIELDS
tcols = tcols if tcols is not None else _STANDARD_TIME_FIELDS
if not isinstance(cols, list):
cols = [cols]
if not isinstance(tcols, list):
tcols = [tcols]

cols = cols + _STANDARD_DATE_FIELDS if cols is not None else _STANDARD_DATE_FIELDS
tcols = (
tcols + _STANDARD_TIME_FIELDS if tcols is not None else _STANDARD_TIME_FIELDS
)

for col in cols:
if col in df.columns:
Expand Down
2 changes: 1 addition & 1 deletion pyEX/options/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ def options(symbol, expiration, side="", token="", version="", filter=""):
def optionsDF(symbol, expiration, side="", token="", version="", filter=""):
p = options(symbol, expiration, side, token, version, filter)
df = pd.DataFrame(p)
_toDatetime(df)
_toDatetime(df, tcols=["date"])
return df
39 changes: 28 additions & 11 deletions pyEX/refdata/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def symbolsDF(token="", version="", filter=""):
df = pd.DataFrame(symbols(token, version, filter))
_toDatetime(df)
_reindex(df, "symbol")
df.sort_index(inplace=True)
return df


Expand All @@ -177,6 +178,7 @@ def iexSymbolsDF(token="", version="", filter=""):
df = pd.DataFrame(iexSymbols(token, version, filter))
_toDatetime(df)
_reindex(df, "symbol")
df.sort_index(inplace=True)
return df


Expand All @@ -185,6 +187,7 @@ def mutualFundSymbolsDF(token="", version="", filter=""):
df = pd.DataFrame(mutualFundSymbols(token, version, filter))
_toDatetime(df)
_reindex(df, "symbol")
df.sort_index(inplace=True)
return df


Expand All @@ -193,6 +196,7 @@ def otcSymbolsDF(token="", version="", filter=""):
df = pd.DataFrame(otcSymbols(token, version, filter))
_toDatetime(df)
_reindex(df, "symbol")
df.sort_index(inplace=True)
return df


Expand All @@ -201,6 +205,7 @@ def internationalSymbolsDF(region="", exchange="", token="", version="", filter=
df = pd.DataFrame(internationalSymbols(region, exchange, token, version, filter))
_toDatetime(df)
_reindex(df, "symbol")
df.sort_index(inplace=True)
return df


Expand All @@ -210,6 +215,8 @@ def fxSymbolsDF(token="", version=""):
df1 = pd.DataFrame(fx["currencies"])
df2 = pd.DataFrame(fx["pairs"])
_reindex(df1, "code")
df1.sort_index(inplace=True)
df2.sort_index(inplace=True)
return [df1, df2]


Expand All @@ -218,6 +225,7 @@ def optionsSymbolsDF(token="", version="", filter=""):
df = json_normalize(optionsSymbols(token, version, filter))
df = df.T
df.columns = ["expirations"]
df.sort_index(inplace=True)
return df


Expand All @@ -226,35 +234,42 @@ def cryptoSymbolsDF(token="", version="", filter=""):
df = pd.DataFrame(cryptoSymbols(token, version, filter))
_toDatetime(df)
_reindex(df, "symbol")
df.sort_index(inplace=True)
return df


@wraps(symbols)
def symbolsList(token="", version=""):
return [x["symbol"] for x in symbols(token, version, filter="symbol")]
return sorted([x["symbol"] for x in symbols(token, version, filter="symbol")])


@wraps(iexSymbols)
def iexSymbolsList(token="", version=""):
return [x["symbol"] for x in iexSymbols(token, version, filter="symbol")]
return sorted([x["symbol"] for x in iexSymbols(token, version, filter="symbol")])


@wraps(mutualFundSymbols)
def mutualFundSymbolsList(token="", version=""):
return [x["symbol"] for x in mutualFundSymbols(token, version, filter="symbol")]
return sorted(
[x["symbol"] for x in mutualFundSymbols(token, version, filter="symbol")]
)


@wraps(otcSymbols)
def otcSymbolsList(token="", version=""):
return [x["symbol"] for x in otcSymbols(token, version, filter="symbol")]
return sorted([x["symbol"] for x in otcSymbols(token, version, filter="symbol")])


@wraps(internationalSymbols)
def internationalSymbolsList(region="", exchange="", token="", version=""):
return [
x["symbol"]
for x in internationalSymbols(region, exchange, token, version, filter="symbol")
]
return sorted(
[
x["symbol"]
for x in internationalSymbols(
region, exchange, token, version, filter="symbol"
)
]
)


@wraps(fxSymbols)
Expand All @@ -265,17 +280,19 @@ def fxSymbolsList(token="", version=""):
ret[0].append(c["code"])
for p in fx["pairs"]:
ret[1].append(p["fromCurrency"] + p["toCurrency"])
return ret
return sorted(ret)


@wraps(optionsSymbols)
def optionsSymbolsList(token="", version=""):
return [x["symbol"] for x in optionsSymbols(token, version, filter="symbol")]
return sorted(
[x["symbol"] for x in optionsSymbols(token, version, filter="symbol")]
)


@wraps(cryptoSymbols)
def cryptoSymbolsList(token="", version=""):
return [x["symbol"] for x in cryptoSymbols(token, version, filter="symbol")]
return sorted([x["symbol"] for x in cryptoSymbols(token, version, filter="symbol")])


def isinLookup(isin, token="", version=""):
Expand Down

0 comments on commit 564c612

Please sign in to comment.