mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-01 23:12:21 +00:00
* implement user and change is guest * replace User methods * move remaining functions to user * fix bug * portfolio test * fix tests * fix tests * uncomment skip * ruff * start credentials model implementation * change deault structure * refacto quandl * change default struct and file names * bug * start using global user * add comments * move update flair * change cfg references in keys model * reddit & fmp * refactore additional keys * remaing config keys * remove unsude imports and fix hub keys * ruff * fix line too long * unblock unittests * fix keys model tests * remove os patch * fix account controller tests * fix account controller tests * fix account model * account fixed * fix user tests * User Model * User Model * User Model * Move session folder * User Model : grouping the models * User Model : fix bugs * Config Plot + bug fix * User Model : Refactoring plots * Feature flags * Remove dup * clean comments a fix some vars * fix feature flags controller * refactor obbff from settings controller * refactor a bunch of obbff variables * fix bug blocking terminal * fix integration tests * refactor controllers with obbff * refactor remaining ffs * remove comments * log not started * mispelled variable * set current user on local model * User Model : moving files + updating * User Preferences * User : Refactor is_guest function + bug fix * User : refactor is_guest function * Fix conftest.py * remove lost obbffs * typo on fileoverwrite * Plot config: move variables and start plot dpi * User : tests * refactor plot dpi references * remove plot dpi imports * refactor some config terminal leftover * /account/sync : fix bug * remove configs reload * start path refactor * installation paths vs user paths * remove cfg_plot * Tests : User Refactoring * user prefix only for preferences * user prefix only for preferences * move user paths * remove comment * update apply remote configs * fix tz not updating * save some copys * small fix * create interface for credentials and preferences * wrong docstrings fixed * ruff core * fix some pref setting * login is better * ruff * ruff * remove Literal * add small comment * Tests : User Refactoring * Credentials Model : add DataBento * Fix helper_funcs * Fixing code * Tests : fixing * User Model : freezing the models * Fixed Income + Databento * Tests : fixing keys * black * ruff * Tests : user model * Tests : user model * Fix linting * Fix linting * Linting * Linting * Fixing code and tests * Fix tests * mypy * SDK * Clean ruff cache * Fix syntax issue * Update fred_view * Black * Linting * Update code * Update tests * Linting * Linting * Tests * Black * Linting * Linting * Mock os.listdir to avoid looking for file that doesnt exist * Mock options paths * lint * Tests : fix * Code : update * Tests + Linting * Tests * Ruff * Code : update * Tests * Code : update * Fix workflow * Code : update --------- Co-authored-by: Chavithra PARANA <chavithra@gmail.com> Co-authored-by: luqazino@gmail.com <luqazino@gmail.com> Co-authored-by: James Maslek <jmaslek11@gmail.com>
122 lines
3.2 KiB
Python
122 lines
3.2 KiB
Python
"""Tradingview model"""
|
|
__docformat__ = "numpy"
|
|
|
|
import logging
|
|
|
|
import pandas as pd
|
|
from tradingview_ta import TA_Handler
|
|
|
|
from openbb_terminal.core.session.current_user import get_current_user
|
|
from openbb_terminal.decorators import log_start_end
|
|
from openbb_terminal.helper_funcs import request
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
INTERVALS = {
|
|
"1m": "1 min",
|
|
"5m": "5 min",
|
|
"15m": "15 min",
|
|
"1h": "1 hour",
|
|
"4h": "4 hours",
|
|
"1d": "1 day",
|
|
"1W": "1 week",
|
|
"1M": "1 month",
|
|
}
|
|
|
|
SCREENERS = [
|
|
"australia",
|
|
"brazil",
|
|
"cfd",
|
|
"crypto",
|
|
"euronext",
|
|
"forex",
|
|
"france",
|
|
"germany",
|
|
"hongkong",
|
|
"india",
|
|
"indonesia",
|
|
"malaysia",
|
|
"philippines",
|
|
"russia",
|
|
"ksa",
|
|
"rsa",
|
|
"korea",
|
|
"spain",
|
|
"sweden",
|
|
"taiwan",
|
|
"thailand",
|
|
"turkey",
|
|
"uk",
|
|
"america",
|
|
"vietnam",
|
|
]
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def get_tradingview_recommendation(
|
|
symbol: str, screener: str = "america", exchange: str = "", interval: str = ""
|
|
) -> pd.DataFrame:
|
|
"""Get tradingview recommendation based on technical indicators
|
|
|
|
Parameters
|
|
----------
|
|
symbol : str
|
|
Ticker symbol to get the recommendation from tradingview based on technical indicators
|
|
screener : str
|
|
Screener based on tradingview docs https://python-tradingview-ta.readthedocs.io/en/latest/usage.html
|
|
exchange: str
|
|
Exchange based on tradingview docs https://python-tradingview-ta.readthedocs.io/en/latest/usage.html
|
|
interval: str
|
|
Interval time to check technical indicators and correspondent recommendation
|
|
|
|
Returns
|
|
-------
|
|
df_recommendation: pd.DataFrame
|
|
Dataframe of tradingview recommendations based on technical indicators
|
|
"""
|
|
|
|
if not exchange:
|
|
current_user = get_current_user()
|
|
s_req = (
|
|
f"https://www.alphavantage.co/query?function=OVERVIEW&symbol={symbol}&"
|
|
f"apikey={current_user.credentials.API_KEY_ALPHAVANTAGE}"
|
|
)
|
|
result = request(s_req, stream=True)
|
|
data = result.json()
|
|
if not data:
|
|
return pd.DataFrame()
|
|
exchange = data["Exchange"]
|
|
|
|
intervals = (
|
|
[interval] if interval else ["1M", "1W", "1d", "4h", "1h", "15m", "5m", "1m"]
|
|
)
|
|
|
|
df_recommendation = pd.DataFrame()
|
|
index_recommendation = []
|
|
for an_interval in intervals:
|
|
if exchange:
|
|
stock_recommendation = TA_Handler(
|
|
symbol=symbol,
|
|
screener=screener,
|
|
exchange=exchange,
|
|
interval=an_interval,
|
|
)
|
|
d_recommendation = stock_recommendation.get_analysis().summary
|
|
df_recommendation = pd.concat(
|
|
[
|
|
pd.DataFrame.from_dict(d_recommendation, orient="index").T,
|
|
df_recommendation,
|
|
],
|
|
axis=0,
|
|
)
|
|
index_recommendation.append(INTERVALS[an_interval])
|
|
|
|
df_recommendation.index = index_recommendation
|
|
df_recommendation[["BUY", "NEUTRAL", "SELL"]] = df_recommendation[
|
|
["BUY", "NEUTRAL", "SELL"]
|
|
].astype(int)
|
|
|
|
df_recommendation.index.name = "Interval"
|
|
|
|
return df_recommendation
|