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 #119 from timkpaine/updates
Browse files Browse the repository at this point in the history
Implement technicals, fix a few stock endpoints to support `period` and `last`, add field indexing for keyStats
  • Loading branch information
timkpaine authored Aug 27, 2020
2 parents b396bf6 + f43caf7 commit 8a62284
Show file tree
Hide file tree
Showing 7 changed files with 736 additions and 35 deletions.
3 changes: 3 additions & 0 deletions pyEX/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
stockSplits, stockSplitsDF, \
tenQ, tenK, \
threshold, thresholdDF, \
technicals, technicalsDF, \
timeSeriesInventory, timeSeries, \
timeSeriesInventoryDF, timeSeriesDF, \
upcomingEvents, upcomingEventsDF, \
Expand Down Expand Up @@ -360,6 +361,8 @@
('stockSplitsDF', stockSplitsDF),
('tenQ', tenQ),
('tenK', tenK),
('technicals', technicals),
('technicalsDF', technicalsDF),
('timeSeriesInventory', timeSeriesInventory),
('timeSeriesInventoryDF', timeSeriesInventoryDF),
('timeSeries', timeSeries),
Expand Down
259 changes: 258 additions & 1 deletion pyEX/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,38 @@
'next-week',
'next-month',
'next-quarter']

_KEY_STATS = [
'companyName',
'marketcap',
'week52high',
'week52low',
'week52change',
'sharesOutstanding',
'float',
'avg10Volume',
'avg30Volume',
'day200MovingAvg',
'day50MovingAvg',
'employees',
'ttmEPS',
'ttmDividendRate',
'dividendYield',
'nextDividendDate',
'exDividendDate',
'nextEarningsDate',
'peRatio',
'beta',
'maxChangePercent',
'year5ChangePercent',
'year2ChangePercent',
'year1ChangePercent',
'ytdChangePercent',
'month6ChangePercent',
'month3ChangePercent',
'month1ChangePercent',
'day30ChangePercent',
'day5ChangePercent',
]
_USAGE_TYPES = ['messages', 'rules', 'rule-records', 'alerts', 'alert-records']
_PYEX_PROXIES = None
_PYEX_CACHE_FOLDER = os.path.abspath(os.path.join(tempfile.gettempdir(), "pyEX"))
Expand Down Expand Up @@ -122,6 +153,220 @@
'reportDate',
'report_date']

_INDICATORS = [
"abs",
"acos",
"ad",
"add",
"adosc",
"adx",
"adxr",
"ao",
"apo",
"aroon",
"aroonosc",
"asin",
"atan",
"atr",
"avgprice",
"bbands",
"bop",
"cci",
"ceil",
"cmo",
"cos",
"cosh",
"crossany",
"crossover",
"cvi",
"decay",
"dema",
"di",
"div",
"dm",
"dpo",
"dx",
"edecay",
"ema",
"emv",
"exp",
"fisher",
"floor",
"fosc",
"hma",
"kama",
"kvo",
"lag",
"linreg",
"linregintercept",
"linregslope",
"ln",
"log10",
"macd",
"marketfi",
"mass",
"max",
"md",
"medprice",
"mfi",
"min",
"mom",
"msw",
"mul",
"natr",
"nvi",
"obv",
"ppo",
"psar",
"pvi",
"qstick",
"roc",
"rocr",
"round",
"rsi",
"sin",
"sinh",
"sma",
"sqrt",
"stddev",
"stderr",
"stoch",
"stochrsi",
"sub",
"sum",
"tan",
"tanh",
"tema",
"todeg",
"torad",
"tr",
"trima",
"trix",
"trunc",
"tsf",
"typprice",
"ultosc",
"var",
"vhf",
"vidya",
"volatility",
"vosc",
"vwma",
"wad",
"wcprice",
"wilders",
"willr",
"wma",
"zlema",
]

_INDICATOR_RETURNS = {
"abs": ("abs",),
"acos": ("acos",),
"ad": ("ad",),
"add": ("add",),
"adosc": ("adosc",),
"adx": ("dx",),
"adxr": ("dx",),
"ao": ("ao",),
"apo": ("apo",),
"aroon": ("aroon_down", "aroon_up"),
"aroonosc": ("aroonosc",),
"asin": ("asin",),
"atan": ("atan",),
"atr": ("atr",),
"avgprice": ("avgprice",),
"bbands": ("bbands_lower", "bbands_middle", "bbands_upper",),
"bop": ("bop",),
"cci": ("cci",),
"ceil": ("ceil",),
"cmo": ("cmo",),
"cos": ("cos",),
"cosh": ("cosh",),
"crossany": ("crossany",),
"crossover": ("crossover",),
"cvi": ("cvi",),
"decay": ("decay",),
"dema": ("dema",),
"di": ("plus_di", "minus_di",),
"div": ("div",),
"dm": ("plus_dm", "minus_dm",),
"dpo": ("dop",),
"dx": ("dx",),
"edecay": ("edecay",),
"ema": ("ema",),
"emv": ("emv",),
"exp": ("exp",),
"fisher": ("fisher", "fisher_signal",),
"floor": ("floor",),
"fosc": ("fosc",),
"hma": ("hma",),
"kama": ("kama",),
"kvo": ("kvo",),
"lag": ("lag",),
"linreg": ("linreg",),
"linregintercept": ("linregintercept",),
"linregslope": ("linregslope",),
"ln": ("ln",),
"log10": ("log10",),
"macd": ("macd", "macd_signal", "macd_histogram",),
"marketfi": ("marketfi",),
"mass": ("mass",),
"max": ("max",),
"md": ("md",),
"medprice": ("medprice",),
"mfi": ("mfi",),
"min": ("min",),
"mom": ("mom",),
"msw": ("msw_sine", "msw_lead",),
"mul": ("mul",),
"natr": ("matr",),
"nvi": ("nvi",),
"obv": ("obv",),
"ppo": ("ppo",),
"psar": ("psar",),
"pvi": ("pvi",),
"qstick": ("qstick",),
"roc": ("roc",),
"rocr": ("rocr",),
"round": ("round",),
"rsi": ("rsi",),
"sin": ("sin",),
"sinh": ("sinh",),
"sma": ("sma",),
"sqrt": ("sqrt",),
"stddev": ("stddev",),
"stderr": ("stderr",),
"stoch": ("stock_k", "stock_d",),
"stochrsi": ("stochrsi",),
"sub": ("sub",),
"sum": ("sum",),
"tan": ("tan",),
"tanh": ("tanh",),
"tema": ("tema",),
"todeg": ("degrees",),
"torad": ("radians",),
"tr": ("tr",),
"trima": ("trima",),
"trix": ("trix",),
"trunc": ("trunc",),
"tsf": ("tsf",),
"typprice": ("typprice",),
"ultosc": ("ultosc",),
"var": ("var",),
"vhf": ("vhf",),
"vidya": ("vidya",),
"volatility": ("volatility",),
"vosc": ("vosc",),
"vwma": ("vwma",),
"wad": ("wad",),
"wcprice": ("wcprice",),
"wilders": ("wilders",),
"willr": ("willr",),
"wma": ("wma",),
"zlema": ("zlema",),
}


class PyEXception(Exception):
pass
Expand Down Expand Up @@ -208,6 +453,18 @@ def _raiseIfNotStr(s):
raise PyEXception('Cannot use type %s' % str(type(s)))


def _checkPeriodLast(per, last):
'''check if period is ok with last'''
if per not in ("quarter", "annual"):
raise PyEXception("Period must be in {'quarter', 'annual'}")
if per == 'quarter':
if last < 1 or last > 12:
raise PyEXception("Last must be in [1, 12] for period 'quarter'")
else:
if last < 1 or last > 4:
raise PyEXception("Last must be in [1, 4] for period 'annual'")


def _tryJson(data, raw=True):
'''internal'''
if raw:
Expand Down
3 changes: 2 additions & 1 deletion pyEX/stocks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
from .research import (advancedStats, advancedStatsDF, analystRecommendations, analystRecommendationsDF, # noqa: F401
estimates, estimatesDF, fundOwnership, # noqa: F401
fundOwnershipDF, institutionalOwnership, institutionalOwnershipDF, # noqa: F401
keyStats, keyStatsDF, priceTarget, priceTargetDF) # noqa: F401
keyStats, keyStatsDF, priceTarget, priceTargetDF,
technicals, technicalsDF) # noqa: F401

from .stocks import threshold, thresholdDF, shortInterest, shortInterestDF # noqa: F401

Expand Down
Loading

0 comments on commit 8a62284

Please sign in to comment.