From b194d625caf7e64dd58f727adad9f1b8ba5fb7bd Mon Sep 17 00:00:00 2001 From: jose-donato Date: Wed, 15 Feb 2023 00:15:46 +0000 Subject: [PATCH 01/14] fix: remove old commands --- .../onchain/onchain_controller.py | 135 +++--------------- .../cryptocurrency/onchain/shroom_model.py | 31 +++- .../cryptocurrency/onchain/shroom_view.py | 39 +++++ .../miscellaneous/data_sources_default.json | 19 +-- openbb_terminal/miscellaneous/i18n/en.yml | 4 +- 5 files changed, 94 insertions(+), 134 deletions(-) diff --git a/openbb_terminal/cryptocurrency/onchain/onchain_controller.py b/openbb_terminal/cryptocurrency/onchain/onchain_controller.py index b3f07b714943..1ad9974cbc61 100644 --- a/openbb_terminal/cryptocurrency/onchain/onchain_controller.py +++ b/openbb_terminal/cryptocurrency/onchain/onchain_controller.py @@ -82,9 +82,7 @@ class OnchainController(BaseController): "btccp", "btcct", "btcblockdata", - "dt", - "ds", - "tvl", + "query" ] PATH = "/crypto/onchain/" @@ -101,9 +99,6 @@ def __init__(self, queue: List[str] = None): choices: dict = self.choices_default choices["hr"].update({c: {} for c in GLASSNODE_SUPPORTED_HASHRATE_ASSETS}) - choices["ds"].update( - {c: None for c in shroom_model.DAPP_STATS_PLATFORM_CHOICES} - ) self.completer = NestedCompleter.from_nested_dict(choices) @@ -122,9 +117,7 @@ def print_help(self): mt.add_cmd("ueat") mt.add_cmd("ttcp") mt.add_cmd("baas") - mt.add_cmd("dt") - mt.add_cmd("ds") - mt.add_cmd("tvl") + mt.add_cmd("query") mt.add_raw("\n") mt.add_param("_address", self.address or "") mt.add_param("_type", self.address_type or "") @@ -142,136 +135,40 @@ def print_help(self): console.print(text=mt.menu_text, menu="Cryptocurrency - Onchain") @log_start_end(log=logger) - def call_tvl(self, other_args: List[str]): - """Process tvl command""" + def call_query(self, other_args: List[str]): + """Process query command""" parser = argparse.ArgumentParser( add_help=False, formatter_class=argparse.ArgumentDefaultsHelpFormatter, - prog="tvl", + prog="query", description=""" - Total value locked (TVL) metric - Ethereum ERC20 + Make any flipsidecrypto query [Source:https://docs.flipsidecrypto.com/] - useraddress OR addressname must be provided """, ) parser.add_argument( - "-u", - "--useraddress", - dest="useraddress", + "-q", + "--query", + dest="query", type=str, - help="User address we'd like to take a balance reading of against the contract", - ) - - parser.add_argument( - "-a", - "--addressname", - dest="addressname", - type=str, - help="Address name corresponding to the user address", - ) - - parser.add_argument( - "-s", - "--symbol", - dest="symbol", - type=str, - help="Contract symbol", - default="USDC", - ) - - parser.add_argument( - "-i", - "--interval", - dest="interval", - type=int, - help="Interval in months", - default=12, + nargs="+", + required=True, + help="Query to make", ) if other_args and not other_args[0][0] == "-": - other_args.insert(0, "-u") + other_args.insert(0, "-q") ns_parser = self.parse_known_args_and_warn( - parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES + parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES, limit=10 ) if ns_parser: - shroom_view.display_total_value_locked( - user_address=ns_parser.useraddress, - address_name=ns_parser.addressname, - interval=ns_parser.interval, - symbol=ns_parser.symbol, + shroom_view.display_query( + query=" ".join(ns_parser.query), export=ns_parser.export, - sheet_name=" ".join(ns_parser.sheet_name) - if ns_parser.sheet_name - else None, - ) - - @log_start_end(log=logger) - def call_ds(self, other_args: List[str]): - """Process ds command""" - parser = argparse.ArgumentParser( - add_help=False, - formatter_class=argparse.ArgumentDefaultsHelpFormatter, - prog="ds", - description=""" - Get daily transactions for certain symbols in ethereum blockchain - [Source: https://sdk.flipsidecrypto.xyz/shroomdk] - """, - ) - - parser.add_argument( - "-p", - "--platform", - dest="platform", - type=str, - help="Ethereum platform to check fees/number of users over time", - default="curve", - choices=shroom_model.DAPP_STATS_PLATFORM_CHOICES, - ) - - if other_args and not other_args[0][0] == "-": - other_args.insert(0, "-p") - - ns_parser = self.parse_known_args_and_warn( - parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES, raw=True, limit=10 - ) - - if ns_parser: - shroom_view.display_dapp_stats( - raw=ns_parser.raw, limit=ns_parser.limit, - platform=ns_parser.platform, - export=ns_parser.export, - sheet_name=" ".join(ns_parser.sheet_name) - if ns_parser.sheet_name - else None, - ) - - @log_start_end(log=logger) - def call_dt(self, other_args: List[str]): - """Process dt command""" - parser = argparse.ArgumentParser( - add_help=False, - formatter_class=argparse.ArgumentDefaultsHelpFormatter, - prog="dt", - description=""" - Get daily transactions for certain symbols in ethereum blockchain - [Source: https://sdk.flipsidecrypto.xyz/shroomdk] - """, - ) - - ns_parser = self.parse_known_args_and_warn( - parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES - ) - - if ns_parser: - shroom_view.display_daily_transactions( - export=ns_parser.export, - sheet_name=" ".join(ns_parser.sheet_name) - if ns_parser.sheet_name - else None, ) @log_start_end(log=logger) diff --git a/openbb_terminal/cryptocurrency/onchain/shroom_model.py b/openbb_terminal/cryptocurrency/onchain/shroom_model.py index de8f503072e7..187958769cd5 100644 --- a/openbb_terminal/cryptocurrency/onchain/shroom_model.py +++ b/openbb_terminal/cryptocurrency/onchain/shroom_model.py @@ -77,6 +77,29 @@ def get_shroom_data(sql: str): return data +@log_start_end(log=logger) +@check_api_key(["API_SHROOM_KEY"]) +def get_query_data(sql: str) -> pd.DataFrame: + """Get query data + + Parameters + ---------- + sql : str + SQL query + + Returns + ------- + pd.DataFrame + DataFrame with query data + """ + data = get_shroom_data(sql) + + if data and data["results"] and data["columnLabels"]: + df = pd.DataFrame(data["results"], columns=data["columnLabels"]) + return df + + return pd.DataFrame() + @log_start_end(log=logger) @check_api_key(["API_SHROOM_KEY"]) def get_dapp_stats( @@ -99,8 +122,8 @@ def get_dapp_stats( sum(t.fee_usd) as fee, count(distinct(s.from_address)) as n_users, count(distinct(s.amount_usd)) as volume - from ethereum.dex_swaps s - join ethereum.transactions t + from ethereum.core.ez_dex_swaps s + join ethereum.core.fact_transactions t on s.tx_id = t.tx_id where platform = '{platform}' group by date @@ -147,7 +170,7 @@ def get_daily_transactions(symbols: List[str]) -> pd.DataFrame: select date_trunc('day', block_timestamp) as timeframe, {extra_sql} - from ethereum.udm_events + from ethereum.core.udm_events where block_timestamp >= '2020-06-01' -- and amount0_usd > '0' @@ -211,7 +234,7 @@ def get_total_value_locked( symbol, amount_usd/1000000 as amount_usd FROM - ethereum.erc20_balances + ethereum.core.erc20_balances WHERE {extra_sql} symbol = '{symbol}' AND diff --git a/openbb_terminal/cryptocurrency/onchain/shroom_view.py b/openbb_terminal/cryptocurrency/onchain/shroom_view.py index 5c51c62f3718..688b4111b83f 100644 --- a/openbb_terminal/cryptocurrency/onchain/shroom_view.py +++ b/openbb_terminal/cryptocurrency/onchain/shroom_view.py @@ -16,6 +16,7 @@ get_daily_transactions, get_dapp_stats, get_total_value_locked, + get_query_data ) from openbb_terminal.decorators import check_api_key, log_start_end from openbb_terminal.helper_funcs import ( @@ -28,6 +29,44 @@ logger = logging.getLogger(__name__) +@log_start_end(log=logger) +@check_api_key(["API_SHROOM_KEY"]) +def display_query( + query: str, + raw: bool = False, + limit: int = 10, + export: str = "", +): + """Display query results from shroom + [Source: https://sdk.flipsidecrypto.xyz/shroomdk] + + Parameters + ---------- + query : str + Query string + raw : bool + Show raw data + limit : int + Limit of rows + export : str + Export dataframe data to csv,json,xlsx file + """ + df = get_query_data(query) + if df.empty: + console.print("[red]No data found.[/red]") + elif not df.empty: + if raw: + console.print(df) + else: + print_rich_table(df.head(limit)) + + export_data( + export, + os.path.dirname(os.path.abspath(__file__)), + "query", + df, + ) + @log_start_end(log=logger) @check_api_key(["API_SHROOM_KEY"]) diff --git a/openbb_terminal/miscellaneous/data_sources_default.json b/openbb_terminal/miscellaneous/data_sources_default.json index cc7d55fe5dd7..63f4d5f07ad5 100644 --- a/openbb_terminal/miscellaneous/data_sources_default.json +++ b/openbb_terminal/miscellaneous/data_sources_default.json @@ -13,7 +13,7 @@ "closed": ["Bursa"], "all": ["Bursa"], "exchange": ["Bursa"], - "holidays":["PandasMarketCalendars"] + "holidays": ["PandasMarketCalendars"] }, "options": { "unu": ["FDScanner"], @@ -28,7 +28,7 @@ "pcr": ["AlphaQuery"], "info": ["Barchart"], "chains": ["YahooFinance", "Tradier", "Nasdaq", "Intrinio"], - "eodchain":["Intrinio"], + "eodchain": ["Intrinio"], "oi": ["YahooFinance", "Tradier", "Nasdaq"], "vol": ["YahooFinance", "Tradier", "Nasdaq"], "voi": ["YahooFinance", "Tradier", "Nasdaq"], @@ -231,7 +231,12 @@ "EODHD", "YahooFinance" ], - "overview": ["Finviz", "FinancialModelingPrep", "AlphaVantage", "YahooFinance"], + "overview": [ + "Finviz", + "FinancialModelingPrep", + "AlphaVantage", + "YahooFinance" + ], "mgmt": ["BusinessInsider"], "analysis": ["Elect"], "score": ["FinancialModelingPrep"], @@ -345,9 +350,7 @@ "th": ["Ethplorer"], "prices": ["Ethplorer"], "tx": ["Ethplorer"], - "dt": ["Shroom"], - "ds": ["Shroom"], - "tvl": ["Shroom"] + "query": ["Shroom"] }, "defi": { "newsletter": ["Substack"], @@ -481,8 +484,8 @@ "info": ["MorningStar"], "plot": ["MorningStar"], "sector": ["MorningStar"], - "carbon" : ["MorningStar"], - "exclusion" : ["MorningStar"], + "carbon": ["MorningStar"], + "exclusion": ["MorningStar"], "holdings": ["MorningStar"], "alswe": ["Avanza"], "infoswe": ["Avanza"] diff --git a/openbb_terminal/miscellaneous/i18n/en.yml b/openbb_terminal/miscellaneous/i18n/en.yml index 412ec9541282..3de5302f2ce4 100644 --- a/openbb_terminal/miscellaneous/i18n/en.yml +++ b/openbb_terminal/miscellaneous/i18n/en.yml @@ -533,9 +533,7 @@ en: crypto/onchain/ueat: unique ethereum addresses which made a transaction crypto/onchain/ttcp: top traded crypto pairs on given decentralized exchange crypto/onchain/baas: bid, ask prices, average spread for given crypto pair - crypto/onchain/dt: daily transactions of eth tokens - crypto/onchain/ds: stats of eth platform (daily users; fees) - crypto/onchain/tvl: total value locked of ERC20 tokens + crypto/onchain/query: flipsidecrypto query crypto/onchain/_address: Ethereum address crypto/onchain/_type: Address type crypto/onchain/_ethereum_: Ethereum From 67262e21f20494a4afd1f75ae6e01f075d163357 Mon Sep 17 00:00:00 2001 From: jose-donato Date: Wed, 29 Mar 2023 11:57:43 +0100 Subject: [PATCH 02/14] fix: ruff --- openbb_terminal/cryptocurrency/onchain/onchain_controller.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openbb_terminal/cryptocurrency/onchain/onchain_controller.py b/openbb_terminal/cryptocurrency/onchain/onchain_controller.py index 1e67e673e1f4..4e770df5f5e5 100644 --- a/openbb_terminal/cryptocurrency/onchain/onchain_controller.py +++ b/openbb_terminal/cryptocurrency/onchain/onchain_controller.py @@ -22,7 +22,6 @@ ethgasstation_view, ethplorer_model, ethplorer_view, - shroom_model, shroom_view, whale_alert_model, whale_alert_view, @@ -157,7 +156,7 @@ def call_query(self, other_args: List[str]): help="Query to make", ) - if other_args and not other_args[0][0] == "-": + if other_args and other_args[0][0] != "-": other_args.insert(0, "-q") ns_parser = self.parse_known_args_and_warn( From 268f584a82e86dee5ace85d40dab391dab2b7ea4 Mon Sep 17 00:00:00 2001 From: jose-donato Date: Wed, 29 Mar 2023 12:52:27 +0100 Subject: [PATCH 03/14] fix: ruff --- openbb_terminal/cryptocurrency/onchain/shroom_view.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbb_terminal/cryptocurrency/onchain/shroom_view.py b/openbb_terminal/cryptocurrency/onchain/shroom_view.py index f637366338e3..ca0171d24932 100644 --- a/openbb_terminal/cryptocurrency/onchain/shroom_view.py +++ b/openbb_terminal/cryptocurrency/onchain/shroom_view.py @@ -9,8 +9,8 @@ from openbb_terminal.cryptocurrency.onchain.shroom_model import ( get_daily_transactions, get_dapp_stats, - get_total_value_locked, get_query_data, + get_total_value_locked, ) from openbb_terminal.decorators import check_api_key, log_start_end from openbb_terminal.helper_funcs import export_data, print_rich_table From d743afe68cba695788038fd258b1d9dd5a586db7 Mon Sep 17 00:00:00 2001 From: jose-donato Date: Tue, 11 Apr 2023 13:56:56 +0100 Subject: [PATCH 04/14] fix: james suggestions --- openbb_terminal/cryptocurrency/onchain/shroom_view.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/openbb_terminal/cryptocurrency/onchain/shroom_view.py b/openbb_terminal/cryptocurrency/onchain/shroom_view.py index ca0171d24932..07dc7acd0d9b 100644 --- a/openbb_terminal/cryptocurrency/onchain/shroom_view.py +++ b/openbb_terminal/cryptocurrency/onchain/shroom_view.py @@ -23,7 +23,7 @@ @check_api_key(["API_SHROOM_KEY"]) def display_query( query: str, - raw: bool = False, + sheet_name: Optional[str] = None, limit: int = 10, export: str = "", ): @@ -45,16 +45,14 @@ def display_query( if df.empty: console.print("[red]No data found.[/red]") elif not df.empty: - if raw: - console.print(df) - else: - print_rich_table(df.head(limit)) + print_rich_table(df, limit=limit) export_data( export, os.path.dirname(os.path.abspath(__file__)), "query", df, + sheet_name, ) From de462b9110134d162156c7a2ff966656ab4a5ee9 Mon Sep 17 00:00:00 2001 From: jose-donato Date: Wed, 12 Apr 2023 12:13:46 +0100 Subject: [PATCH 05/14] fix: added to csv --- openbb_terminal/core/sdk/trail_map.csv | 1 + 1 file changed, 1 insertion(+) diff --git a/openbb_terminal/core/sdk/trail_map.csv b/openbb_terminal/core/sdk/trail_map.csv index d3544df883b1..3be7c07cacfd 100644 --- a/openbb_terminal/core/sdk/trail_map.csv +++ b/openbb_terminal/core/sdk/trail_map.csv @@ -128,6 +128,7 @@ crypto.onchain.tv,crypto_onchain_bitquery_model.get_token_volume_on_dexes,crypto crypto.onchain.tx,crypto_onchain_ethplorer_model.get_tx_info,crypto_onchain_ethplorer_view.display_tx_info crypto.onchain.ueat,crypto_onchain_bitquery_model.get_ethereum_unique_senders,crypto_onchain_bitquery_view.display_ethereum_unique_senders crypto.onchain.whales,crypto_onchain_whale_alert_model.get_whales_transactions,crypto_onchain_whale_alert_view.display_whales_transactions +crypto.onchain.query,crypto_onchain_shroom_model.get_query_data,crypto_onchain_shroom_view.display_query crypto.ov.altindex,crypto_ov_blockchaincenter_model.get_altcoin_index,crypto_ov_blockchaincenter_view.display_altcoin_index crypto.ov.btcrb,crypto_ov_glassnode_model.get_btc_rainbow,crypto_ov_glassnode_view.display_btc_rainbow crypto.ov.categories,crypto_ov_pycoingecko_model.get_top_crypto_categories,crypto_ov_pycoingecko_view.display_categories From 57564fcefc0f19ed9d97bbcf2cd51a9401f5f635 Mon Sep 17 00:00:00 2001 From: jose-donato Date: Wed, 12 Apr 2023 13:24:35 +0100 Subject: [PATCH 06/14] fix: generate sdk cmds --- .../sdk/controllers/crypto_sdk_controller.py | 2 + .../sdk/controllers/stocks_sdk_controller.py | 2 +- .../core/sdk/models/crypto_sdk_model.py | 4 + .../core/sdk/models/forecast_sdk_model.py | 1 + .../core/sdk/models/portfolio_sdk_model.py | 1 + .../core/sdk/models/stocks_sdk_model.py | 2 +- openbb_terminal/core/sdk/sdk_helpers.py | 132 ++++++++++++++++++ openbb_terminal/core/sdk/sdk_init.py | 104 ++++++++++++++ openbb_terminal/core/sdk/trail_map.csv | 12 +- openbb_terminal/core/sdk/trailmap.py | 67 +++++++++ .../dashboards/voila/forecast.ipynb | 1 + .../reports/templates/crypto.ipynb | 1 + .../reports/templates/economy.ipynb | 16 ++- .../reports/templates/equity.ipynb | 1 + openbb_terminal/reports/templates/etf.ipynb | 6 +- .../reports/templates/forecast.ipynb | 1 + openbb_terminal/reports/templates/forex.ipynb | 1 + .../reports/templates/portfolio.ipynb | 1 + openbb_terminal/sdk.py | 4 +- 19 files changed, 344 insertions(+), 15 deletions(-) diff --git a/openbb_terminal/core/sdk/controllers/crypto_sdk_controller.py b/openbb_terminal/core/sdk/controllers/crypto_sdk_controller.py index 0566bfe9d1b5..850c18af5aee 100644 --- a/openbb_terminal/core/sdk/controllers/crypto_sdk_controller.py +++ b/openbb_terminal/core/sdk/controllers/crypto_sdk_controller.py @@ -240,6 +240,8 @@ def onchain(self): `lt_chart`: Prints table showing Trades on Decentralized Exchanges aggregated by DEX or Month\n `prices`: Get token historical prices with volume and market cap, and average price. [Source: Ethplorer]\n `prices_chart`: Display token historical prices with volume and market cap, and average price.\n + `query`: Get query data\n + `query_chart`: Display query results from shroom\n `query_graph`: Helper methods for querying graphql api. [Source: https://bitquery.io/]\n `th`: Get info about token historical transactions. [Source: Ethplorer]\n `th_chart`: Display info about token history. [Source: Ethplorer]\n diff --git a/openbb_terminal/core/sdk/controllers/stocks_sdk_controller.py b/openbb_terminal/core/sdk/controllers/stocks_sdk_controller.py index bd3bad6a5cf0..ae49c3f753b8 100644 --- a/openbb_terminal/core/sdk/controllers/stocks_sdk_controller.py +++ b/openbb_terminal/core/sdk/controllers/stocks_sdk_controller.py @@ -24,7 +24,7 @@ class StocksController(model.StocksRoot): Attributes: `candle`: Show candle plot of loaded ticker.\n `load`: Load a symbol to perform analysis using the string above as a template.\n - `news`: Get news for a given term and source. [Source: Feedparser]\n + `news`: Get news for a given term and source. [Source: Ultima Insights News Monitor]\n `process_candle`: Process DataFrame into candle style plot.\n `quote`: Gets ticker quote from FMP\n `search`: Search selected query for tickers.\n diff --git a/openbb_terminal/core/sdk/models/crypto_sdk_model.py b/openbb_terminal/core/sdk/models/crypto_sdk_model.py index b25092e17f2b..5dcd4460b22e 100644 --- a/openbb_terminal/core/sdk/models/crypto_sdk_model.py +++ b/openbb_terminal/core/sdk/models/crypto_sdk_model.py @@ -429,6 +429,8 @@ class CryptoOnChain(Category): `lt_chart`: Prints table showing Trades on Decentralized Exchanges aggregated by DEX or Month\n `prices`: Get token historical prices with volume and market cap, and average price. [Source: Ethplorer]\n `prices_chart`: Display token historical prices with volume and market cap, and average price.\n + `query`: Get query data\n + `query_chart`: Display query results from shroom\n `query_graph`: Helper methods for querying graphql api. [Source: https://bitquery.io/]\n `th`: Get info about token historical transactions. [Source: Ethplorer]\n `th_chart`: Display info about token history. [Source: Ethplorer]\n @@ -497,6 +499,8 @@ def __init__(self): self.prices_chart = ( lib.crypto_onchain_ethplorer_view.display_token_historical_prices ) + self.query = lib.crypto_onchain_shroom_model.get_query_data + self.query_chart = lib.crypto_onchain_shroom_view.display_query self.query_graph = lib.crypto_onchain_bitquery_model.query_graph self.th = lib.crypto_onchain_ethplorer_model.get_token_history self.th_chart = lib.crypto_onchain_ethplorer_view.display_token_history diff --git a/openbb_terminal/core/sdk/models/forecast_sdk_model.py b/openbb_terminal/core/sdk/models/forecast_sdk_model.py index dacbfa927a35..be6fbc3e4f0d 100644 --- a/openbb_terminal/core/sdk/models/forecast_sdk_model.py +++ b/openbb_terminal/core/sdk/models/forecast_sdk_model.py @@ -78,6 +78,7 @@ def __init__(self): if not lib.FORECASTING_TOOLKIT_ENABLED: # pylint: disable=C0415 + from openbb_terminal.rich_config import console console.print(lib.FORECASTING_TOOLKIT_WARNING) diff --git a/openbb_terminal/core/sdk/models/portfolio_sdk_model.py b/openbb_terminal/core/sdk/models/portfolio_sdk_model.py index 14457d671fdf..bc4558a9aea6 100644 --- a/openbb_terminal/core/sdk/models/portfolio_sdk_model.py +++ b/openbb_terminal/core/sdk/models/portfolio_sdk_model.py @@ -178,6 +178,7 @@ def __init__(self): if not lib.OPTIMIZATION_TOOLKIT_ENABLED: # pylint: disable=C0415 + from openbb_terminal.rich_config import console console.print(lib.OPTIMIZATION_TOOLKIT_WARNING) diff --git a/openbb_terminal/core/sdk/models/stocks_sdk_model.py b/openbb_terminal/core/sdk/models/stocks_sdk_model.py index 511936bcc41b..d3bd9b14701a 100644 --- a/openbb_terminal/core/sdk/models/stocks_sdk_model.py +++ b/openbb_terminal/core/sdk/models/stocks_sdk_model.py @@ -11,7 +11,7 @@ class StocksRoot(Category): Attributes: `candle`: Show candle plot of loaded ticker.\n `load`: Load a symbol to perform analysis using the string above as a template.\n - `news`: Get news for a given term and source. [Source: Feedparser]\n + `news`: Get news for a given term and source. [Source: Ultima Insights News Monitor]\n `process_candle`: Process DataFrame into candle style plot.\n `quote`: Gets ticker quote from FMP\n `search`: Search selected query for tickers.\n diff --git a/openbb_terminal/core/sdk/sdk_helpers.py b/openbb_terminal/core/sdk/sdk_helpers.py index d286d4421355..6cde6e9e642d 100644 --- a/openbb_terminal/core/sdk/sdk_helpers.py +++ b/openbb_terminal/core/sdk/sdk_helpers.py @@ -1,43 +1,58 @@ """OpenBB Terminal SDK Helpers.""" + import json + from inspect import signature + from logging import Logger, getLogger + from typing import Any, Callable, Dict, Optional + from openbb_terminal.core.config.paths import SETTINGS_ENV_FILE + from openbb_terminal.core.sdk.sdk_init import ( FORECASTING_TOOLKIT_ENABLED, FORECASTING_TOOLKIT_WARNING, OPTIMIZATION_TOOLKIT_ENABLED, OPTIMIZATION_TOOLKIT_WARNING, ) + from openbb_terminal.core.session.current_system import ( get_current_system, set_system_variable, ) + from openbb_terminal.rich_config import console + SETTINGS_ENV_FILE.parent.mkdir(parents=True, exist_ok=True) + if ( not FORECASTING_TOOLKIT_ENABLED and not get_current_system().DISABLE_FORECASTING_WARNING ): set_system_variable("DISABLE_FORECASTING_WARNING", True) + console.print(FORECASTING_TOOLKIT_WARNING) + if ( not OPTIMIZATION_TOOLKIT_ENABLED and not get_current_system().DISABLE_OPTIMIZATION_WARNING ): set_system_variable("DISABLE_OPTIMIZATION_WARNING", True) + console.print(OPTIMIZATION_TOOLKIT_WARNING) def clean_attr_desc(attr: Optional[Any] = None) -> Optional[str]: """Clean the attribute description.""" + if attr.__doc__ is None: return None + return ( attr.__doc__.splitlines()[1].lstrip() if not attr.__doc__.splitlines()[0] @@ -49,6 +64,7 @@ def clean_attr_desc(attr: Optional[Any] = None) -> Optional[str]: def class_repr(cls_dict: Dict[str, Any]) -> list: """Return the representation of the class.""" + return [ f" {k}: {clean_attr_desc(v)}\n" for k, v in cls_dict.items() @@ -59,7 +75,9 @@ def class_repr(cls_dict: Dict[str, Any]) -> list: class Operation: def __init__(self, name: str, trail: str, func: Callable) -> None: self._trail = trail + self._method = func + self._name = name for attr in [ @@ -71,50 +89,65 @@ def __init__(self, name: str, trail: str, func: Callable) -> None: "__module__", ]: setattr(self.__class__, attr, getattr(func, attr)) + setattr(self, attr, getattr(func, attr)) self.__signature__ = signature(func) + self.__class__.__signature__ = signature(func) def __call__(self, *args: Any, **kwargs: Any) -> Any: method = self._method # We make a copy of the kwargs to avoid modifying the original + log_kwargs = kwargs.copy() + log_kwargs["chart"] = "chart" in self._name operation_logger = OperationLogger( trail=self._trail, method_chosen=method, args=args, kwargs=log_kwargs ) + operation_logger.log_before_call() + method_result = method(*args, **kwargs) + operation_logger.log_after_call(method_result=method_result) return method_result def about(self): # pylint: disable=C0415 + import webbrowser trail = "/".join(self._trail.split(".")).replace("_chart", "") + url = f"https://docs.openbb.co/sdk/reference/{trail}" + webbrowser.open(url) class Category: + """The base class that all categories must inherit from.""" _location_path: str = "" def __init__(self, *args, **kwargs): """Initialize the class""" + super().__init__(*args, **kwargs) def __repr__(self): """Return the representation of the class.""" + repr_docs = [] + if submodules := class_repr(self.__class__.__dict__): repr_docs += ["\nSubmodules:\n"] + submodules + if attributes := class_repr(self.__dict__): repr_docs += ["\nAttributes:\n"] + attributes @@ -122,9 +155,13 @@ def __repr__(self): def __getattribute__(self, name: str): """We override the __getattribute__ method and wrap all callable + attributes with a wrapper that logs the call and the result. + """ + attr = super().__getattribute__(name) + if isinstance(attr, Operation) or name.startswith("__"): return attr @@ -132,18 +169,24 @@ def __getattribute__(self, name: str): if callable(attr) and not isinstance(attr, Operation): # We set the attribute to the wrapped function so that we don't + # have to wrap it when called again. + setattr(self, name, Operation(name=name, trail=trail, func=attr)) + return getattr(self, name) return attr def about(self): # pylint: disable=C0415 + import webbrowser trail = "/".join(self._location_path.split(".")) + url = f"https://docs.openbb.co/sdk/reference/{trail}" + webbrowser.open(url) @@ -159,9 +202,13 @@ def __init__( logger: Optional[Logger] = None, ) -> None: self.__trail = trail + self.__method_chosen = method_chosen + self.__logger = logger or getLogger(self.__method_chosen.__module__) + self.__args = args + self.__kwargs = kwargs def log_before_call( @@ -169,7 +216,9 @@ def log_before_call( ): if self.__check_logging_conditions(): logger = self.__logger + self.__log_start(logger=logger, method_chosen=self.__method_chosen) + self.__log_method_info( logger=logger, trail=self.__trail, @@ -194,15 +243,19 @@ def __log_method_info( kwargs: Any, ): merged_args = self.__merge_function_args(method_chosen, args, kwargs) + merged_args = self.__remove_key_and_log_state( method_chosen.__module__, merged_args ) logging_info: Dict[str, Any] = {} + logging_info["INPUT"] = { key: str(value)[:100] for key, value in merged_args.items() } + logging_info["VIRTUAL_PATH"] = trail + logging_info["CHART"] = kwargs.get("chart", False) logger.info( @@ -213,64 +266,106 @@ def __log_method_info( @staticmethod def __merge_function_args(func: Callable, args: tuple, kwargs: dict) -> dict: """ + Merge user input args and kwargs with signature defaults into a dictionary. + + Parameters + ---------- + + func : Callable + Function to get the args from + args : tuple + Positional args + kwargs : dict + Keyword args + + Returns + ---------- + dict + Merged user args and signature defaults + """ + import inspect # pylint: disable=C0415 sig = inspect.signature(func) + sig_args = { param.name: param.default for param in sig.parameters.values() if param.default is not inspect.Parameter.empty } + # merge args with sig_args + sig_args.update(dict(zip(sig.parameters, args))) + # add kwargs elements to sig_args + sig_args.update(kwargs) + return sig_args @staticmethod def __remove_key_and_log_state(func_module: str, function_args: dict) -> dict: """ + Remove API key from the function args and log state of keys. + + Parameters + ---------- + func_module : str + Module of the function + function_args : dict + Function args + + Returns + ---------- + dict + Function args with API key removed + """ if func_module == "openbb_terminal.keys_model": # pylint: disable=C0415 + from openbb_terminal.core.log.generation.settings_logger import ( log_credentials, ) # remove key if defined + function_args.pop("key", None) + log_credentials() + return function_args def log_after_call( @@ -279,15 +374,18 @@ def log_after_call( ): if self.__check_logging_conditions(): logger = self.__logger + self.__log_exception_if_any( logger=logger, method_result=method_result, method_chosen=self.__method_chosen, ) + self.__log_end( logger=logger, method_chosen=self.__method_chosen, ) + OperationLogger.last_method = { f"{self.__method_chosen.__module__}.{self.__method_chosen.__name__}": { "args": str(self.__args)[:100], @@ -326,41 +424,75 @@ def __check_last_method(self) -> bool: "kwargs": str(self.__kwargs)[:100], } } + return OperationLogger.last_method == current_method def get_sdk_imports_text() -> str: """Return the text for the SDK imports.""" + sdk_imports = """\"\"\"OpenBB Terminal SDK.\"\"\" + # ######### THIS FILE IS AUTO GENERATED - ANY CHANGES WILL BE VOID ######### # + # flake8: noqa + # pylint: disable=unused-import,wrong-import-order + # pylint: disable=C0302,W0611,R0902,R0903,C0412,C0301,not-callable + import logging + + import openbb_terminal.config_terminal as cfg + from openbb_terminal import helper_funcs as helper # noqa: F401 + from openbb_terminal.core.plots.plotly_helper import theme # noqa: F401 + + from openbb_terminal.cryptocurrency.due_diligence.pycoingecko_model import Coin + from openbb_terminal.dashboards.dashboards_controller import DashboardsController + from openbb_terminal.helper_classes import TerminalStyle # noqa: F401 + from openbb_terminal.reports import widget_helpers as widgets # noqa: F401 + from openbb_terminal.reports.reports_controller import ReportController + + import openbb_terminal.core.sdk.sdk_init as lib + from openbb_terminal.core.sdk import ( + controllers as ctrl, + models as model, + ) + from openbb_terminal.core.session.current_system import get_current_system + from openbb_terminal.core.session.current_user import is_local + from openbb_terminal.terminal_helper import is_auth_enabled + + cfg.setup_config_terminal(is_sdk=True) + + logger = logging.getLogger(__name__) + cfg.theme.applyMPLstyle() + \r\r\r + """ + return "\r".join(sdk_imports.splitlines()) diff --git a/openbb_terminal/core/sdk/sdk_init.py b/openbb_terminal/core/sdk/sdk_init.py index c6682a270e06..1e9d0a7f224e 100644 --- a/openbb_terminal/core/sdk/sdk_init.py +++ b/openbb_terminal/core/sdk/sdk_init.py @@ -1,47 +1,78 @@ # flake8: noqa pylint: disable=R0402,C0412,unused-import + # noqa: F401 # Session + from openbb_terminal.core.session import sdk_session + # Alternative + import openbb_terminal.alternative.hackernews_model as alt_hackernews_model + import openbb_terminal.alternative.hackernews_view as alt_hackernews_view + import openbb_terminal.alternative.oss.github_model as alt_oss_github_model + import openbb_terminal.alternative.oss.github_view as alt_oss_github_view + import openbb_terminal.alternative.oss.runa_model as alt_oss_runa_model + import openbb_terminal.alternative.oss.runa_view as alt_oss_runa_view + import openbb_terminal.alternative.realestate.landRegistry_model as alt_realestate_landRegistry_model + # Crypto Helpers + import openbb_terminal.cryptocurrency.cryptocurrency_helpers as crypto_helpers + # ETF + import openbb_terminal.etf.discovery.wsj_model as etf_disc_wsj_model + import openbb_terminal.etf.discovery.wsj_view as etf_disc_wsj_view + # Forex Helpers + import openbb_terminal.forex.forex_helper as forex_helper + import openbb_terminal.forex.oanda.oanda_model as forex_oanda_model + import openbb_terminal.forex.oanda.oanda_view as forex_oanda_view + # Keys + import openbb_terminal.keys_model as keys_model + import openbb_terminal.stocks.options.hedge.hedge_model as stocks_options_hedge_model + import openbb_terminal.stocks.options.hedge.hedge_view as stocks_options_hedge_view + import openbb_terminal.stocks.quantitative_analysis.beta_model as stocks_qa_beta_model + import openbb_terminal.stocks.quantitative_analysis.beta_view as stocks_qa_beta_view + # Stocks - Quantitative Analysis + import openbb_terminal.stocks.quantitative_analysis.factors_model as stocks_qa_factors_model + import openbb_terminal.stocks.quantitative_analysis.factors_view as stocks_qa_factors_view + from openbb_terminal.alternative.covid import ( covid_model as alt_covid_model, covid_view as alt_covid_view, ) + # Common + from openbb_terminal.common import ( common_model, feedparser_model as common_feedparser_model, @@ -52,7 +83,9 @@ newsapi_view as common_newsapi_view, ) + # Common Behavioural Analysis + from openbb_terminal.common.behavioural_analysis import ( finbrain_model as stocks_ba_finbrain_model, finbrain_view as stocks_ba_finbrain_view, @@ -66,7 +99,9 @@ twitter_view as stocks_ba_twitter_view, ) + # Common Quantitative Analysis + from openbb_terminal.common.quantitative_analysis import ( qa_model as common_qa_model, qa_view as common_qa_view, @@ -74,7 +109,9 @@ rolling_view as common_qa_rolling_view, ) + # Common Technical Analysis + from openbb_terminal.common.technical_analysis import ( custom_indicators_model as common_ta_custom_indicators_model, custom_indicators_view as common_ta_custom_indicators_view, @@ -89,12 +126,15 @@ volume_model as common_ta_volume_model, volume_view as common_ta_volume_view, ) + from openbb_terminal.cryptocurrency import ( crypto_models, pyth_model as crypto_pyth_model, ) + # Cryptocurrency Defi + from openbb_terminal.cryptocurrency.defi import ( coindix_model as crypto_defi_coindix_model, coindix_view as crypto_defi_coindix_view, @@ -114,7 +154,9 @@ terramoney_fcd_view as crypto_defi_terramoney_fcd_view, ) + # Cryptocurrency Discovery + from openbb_terminal.cryptocurrency.discovery import ( coinmarketcap_model as crypto_disc_coinmarketcap_model, coinmarketcap_view as crypto_disc_coinmarketcap_view, @@ -127,7 +169,9 @@ sdk_helpers as crypto_disc_sdk_helpers, ) + # Cryptocurrency Due Diligence + from openbb_terminal.cryptocurrency.due_diligence import ( binance_model as crypto_dd_binance_model, binance_view as crypto_dd_binance_view, @@ -152,7 +196,9 @@ sdk_helper as crypto_dd_sdk_helper, ) + # Cryptocurrency NFT + from openbb_terminal.cryptocurrency.nft import ( nftpricefloor_model as crypto_nft_pricefloor_model, nftpricefloor_view as crypto_nft_pricefloor_view, @@ -160,7 +206,9 @@ opensea_view as crypto_nft_opensea_view, ) + # Cryptocurrency Onchain + from openbb_terminal.cryptocurrency.onchain import ( bitquery_model as crypto_onchain_bitquery_model, bitquery_view as crypto_onchain_bitquery_view, @@ -172,9 +220,13 @@ ethplorer_view as crypto_onchain_ethplorer_view, whale_alert_model as crypto_onchain_whale_alert_model, whale_alert_view as crypto_onchain_whale_alert_view, + shroom_model as crypto_onchain_shroom_model, + shroom_view as crypto_onchain_shroom_view, ) + # Cryptocurrency Overview + from openbb_terminal.cryptocurrency.overview import ( blockchaincenter_model as crypto_ov_blockchaincenter_model, blockchaincenter_view as crypto_ov_blockchaincenter_view, @@ -197,13 +249,17 @@ withdrawalfees_view as crypto_ov_withdrawalfees_view, ) + # Cryptocurrency Tools + from openbb_terminal.cryptocurrency.tools import ( tools_model as crypto_tools_model, tools_view as crypto_tools_view, ) + # Econometrics + from openbb_terminal.econometrics import ( econometrics_model, econometrics_view, @@ -211,7 +267,9 @@ regression_view as econometrics_regression_view, ) + # Fixedincome + from openbb_terminal.fixedincome import ( fred_model as fixedincome_fred_model, ecb_model as fixedincome_ecb_model, @@ -221,6 +279,7 @@ # Economy + from openbb_terminal.economy import ( alphavantage_model as economy_alphavantage_model, alphavantage_view as economy_alphavantage_view, @@ -240,7 +299,9 @@ oecd_view as economy_oecd_view, ) + # ETF's + from openbb_terminal.etf import ( financedatabase_model as etf_financedatabase_model, financedatabase_view as etf_financedatabase_view, @@ -250,7 +311,9 @@ fmp_view as etf_fmp_view, ) + # Forex + from openbb_terminal.forex import ( av_model as forex_av_model, av_view as forex_av_view, @@ -259,20 +322,26 @@ sdk_helpers as forex_sdk_helpers, ) + # Funds + from openbb_terminal.mutual_funds import ( mstarpy_model as funds_mstarpy_model, mstarpy_view as funds_mstarpy_view, ) + # Futures + from openbb_terminal.futures import ( yfinance_model as futures_yfinance_model, yfinance_view as futures_yfinance_view, sdk_helper as futures_sdk_model, ) + # Stocks Helpers + from openbb_terminal.stocks import ( cboe_model as stocks_cboe_model, cboe_view as stocks_cboe_view, @@ -281,13 +350,17 @@ stocks_view, ) + # Stocks -Behavioral Analysis + from openbb_terminal.stocks.behavioural_analysis import ( finnhub_model as stocks_ba_finnhub_model, finnhub_view as stocks_ba_finnhub_view, ) + # Stocks - Comparison Analysis + from openbb_terminal.stocks.comparison_analysis import ( finbrain_model as stocks_ca_finbrain_model, finbrain_view as stocks_ca_finbrain_view, @@ -301,7 +374,9 @@ yahoo_finance_view as stocks_ca_yahoo_finance_view, ) + # Stocks - Dark Pool Shorts + from openbb_terminal.stocks.dark_pool_shorts import ( finra_model as stocks_dps_finra_model, finra_view as stocks_dps_finra_view, @@ -318,7 +393,9 @@ yahoofinance_model as stocks_dps_yahoofinance_model, ) + # Stocks - Fundamental Discovery + from openbb_terminal.stocks.discovery import ( ark_model as stocks_disc_ark_model, finnhub_model as stocks_disc_finnhub_model, @@ -329,7 +406,9 @@ yahoofinance_model as stocks_disc_yahoofinance_model, ) + # Stocks - Fundamental Analysis + from openbb_terminal.stocks.fundamental_analysis import ( av_model as stocks_fa_av_model, av_view as stocks_fa_av_view, @@ -355,13 +434,17 @@ yahoo_finance_view as stocks_fa_yahoo_finance_view, ) + # Government + from openbb_terminal.stocks.government import ( quiverquant_model as stocks_gov_quiverquant_model, quiverquant_view as stocks_gov_quiverquant_view, ) + # Stocks - Insider Trading + from openbb_terminal.stocks.insider import ( businessinsider_model as stocks_insider_businessinsider_model, businessinsider_view as stocks_insider_businessinsider_view, @@ -372,7 +455,9 @@ sdk_helper as stocks_insider_sdk_helper, ) + # Stocks - Options + from openbb_terminal.stocks.options import ( alphaquery_model as stocks_options_alphaquery_model, alphaquery_view as stocks_options_alphaquery_view, @@ -392,18 +477,23 @@ yfinance_model as stocks_options_yfinance_model, yfinance_view as stocks_options_yfinance_view, ) + from openbb_terminal.stocks.options.screen import ( syncretism_model as stocks_options_screen_syncretism_model, syncretism_view as stocks_options_screen_syncretism_view, ) + # Stocks - Screener + from openbb_terminal.stocks.screener import ( finviz_model as stocks_screener_finviz_model, finviz_view as stocks_screener_finviz_view, ) + # Stocks - Technical Analysis + from openbb_terminal.stocks.technical_analysis import ( finbrain_model as stocks_ta_finbrain_model, finbrain_view as stocks_ta_finbrain_view, @@ -415,22 +505,29 @@ tradingview_view as stocks_ta_tradingview_view, ) + # Stocks - Trading Hours + from openbb_terminal.stocks.tradinghours import ( bursa_model as stocks_th_bursa_model, bursa_view as stocks_th_bursa_view, ) + # Forecast Extras + try: import darts # pyright: reportMissingImports=false # If you just import darts this will pass during pip install, this creates + # Failures later on, also importing utils ensures that darts is installed correctly + from darts import utils FORECASTING_TOOLKIT_ENABLED = True + from openbb_terminal.forecast import ( anom_model as forecast_anom_model, anom_view as forecast_anom_view, @@ -474,15 +571,19 @@ trans_view as forecast_trans_view, whisper_model as forecast_whisper_model, ) + except ImportError: FORECASTING_TOOLKIT_ENABLED = False # Portfolio + from openbb_terminal.portfolio import portfolio_model, portfolio_view + try: # pylint: disable=W0611 # noqa: F401 # pyright: reportMissingImports=false + from openbb_terminal.portfolio.portfolio_optimization import ( excel_model as portfolio_optimization_excel_model, optimizer_model as portfolio_optimization_optimizer_model, @@ -492,9 +593,11 @@ ) OPTIMIZATION_TOOLKIT_ENABLED = True + except ModuleNotFoundError: OPTIMIZATION_TOOLKIT_ENABLED = False + FORECASTING_TOOLKIT_WARNING = ( "[yellow]" "Forecasting Toolkit is disabled. " @@ -503,6 +606,7 @@ "\n" "[/yellow]" ) + OPTIMIZATION_TOOLKIT_WARNING = ( "[yellow]" "Portfolio Optimization Toolkit is disabled. " diff --git a/openbb_terminal/core/sdk/trail_map.csv b/openbb_terminal/core/sdk/trail_map.csv index 3be7c07cacfd..786bce4d93bc 100644 --- a/openbb_terminal/core/sdk/trail_map.csv +++ b/openbb_terminal/core/sdk/trail_map.csv @@ -119,6 +119,7 @@ crypto.onchain.hr,crypto_dd_glassnode_model.get_hashrate,crypto_dd_glassnode_vie crypto.onchain.info,crypto_onchain_ethplorer_model.get_token_info,crypto_onchain_ethplorer_view.display_token_info crypto.onchain.lt,crypto_onchain_bitquery_model.get_dex_trades_by_exchange,crypto_onchain_bitquery_view.display_dex_trades crypto.onchain.prices,crypto_onchain_ethplorer_model.get_token_historical_price,crypto_onchain_ethplorer_view.display_token_historical_prices +crypto.onchain.query,crypto_onchain_shroom_model.get_query_data,crypto_onchain_shroom_view.display_query crypto.onchain.query_graph,crypto_onchain_bitquery_model.query_graph, crypto.onchain.th,crypto_onchain_ethplorer_model.get_token_history,crypto_onchain_ethplorer_view.display_token_history crypto.onchain.token_decimals,crypto_onchain_ethplorer_model.get_token_decimals, @@ -128,7 +129,6 @@ crypto.onchain.tv,crypto_onchain_bitquery_model.get_token_volume_on_dexes,crypto crypto.onchain.tx,crypto_onchain_ethplorer_model.get_tx_info,crypto_onchain_ethplorer_view.display_tx_info crypto.onchain.ueat,crypto_onchain_bitquery_model.get_ethereum_unique_senders,crypto_onchain_bitquery_view.display_ethereum_unique_senders crypto.onchain.whales,crypto_onchain_whale_alert_model.get_whales_transactions,crypto_onchain_whale_alert_view.display_whales_transactions -crypto.onchain.query,crypto_onchain_shroom_model.get_query_data,crypto_onchain_shroom_view.display_query crypto.ov.altindex,crypto_ov_blockchaincenter_model.get_altcoin_index,crypto_ov_blockchaincenter_view.display_altcoin_index crypto.ov.btcrb,crypto_ov_glassnode_model.get_btc_rainbow,crypto_ov_glassnode_view.display_btc_rainbow crypto.ov.categories,crypto_ov_pycoingecko_model.get_top_crypto_categories,crypto_ov_pycoingecko_view.display_categories @@ -268,12 +268,12 @@ forex.oanda.positionbook,forex_oanda_model.positionbook_plot_data_request,forex_ forex.oanda.price,forex_oanda_model.fx_price_request,forex_oanda_view.get_fx_price forex.oanda.summary,forex_oanda_model.account_summary_request,forex_oanda_view.get_account_summary forex.quote,forex_sdk_helpers.quote, -funds.load,funds_mstarpy_model.load_funds, -funds.search,funds_mstarpy_model.search_funds, -funds.holdings,funds_mstarpy_model.load_holdings, -funds.exclusion,funds_mstarpy_model.load_exclusion_policy, funds.carbon,funds_mstarpy_model.load_carbon_metrics, +funds.exclusion,funds_mstarpy_model.load_exclusion_policy, funds.historical,funds_mstarpy_model.get_historical,funds_mstarpy_view.display_historical +funds.holdings,funds_mstarpy_model.load_holdings, +funds.load,funds_mstarpy_model.load_funds, +funds.search,funds_mstarpy_model.search_funds, funds.sector,funds_mstarpy_model.get_sector,funds_mstarpy_view.display_sector futures.curve,futures_yfinance_model.get_curve_futures,futures_yfinance_view.display_curve futures.historical,futures_sdk_model.get_historical,futures_yfinance_view.display_historical @@ -507,6 +507,7 @@ stocks.ins.lpsb,stocks_insider_sdk_helper.lpsb, stocks.ins.print_insider_data,stocks_insider_openinsider_model.get_print_insider_data,stocks_insider_openinsider_view.print_insider_data stocks.ins.stats,stocks_insider_sdk_helper.stats, stocks.load,stocks_helper.load, +stocks.news,common_ultima_newsmonitor_model.get_news, stocks.options.chains,stocks_options_sdk_helper.get_full_option_chain, stocks.options.dte,stocks_options_yfinance_model.get_dte, stocks.options.eodchain,stocks_options_intrinio_model.get_full_chain_eod, @@ -526,7 +527,6 @@ stocks.options.unu,stocks_options_fdscanner_model.unusual_options,stocks_options stocks.options.voi,stocks_options_view.plot_voi, stocks.options.vol,stocks_options_view.plot_vol, stocks.options.vsurf,stocks_options_yfinance_model.get_iv_surface,stocks_options_yfinance_view.display_vol_surface -stocks.news,common_ultima_newsmonitor_model.get_news, stocks.process_candle,stocks_helper.process_candle, stocks.qa.beta,stocks_qa_beta_model.beta_model,stocks_qa_beta_view.beta_view stocks.qa.capm,stocks_qa_factors_model.capm_information, diff --git a/openbb_terminal/core/sdk/trailmap.py b/openbb_terminal/core/sdk/trailmap.py index 9ac83c9f6784..35240bbd8c79 100644 --- a/openbb_terminal/core/sdk/trailmap.py +++ b/openbb_terminal/core/sdk/trailmap.py @@ -1,17 +1,25 @@ import inspect + from pathlib import Path + from types import FunctionType + from typing import Any, Callable, Dict, ForwardRef, List, Optional + import pandas as pd + import openbb_terminal.core.sdk.sdk_init as lib + from openbb_terminal.core.config.paths import ( MAP_FORECASTING_PATH, MAP_OPTIMIZATION_PATH, MAP_PATH, ) + from openbb_terminal.core.sdk.sdk_helpers import clean_attr_desc + from openbb_terminal.rich_config import console @@ -19,15 +27,22 @@ def get_signature_parameters( function: Callable[..., Any], globalns: Dict[str, Any] ) -> Dict[str, inspect.Parameter]: signature = inspect.signature(function) + params = {} + cache: dict[str, Any] = {} + for name, parameter in signature.parameters.items(): annotation = parameter.annotation + if annotation is parameter.empty: params[name] = parameter + continue + if annotation is None: params[name] = parameter.replace(annotation=type(None)) + continue if isinstance(annotation, ForwardRef): @@ -44,47 +59,66 @@ def get_signature_parameters( class FuncAttr: def __init__(self) -> None: self.short_doc: Optional[str] = None + self.long_doc: Optional[str] = None + self.func_def: Optional[str] = None + self.path: Optional[str] = None + self.lineon: Optional[int] = None + self.full_path: Optional[str] = None + self.func_unwrapped: Optional[FunctionType] = None + self.func_wrapped: Optional[FunctionType] = None + self.params: Dict[str, inspect.Parameter] = {} def get_func_attrs(self, func: str) -> None: module_path, function_name = func.rsplit(".", 1) + func_attr = getattr(getattr(lib, module_path), function_name) + self.func_wrapped = func_attr add_lineon = 0 + if hasattr(func_attr, "__wrapped__"): while hasattr(func_attr, "__wrapped__"): func_attr = func_attr.__wrapped__ + add_lineon += 1 self.func_unwrapped = func_attr + self.lineon = inspect.getsourcelines(func_attr)[1] + add_lineon self.long_doc = func_attr.__doc__ + self.short_doc = clean_attr_desc(func_attr) for k, p in get_signature_parameters(func_attr, func_attr.__globals__).items(): self.params[k] = p self.path = inspect.getfile(func_attr) + full_path = ( inspect.getfile(func_attr).replace("\\", "/").split("openbb_terminal/")[1] ) + self.full_path = f"openbb_terminal/{full_path}" def get_definition( self, location_path: list, class_attr: str, view: bool = False ) -> str: """Creates the function definition to be used in SDK docs.""" + funcspec = self.params + definition = "" + for arg, param in funcspec.items(): annotation = ( ( @@ -101,50 +135,71 @@ def get_definition( ) default = "" + if param.default is not param.empty: arg_default = ( param.default if param.default is not inspect.Parameter.empty else "None" ) + default = ( f" = {arg_default}" if not isinstance(arg_default, str) else f' = "{arg_default}"' ) + definition += f"{arg}: {annotation}{default}, " definition = definition.rstrip(", ") trail = ".".join([t for t in location_path if t != ""]) + sdk_name = class_attr if not view else f"{class_attr}_chart" trail = trail.replace("root.", "") + sdk_path = f"{f'openbb.{trail}' if trail else 'openbb'}.{sdk_name}" return f"{sdk_path}({definition })" # pylint: disable=R0903 + + class Trailmap: def __init__(self, trailmap: str, model: str, view: Optional[str] = None): self.trailmap: str = trailmap + tmap = trailmap.split(".") + if len(tmap) == 1: tmap = ["root", tmap[0]] + self.class_attr: str = tmap.pop(-1) + self.location_path = tmap + self.model = model + self.view = view if view else None + self.view_name = "_chart" + self.model_func: Optional[str] = f"lib.{model}" if model else None + self.view_func: Optional[str] = f"lib.{view}" if view else None + self.func_attrs: Dict[str, FuncAttr] = {} + self.func_attrs["model"] = FuncAttr() + self.func_attrs["view"] = FuncAttr() + for k, cls in self.func_attrs.items(): if getattr(self, f"{k}_func"): cls.get_func_attrs(getattr(self, f"{k}")) + cls.func_def = cls.get_definition( tmap, self.class_attr, view=k == "view" ) @@ -155,10 +210,14 @@ def get_trailmaps(sort: bool = False) -> List[Trailmap]: def load_csv(path: Optional[Path] = None) -> Dict[str, Dict[str, str]]: path = path or MAP_PATH + df = pd.read_csv(path, keep_default_na=False) + df = df.set_index("trail") + if sort: df = df.sort_index() + df.to_csv(path, index=True) return df.to_dict(orient="index") @@ -167,21 +226,27 @@ def print_error(error: str) -> None: console.print( f"[bold red]{error} is disabled and will not be included in the SDK.[/bold red]" ) + console.print( "[bold red]`poetry install -E all` to install all toolkits.[/bold red]" ) def load(): map_dict = load_csv(path=MAP_PATH) + if lib.FORECASTING_TOOLKIT_ENABLED: map_forecasting_dict = load_csv(path=MAP_FORECASTING_PATH) + map_dict.update(map_forecasting_dict) + else: print_error("Forecasting") if lib.OPTIMIZATION_TOOLKIT_ENABLED: map_optimization_dict = load_csv(path=MAP_OPTIMIZATION_PATH) + map_dict.update(map_optimization_dict) + else: print_error("Optimization") @@ -193,7 +258,9 @@ def load(): for trail, attrs in map_dict.items(): model, view = attrs["model"], attrs["view"] + trail_map = Trailmap(trail, model, view) + trailmaps.append(trail_map) return trailmaps diff --git a/openbb_terminal/dashboards/voila/forecast.ipynb b/openbb_terminal/dashboards/voila/forecast.ipynb index 75a7c7ec6c02..49b451ae30f6 100644 --- a/openbb_terminal/dashboards/voila/forecast.ipynb +++ b/openbb_terminal/dashboards/voila/forecast.ipynb @@ -29,6 +29,7 @@ "source": [ "# Suppressing sdk logs\n", "from openbb_terminal.core.session.current_system import set_system_variable\n", + "\n", "set_system_variable(\"LOGGING_SUPPRESS\", True)\n", "\n", "# Import the OpenBB SDK\n", diff --git a/openbb_terminal/reports/templates/crypto.ipynb b/openbb_terminal/reports/templates/crypto.ipynb index 7027e1b18d4f..a5a9dd1d0bcd 100644 --- a/openbb_terminal/reports/templates/crypto.ipynb +++ b/openbb_terminal/reports/templates/crypto.ipynb @@ -46,6 +46,7 @@ "source": [ "# Suppressing sdk logs\n", "from openbb_terminal.core.session.current_system import set_system_variable\n", + "\n", "set_system_variable(\"LOGGING_SUPPRESS\", True)\n", "\n", "# Import the OpenBB SDK\n", diff --git a/openbb_terminal/reports/templates/economy.ipynb b/openbb_terminal/reports/templates/economy.ipynb index 9ba2e9a30c69..5ef15fdcb1a4 100644 --- a/openbb_terminal/reports/templates/economy.ipynb +++ b/openbb_terminal/reports/templates/economy.ipynb @@ -46,6 +46,7 @@ "source": [ "# Suppressing sdk logs\n", "from openbb_terminal.core.session.current_system import set_system_variable\n", + "\n", "set_system_variable(\"LOGGING_SUPPRESS\", True)\n", "\n", "# Import the OpenBB SDK\n", @@ -157,12 +158,16 @@ "try:\n", " news = openbb.news(\"economy\")\n", " news.columns = news.columns.str.title()\n", - " news[\"Title\"] = news.apply(lambda x: f'{x[\"Title\"]}', axis=1)\n", + " news[\"Title\"] = news.apply(\n", + " lambda x: f'{x[\"Title\"]}', axis=1\n", + " )\n", " news = news[[\"Title\", \"Published\"]]\n", " news[\"Published\"] = pd.to_datetime(news[\"Published\"]).dt.strftime(\"%Y-%m-%d %H:%M\")\n", " news.set_index(\"Published\", inplace=True)\n", "\n", - " news = OpenBBFigure.to_table(news, print_index=True, columnwidth=[1.3, 7], width=1100)\n", + " news = OpenBBFigure.to_table(\n", + " news, print_index=True, columnwidth=[1.3, 7], width=1100\n", + " )\n", " news.update_layout(clickmode=\"event+select\")\n", "except:\n", " news = pd.DataFrame()" @@ -667,9 +672,12 @@ "\n", "if not news.empty:\n", " htmlcode += widgets.row(\n", - " [widgets.h(3, \"Top news on 'economy' keyword (source: Newsapi)\") + news.to_html()]\n", + " [\n", + " widgets.h(3, \"Top news on 'economy' keyword (source: Newsapi)\")\n", + " + news.to_html()\n", + " ]\n", " )\n", - " \n", + "\n", "body += widgets.add_tab(\"SUMMARY\", htmlcode)\n", "\n", "# Events\n", diff --git a/openbb_terminal/reports/templates/equity.ipynb b/openbb_terminal/reports/templates/equity.ipynb index f9c89911a124..685b73efa3ee 100644 --- a/openbb_terminal/reports/templates/equity.ipynb +++ b/openbb_terminal/reports/templates/equity.ipynb @@ -40,6 +40,7 @@ "source": [ "# Suppressing sdk logs\n", "from openbb_terminal.core.session.current_system import set_system_variable\n", + "\n", "set_system_variable(\"LOGGING_SUPPRESS\", True)\n", "\n", "# Import the OpenBB SDK\n", diff --git a/openbb_terminal/reports/templates/etf.ipynb b/openbb_terminal/reports/templates/etf.ipynb index c172825803d7..3dea34865eb1 100644 --- a/openbb_terminal/reports/templates/etf.ipynb +++ b/openbb_terminal/reports/templates/etf.ipynb @@ -38,6 +38,7 @@ "source": [ "# Suppressing sdk logs\n", "from openbb_terminal.core.session.current_system import set_system_variable\n", + "\n", "set_system_variable(\"LOGGING_SUPPRESS\", True)\n", "\n", "# Import the OpenBB SDK\n", @@ -209,7 +210,10 @@ "if \"Percentage\" in weights_df.columns:\n", " weights_df.columns = [\"Percentage\"]\n", "\n", - "if \"Percentage\" in weights_df.columns and len(weights_df[weights_df[\"Percentage\"] > 10].index) > 1:\n", + "if (\n", + " \"Percentage\" in weights_df.columns\n", + " and len(weights_df[weights_df[\"Percentage\"] > 10].index) > 1\n", + "):\n", " colors = theme.get_colors()\n", " fig = OpenBBFigure.create_subplots(\n", " 1,\n", diff --git a/openbb_terminal/reports/templates/forecast.ipynb b/openbb_terminal/reports/templates/forecast.ipynb index 2f5cb594f435..03763c973c3e 100644 --- a/openbb_terminal/reports/templates/forecast.ipynb +++ b/openbb_terminal/reports/templates/forecast.ipynb @@ -41,6 +41,7 @@ "source": [ "# Suppressing sdk logs\n", "from openbb_terminal.core.session.current_system import set_system_variable\n", + "\n", "set_system_variable(\"LOGGING_SUPPRESS\", True)\n", "\n", "# Import the OpenBB SDK\n", diff --git a/openbb_terminal/reports/templates/forex.ipynb b/openbb_terminal/reports/templates/forex.ipynb index 1f4c7465b80c..8479cc6bdfa7 100644 --- a/openbb_terminal/reports/templates/forex.ipynb +++ b/openbb_terminal/reports/templates/forex.ipynb @@ -42,6 +42,7 @@ "source": [ "# Suppressing sdk logs\n", "from openbb_terminal.core.session.current_system import set_system_variable\n", + "\n", "set_system_variable(\"LOGGING_SUPPRESS\", True)\n", "\n", "# Import the OpenBB SDK\n", diff --git a/openbb_terminal/reports/templates/portfolio.ipynb b/openbb_terminal/reports/templates/portfolio.ipynb index 52b3dc2601ca..014dc8c88977 100644 --- a/openbb_terminal/reports/templates/portfolio.ipynb +++ b/openbb_terminal/reports/templates/portfolio.ipynb @@ -43,6 +43,7 @@ "source": [ "# Suppressing sdk logs\n", "from openbb_terminal.core.session.current_system import set_system_variable\n", + "\n", "set_system_variable(\"LOGGING_SUPPRESS\", True)\n", "\n", "# Import the OpenBB SDK\n", diff --git a/openbb_terminal/sdk.py b/openbb_terminal/sdk.py index ee4fc6cb09b5..465facfaa8d2 100644 --- a/openbb_terminal/sdk.py +++ b/openbb_terminal/sdk.py @@ -36,7 +36,7 @@ class OpenBBSDK: Attributes: `login`: Login and load user info.\n `logout`: Logout and clear session.\n - `news`: Get news for a given term and source. [Source: Feedparser]\n + `news`: Get news for a given term and source. [Source: Ultima Insights News Monitor]\n `whoami`: Display user info.\n """ @@ -516,7 +516,7 @@ def stocks(self): Attributes: `candle`: Show candle plot of loaded ticker.\n `load`: Load a symbol to perform analysis using the string above as a template.\n - `news`: Get news for a given term and source. [Source: Feedparser]\n + `news`: Get news for a given term and source. [Source: Ultima Insights News Monitor]\n `process_candle`: Process DataFrame into candle style plot.\n `quote`: Gets ticker quote from FMP\n `search`: Search selected query for tickers.\n From a00d6ef4d0348df249d4e38196e6e08aadd228e4 Mon Sep 17 00:00:00 2001 From: teh_coderer Date: Wed, 26 Apr 2023 00:01:52 -0400 Subject: [PATCH 07/14] bump pywry --- poetry.lock | 32 ++++++++++++++++---------------- pyproject.toml | 2 +- requirements-full.txt | 2 +- requirements.txt | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/poetry.lock b/poetry.lock index 56c094997328..f3bfb7f6b8d3 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.4.0 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.4.2 and should not be changed by hand. [[package]] name = "absl-py" @@ -6461,25 +6461,25 @@ files = [ [[package]] name = "pywry" -version = "0.4.8" +version = "0.4.9" description = "" category = "main" optional = false python-versions = ">=3.8" files = [ - {file = "pywry-0.4.8-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:ed25402bb742d24d5ec0531b14b37fc1321f9f7387743e74bbd7c60383361895"}, - {file = "pywry-0.4.8-cp310-cp310-manylinux_2_28_x86_64.whl", hash = "sha256:9375400d8db85e885459b723ab7261f2f8a84daeda12ff0e9cb00f51ab540c75"}, - {file = "pywry-0.4.8-cp310-none-win_amd64.whl", hash = "sha256:081ddc8b6bd1656d94c23c79aab11c18ba2f30fae5d05764409ddf933f7e1398"}, - {file = "pywry-0.4.8-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:98260336dc01c638546b7360a9219bb21c0563e58b0cd8093dc59e8e9032ffaa"}, - {file = "pywry-0.4.8-cp311-cp311-manylinux_2_28_x86_64.whl", hash = "sha256:304509551ad797b738105037e0ce881502f4b272aa93a0c1dc6afcd4b67d25f9"}, - {file = "pywry-0.4.8-cp311-none-win_amd64.whl", hash = "sha256:b7c41369997071be16bebde755e34dacce05a3420bbec3c116a5403e50a0ee0f"}, - {file = "pywry-0.4.8-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:26d5902e26ac48f9996169d9bb1cbd86930fb8d5cf2941d2d329d5f36088d476"}, - {file = "pywry-0.4.8-cp38-cp38-manylinux_2_28_x86_64.whl", hash = "sha256:5aa3b62a6c0b95ee3c842f594f2bb0c4090a63b3573e2515fcb7c06b02bc5ba1"}, - {file = "pywry-0.4.8-cp38-none-win_amd64.whl", hash = "sha256:3df9986f8ad7b8bb4c4fd8644bd785f3b23a01c2f9a377df7875974beab25c00"}, - {file = "pywry-0.4.8-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:0c57fee1746a84d19fa46142db7f394236a7e6fad78f10be44fd23c1310b990c"}, - {file = "pywry-0.4.8-cp39-cp39-manylinux_2_28_x86_64.whl", hash = "sha256:18b0be063650dfcc46b03f61ed97a4a32dbd2956feee1b9a8e94a7a2a82da960"}, - {file = "pywry-0.4.8-cp39-none-win_amd64.whl", hash = "sha256:dc1367aa1eb435743a7105cd7352189201662a7cdbc22415c08cab68e0fad931"}, - {file = "pywry-0.4.8.tar.gz", hash = "sha256:5ca24922bd406cd9054b11d019a81f5769a5cacfc6de9fc3ce1b091981c99f7e"}, + {file = "pywry-0.4.9-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:8db86b4d55683e851537ca6f67b24855af0a9272a465db948b61022b77be1005"}, + {file = "pywry-0.4.9-cp310-cp310-manylinux_2_28_x86_64.whl", hash = "sha256:d190284949b46d8bbb77172a51fad54bf4cb166886d56bcb7ad7406f46d79876"}, + {file = "pywry-0.4.9-cp310-none-win_amd64.whl", hash = "sha256:8311c8558e2b8b49a8ad0312adc75ec9d9c8773a3a2e4ffc6984d152ea4e5a64"}, + {file = "pywry-0.4.9-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:4d5ae1e6e91e76984d2e105ee00696641d9b889c9bb93d1d8bca0311ee156148"}, + {file = "pywry-0.4.9-cp311-cp311-manylinux_2_28_x86_64.whl", hash = "sha256:6996dc35eb8c56178d7b7b06be3ed31f471c5c5d9b8ae3646bcfc5b65659d7e1"}, + {file = "pywry-0.4.9-cp311-none-win_amd64.whl", hash = "sha256:f40613e4eaf122bd97513fc965bedc32fb8f7abb324fa91fcb1d5a4c0a14f3f6"}, + {file = "pywry-0.4.9-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:488d6856e0dc63d8f1d77f999c114c511f32e5792449f9a96cd5028839c2260c"}, + {file = "pywry-0.4.9-cp38-cp38-manylinux_2_28_x86_64.whl", hash = "sha256:d5d7788269269be1f43ea306242b72432ea3b45ed0acba6ef787b06b2bb27ad5"}, + {file = "pywry-0.4.9-cp38-none-win_amd64.whl", hash = "sha256:65c99a8b984be78d8420ee037cf705823b95d6b3a8e9cc6b9a237fb4b99e2718"}, + {file = "pywry-0.4.9-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:49e48583a8e8d67af42b30d3663a231bec82a05dc8e9cdd9c5100360fc69152a"}, + {file = "pywry-0.4.9-cp39-cp39-manylinux_2_28_x86_64.whl", hash = "sha256:73572e6c22a9d7ac43bce3c00070412e6f6d01884fc70d37ca1c2db6bc7d7546"}, + {file = "pywry-0.4.9-cp39-none-win_amd64.whl", hash = "sha256:b47f1d4e5f42a78e3735e3b54fd9b60c8cb5a80d2928bab1c5190ed03a10f800"}, + {file = "pywry-0.4.9.tar.gz", hash = "sha256:d891a07bc82a12b572095fd66a32b23ca9d956ad35a44d62aa9f3b6a26627b1d"}, ] [package.dependencies] @@ -9656,4 +9656,4 @@ optimization = ["Riskfolio-Lib"] [metadata] lock-version = "2.0" python-versions = "^3.8,<3.11, !=3.9.7" -content-hash = "f750f2d47909d1f88e2b0fae74dd6c812f30f5a9923d46f528f22dc6034d0036" +content-hash = "6d941c794f4d9bbedc714913b3ffc4a7c0882eae8fc569a300d5be152025a32e" diff --git a/pyproject.toml b/pyproject.toml index 4501104e3c33..3cb3afeff909 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -101,7 +101,7 @@ jupyterlab-widgets = "^3.0.3" mstarpy = "^0.0.4" packaging = ">=22.0" streamlit = "^1.21.0" -pywry = "^0.4.8" +pywry = "^0.4.9" svglib = "^1.5.0" sparqlwrapper = "^2.0.0" y-py = "!=0.5.5" # Untraceable third level dependency that requires cargo to be built diff --git a/requirements-full.txt b/requirements-full.txt index 8b921a453dc8..3fab7c948954 100644 --- a/requirements-full.txt +++ b/requirements-full.txt @@ -265,7 +265,7 @@ pytz==2022.7.1 ; python_version >= "3.8" and python_full_version != "3.9.7" and pywin32-ctypes==0.2.0 ; python_version >= "3.8" and python_version < "3.11" and python_full_version != "3.9.7" and sys_platform == "win32" pywin32==305 ; sys_platform == "win32" and platform_python_implementation != "PyPy" and python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" pywinpty==2.0.10 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" and os_name == "nt" -pywry==0.4.8 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" +pywry==0.4.9 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" pyyaml==6.0 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" pyzmq==25.0.1 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" qdldl==0.1.5.post3 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" diff --git a/requirements.txt b/requirements.txt index 8c2521e3d1bb..750253395a90 100644 --- a/requirements.txt +++ b/requirements.txt @@ -182,7 +182,7 @@ pytz-deprecation-shim==0.1.0.post0 ; python_version >= "3.8" and python_full_ver pytz==2022.7.1 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" pywin32==305 ; sys_platform == "win32" and platform_python_implementation != "PyPy" and python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" pywinpty==2.0.10 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" and os_name == "nt" -pywry==0.4.8 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" +pywry==0.4.9 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" pyyaml==6.0 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" pyzmq==25.0.1 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" quandl==3.7.0 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" From 839638bf05d8c49c86fc83e64eccca586c85cef5 Mon Sep 17 00:00:00 2001 From: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Date: Wed, 26 Apr 2023 10:05:15 +0100 Subject: [PATCH 08/14] fix rm command (#4890) Co-authored-by: Henrique Joaquim --- openbb_terminal/cryptocurrency/due_diligence/messari_view.py | 3 +-- openbb_terminal/helper_funcs.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/openbb_terminal/cryptocurrency/due_diligence/messari_view.py b/openbb_terminal/cryptocurrency/due_diligence/messari_view.py index 6977d467cb28..12eea754f1c4 100644 --- a/openbb_terminal/cryptocurrency/due_diligence/messari_view.py +++ b/openbb_terminal/cryptocurrency/due_diligence/messari_view.py @@ -340,7 +340,6 @@ def display_roadmap( ) df_copy = df_copy[df_copy["Date"].notnull()] - titles = list(df_copy[df_copy["Date"] > df_prices.index[0]]["Title"]) max_price = df_prices["Close"].max() for counter, x in enumerate(roadmap_dates): @@ -348,7 +347,7 @@ def display_roadmap( fig.add_annotation( x=x, y=max_price * 0.7, - text=titles[counter], + text=df.iloc[counter]["Title"], textangle=90, font=dict(size=15), xshift=10, diff --git a/openbb_terminal/helper_funcs.py b/openbb_terminal/helper_funcs.py index cd845ad0b200..a4eee4f0ab00 100644 --- a/openbb_terminal/helper_funcs.py +++ b/openbb_terminal/helper_funcs.py @@ -307,7 +307,7 @@ def print_rich_table( try: if not isinstance(df[col].iloc[0], pd.Timestamp): df[col] = pd.to_numeric(df[col]) - except ValueError: + except (ValueError, TypeError): pass def _get_headers(_headers: Union[List[str], pd.Index]) -> List[str]: From e7b8b381cafc967b8432402982151aad9cf2e81b Mon Sep 17 00:00:00 2001 From: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Date: Wed, 26 Apr 2023 10:14:54 +0100 Subject: [PATCH 09/14] Fix `crypto/defi/anchor` (#4892) * handle defi anchor exceptions * reason * mypy --------- Co-authored-by: Henrique Joaquim --- .../cryptocurrency/defi/cryptosaurio_model.py | 7 +++-- .../cryptocurrency/defi/cryptosaurio_view.py | 31 ++++++++++--------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/openbb_terminal/cryptocurrency/defi/cryptosaurio_model.py b/openbb_terminal/cryptocurrency/defi/cryptosaurio_model.py index 1d921181ab90..177a7ced5a53 100644 --- a/openbb_terminal/cryptocurrency/defi/cryptosaurio_model.py +++ b/openbb_terminal/cryptocurrency/defi/cryptosaurio_model.py @@ -8,6 +8,7 @@ from openbb_terminal.decorators import log_start_end from openbb_terminal.helper_funcs import request +from openbb_terminal.rich_config import console logger = logging.getLogger(__name__) @@ -33,13 +34,15 @@ def get_anchor_data(address: str = "") -> Tuple[pd.DataFrame, pd.DataFrame, str] """ if not address.startswith("terra"): - raise Exception( + console.print( "Select a valid address. Valid terra addresses start with 'terra'" ) + return pd.DataFrame(), pd.DataFrame(), "" response = request(f"{api_url}/get-anchor-protocol-data-v2/{address}") if response.status_code != 200: - raise Exception(f"Status code: {response.status_code}. Reason: {response.text}") + console.print(f"Status code: {response.status_code}. Reason: {response.reason}") + return pd.DataFrame(), pd.DataFrame(), "" data = response.json() df = pd.DataFrame(reversed(data["historicalData"])) diff --git a/openbb_terminal/cryptocurrency/defi/cryptosaurio_view.py b/openbb_terminal/cryptocurrency/defi/cryptosaurio_view.py index 5a74ac63538a..c903ee1fea5d 100644 --- a/openbb_terminal/cryptocurrency/defi/cryptosaurio_view.py +++ b/openbb_terminal/cryptocurrency/defi/cryptosaurio_view.py @@ -41,9 +41,10 @@ def display_anchor_data( df, df_deposits, stats_str = cryptosaurio_model.get_anchor_data(address=address) - console.print(f"\n{stats_str}\n") + if stats_str: + console.print(f"\n{stats_str}\n") - if show_transactions: + if not df_deposits.empty and show_transactions: print_rich_table( df_deposits, headers=list(df_deposits.columns), @@ -52,18 +53,20 @@ def display_anchor_data( export=bool(export), ) - fig = OpenBBFigure(yaxis_title="Earnings Value [UST]") - fig.set_title("Earnings in Anchor Earn") + if not df.empty: + fig = OpenBBFigure(yaxis_title="Earnings Value [UST]") + fig.set_title("Earnings in Anchor Earn") - fig.add_scatter(x=df["time"], y=df["yield"], name="Earnings") + fig.add_scatter(x=df["time"], y=df["yield"], name="Earnings") - export_data( - export, - os.path.dirname(os.path.abspath(__file__)), - "anchor", - df, - sheet_name, - fig, - ) + export_data( + export, + os.path.dirname(os.path.abspath(__file__)), + "anchor", + df, + sheet_name, + fig, + ) - return fig.show(external=external_axes) + return fig.show(external=external_axes) + return None From 61dffa02308c968778383655bc59b895c6baa989 Mon Sep 17 00:00:00 2001 From: teh_coderer Date: Wed, 26 Apr 2023 10:28:10 -0400 Subject: [PATCH 10/14] fix windows pyinstaller subprocess fail if space in path --- poetry.lock | 32 ++++++++++++++++---------------- pyproject.toml | 2 +- requirements-full.txt | 2 +- requirements.txt | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/poetry.lock b/poetry.lock index f3bfb7f6b8d3..557d23fba1ed 100644 --- a/poetry.lock +++ b/poetry.lock @@ -6461,31 +6461,31 @@ files = [ [[package]] name = "pywry" -version = "0.4.9" +version = "0.5.0" description = "" category = "main" optional = false python-versions = ">=3.8" files = [ - {file = "pywry-0.4.9-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:8db86b4d55683e851537ca6f67b24855af0a9272a465db948b61022b77be1005"}, - {file = "pywry-0.4.9-cp310-cp310-manylinux_2_28_x86_64.whl", hash = "sha256:d190284949b46d8bbb77172a51fad54bf4cb166886d56bcb7ad7406f46d79876"}, - {file = "pywry-0.4.9-cp310-none-win_amd64.whl", hash = "sha256:8311c8558e2b8b49a8ad0312adc75ec9d9c8773a3a2e4ffc6984d152ea4e5a64"}, - {file = "pywry-0.4.9-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:4d5ae1e6e91e76984d2e105ee00696641d9b889c9bb93d1d8bca0311ee156148"}, - {file = "pywry-0.4.9-cp311-cp311-manylinux_2_28_x86_64.whl", hash = "sha256:6996dc35eb8c56178d7b7b06be3ed31f471c5c5d9b8ae3646bcfc5b65659d7e1"}, - {file = "pywry-0.4.9-cp311-none-win_amd64.whl", hash = "sha256:f40613e4eaf122bd97513fc965bedc32fb8f7abb324fa91fcb1d5a4c0a14f3f6"}, - {file = "pywry-0.4.9-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:488d6856e0dc63d8f1d77f999c114c511f32e5792449f9a96cd5028839c2260c"}, - {file = "pywry-0.4.9-cp38-cp38-manylinux_2_28_x86_64.whl", hash = "sha256:d5d7788269269be1f43ea306242b72432ea3b45ed0acba6ef787b06b2bb27ad5"}, - {file = "pywry-0.4.9-cp38-none-win_amd64.whl", hash = "sha256:65c99a8b984be78d8420ee037cf705823b95d6b3a8e9cc6b9a237fb4b99e2718"}, - {file = "pywry-0.4.9-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:49e48583a8e8d67af42b30d3663a231bec82a05dc8e9cdd9c5100360fc69152a"}, - {file = "pywry-0.4.9-cp39-cp39-manylinux_2_28_x86_64.whl", hash = "sha256:73572e6c22a9d7ac43bce3c00070412e6f6d01884fc70d37ca1c2db6bc7d7546"}, - {file = "pywry-0.4.9-cp39-none-win_amd64.whl", hash = "sha256:b47f1d4e5f42a78e3735e3b54fd9b60c8cb5a80d2928bab1c5190ed03a10f800"}, - {file = "pywry-0.4.9.tar.gz", hash = "sha256:d891a07bc82a12b572095fd66a32b23ca9d956ad35a44d62aa9f3b6a26627b1d"}, + {file = "pywry-0.5.0-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:bba57144a054027084c9b8829fc92a98742b6eeaef895670d0301be103292a18"}, + {file = "pywry-0.5.0-cp310-cp310-manylinux_2_28_x86_64.whl", hash = "sha256:dd5b1806075682dd6a7b9715dad044bf625ac09ea04447a95c2c3af356b68d05"}, + {file = "pywry-0.5.0-cp310-none-win_amd64.whl", hash = "sha256:7dba52d39c156214a04b9f4003b02805c9c3c5ae63cf121dd2174e0f35c4f5a2"}, + {file = "pywry-0.5.0-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:169c3732f1fa7066d250b9603d3d6dc4aa67d0b62433f254b596a0fe97afe52f"}, + {file = "pywry-0.5.0-cp311-cp311-manylinux_2_28_x86_64.whl", hash = "sha256:f04cd9d0cebadbaf8fbbec851f24c3d8b0468408514069b8421e4db497fbaffa"}, + {file = "pywry-0.5.0-cp311-none-win_amd64.whl", hash = "sha256:9920a1a4acc8058655075fb52c31f53b1f8438462c8b9947c4f7cd302ced1ae9"}, + {file = "pywry-0.5.0-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:dd40af058a2731037fb53f81d3fa12b014eb5b6110bbc2ab1792a005c5f9bd8c"}, + {file = "pywry-0.5.0-cp38-cp38-manylinux_2_28_x86_64.whl", hash = "sha256:4f39c990feb98be4e4f1d30d4fd750fe7c74f288698ebfff484d3ae0451ffe74"}, + {file = "pywry-0.5.0-cp38-none-win_amd64.whl", hash = "sha256:2959b2ff68b1548958ed4eec6fe0f2ffe4d20120385c8300a5da5e48aef71022"}, + {file = "pywry-0.5.0-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:93a375cb67e7c954460a5025de17bab0a22f3e396e87532ab68dec7a36a2200d"}, + {file = "pywry-0.5.0-cp39-cp39-manylinux_2_28_x86_64.whl", hash = "sha256:0f89efec669a0445b758894bb6b26fdbad82140b0912da45b64d8e7aab0d4d68"}, + {file = "pywry-0.5.0-cp39-none-win_amd64.whl", hash = "sha256:0a54b8435f754c7f2e03e2a04c67bfc2c4da2931488fdd22cf5ae7b78c6f2c2b"}, + {file = "pywry-0.5.0.tar.gz", hash = "sha256:29b594ace5dde2047f0cb167df2cfa7ae76b8adc8c27947f03300cb64517c11e"}, ] [package.dependencies] psutil = ">=5.8.0,<5.9.4" setproctitle = "*" -websockets = ">=11.0.1" +websockets = "*" [package.extras] dev = ["auditwheel", "wheel"] @@ -9656,4 +9656,4 @@ optimization = ["Riskfolio-Lib"] [metadata] lock-version = "2.0" python-versions = "^3.8,<3.11, !=3.9.7" -content-hash = "6d941c794f4d9bbedc714913b3ffc4a7c0882eae8fc569a300d5be152025a32e" +content-hash = "d2bc3a75f2aff5123a842c656d6e8a9d51fa829433dc0cb1a02deb1d5c6967d9" diff --git a/pyproject.toml b/pyproject.toml index 3cb3afeff909..889c48327604 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -101,7 +101,7 @@ jupyterlab-widgets = "^3.0.3" mstarpy = "^0.0.4" packaging = ">=22.0" streamlit = "^1.21.0" -pywry = "^0.4.9" +pywry = "^0.5.0" svglib = "^1.5.0" sparqlwrapper = "^2.0.0" y-py = "!=0.5.5" # Untraceable third level dependency that requires cargo to be built diff --git a/requirements-full.txt b/requirements-full.txt index 3fab7c948954..b4e35ccb566c 100644 --- a/requirements-full.txt +++ b/requirements-full.txt @@ -265,7 +265,7 @@ pytz==2022.7.1 ; python_version >= "3.8" and python_full_version != "3.9.7" and pywin32-ctypes==0.2.0 ; python_version >= "3.8" and python_version < "3.11" and python_full_version != "3.9.7" and sys_platform == "win32" pywin32==305 ; sys_platform == "win32" and platform_python_implementation != "PyPy" and python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" pywinpty==2.0.10 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" and os_name == "nt" -pywry==0.4.9 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" +pywry==0.5.0 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" pyyaml==6.0 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" pyzmq==25.0.1 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" qdldl==0.1.5.post3 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" diff --git a/requirements.txt b/requirements.txt index 750253395a90..9490ac55b3f6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -182,7 +182,7 @@ pytz-deprecation-shim==0.1.0.post0 ; python_version >= "3.8" and python_full_ver pytz==2022.7.1 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" pywin32==305 ; sys_platform == "win32" and platform_python_implementation != "PyPy" and python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" pywinpty==2.0.10 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" and os_name == "nt" -pywry==0.4.9 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" +pywry==0.5.0 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" pyyaml==6.0 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" pyzmq==25.0.1 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" quandl==3.7.0 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" From 30d5e587765cd239b2221e72254ca2e176416a2f Mon Sep 17 00:00:00 2001 From: teh_coderer Date: Wed, 26 Apr 2023 10:32:26 -0400 Subject: [PATCH 11/14] remove API_IEX_TOKEN --- openbb_terminal/miscellaneous/models/hub_credentials.json | 1 - tests/openbb_terminal/test_keys_controller.py | 1 - 2 files changed, 2 deletions(-) diff --git a/openbb_terminal/miscellaneous/models/hub_credentials.json b/openbb_terminal/miscellaneous/models/hub_credentials.json index 633f70884c23..f302ed75d6e2 100644 --- a/openbb_terminal/miscellaneous/models/hub_credentials.json +++ b/openbb_terminal/miscellaneous/models/hub_credentials.json @@ -9,7 +9,6 @@ "API_NEWS_TOKEN": "", "API_CMC_KEY": "", "API_FINNHUB_KEY": "", - "API_IEX_TOKEN": "", "API_SENTIMENTINVESTOR_TOKEN": "", "API_WHALE_ALERT_KEY": "", "API_GLASSNODE_KEY": "", diff --git a/tests/openbb_terminal/test_keys_controller.py b/tests/openbb_terminal/test_keys_controller.py index 451ba653371e..eaa416045d0c 100644 --- a/tests/openbb_terminal/test_keys_controller.py +++ b/tests/openbb_terminal/test_keys_controller.py @@ -48,7 +48,6 @@ def __init__(self, **kwargs): self.API_TRADIER_TOKEN = kwargs.get("TRADIER", None) self.API_CMC_KEY = kwargs.get("CMC", None) self.API_FINNHUB_KEY = kwargs.get("FINNHUB", None) - self.API_IEX_TOKEN = kwargs.get("IEX", None) self.API_REDDIT_CLIENT_ID = kwargs.get("REDDIT_CLIENT", None) self.API_REDDIT_CLIENT_SECRET = kwargs.get("REDDIT_SECRET", None) self.API_REDDIT_USERNAME = kwargs.get("REDDIT_USERNAME", None) From 915dd1fa41d9548c93801efd7f5c394835a9190e Mon Sep 17 00:00:00 2001 From: teh_coderer Date: Wed, 26 Apr 2023 10:33:26 -0400 Subject: [PATCH 12/14] remove API_SENTIMENTINVESTOR_TOKEN --- openbb_terminal/miscellaneous/models/hub_credentials.json | 1 - tests/openbb_terminal/test_keys_controller.py | 1 - 2 files changed, 2 deletions(-) diff --git a/openbb_terminal/miscellaneous/models/hub_credentials.json b/openbb_terminal/miscellaneous/models/hub_credentials.json index f302ed75d6e2..47891a407abe 100644 --- a/openbb_terminal/miscellaneous/models/hub_credentials.json +++ b/openbb_terminal/miscellaneous/models/hub_credentials.json @@ -9,7 +9,6 @@ "API_NEWS_TOKEN": "", "API_CMC_KEY": "", "API_FINNHUB_KEY": "", - "API_SENTIMENTINVESTOR_TOKEN": "", "API_WHALE_ALERT_KEY": "", "API_GLASSNODE_KEY": "", "API_COINGLASS_KEY": "", diff --git a/tests/openbb_terminal/test_keys_controller.py b/tests/openbb_terminal/test_keys_controller.py index eaa416045d0c..10c2de4d5cf4 100644 --- a/tests/openbb_terminal/test_keys_controller.py +++ b/tests/openbb_terminal/test_keys_controller.py @@ -64,7 +64,6 @@ def __init__(self, **kwargs): self.API_BINANCE_KEY = kwargs.get("BINANCE", None) self.API_BINANCE_SECRET = kwargs.get("BINANCE", None) self.API_BITQUERY_KEY = kwargs.get("BITQUERY", None) - self.API_SENTIMENTINVESTOR_TOKEN = kwargs.get("SI", None) self.API_COINBASE_KEY = kwargs.get("COINBASE", None) self.API_COINBASE_SECRET = kwargs.get("COINBASE", None) self.API_COINBASE_PASS_PHRASE = kwargs.get("COINBASE", None) From fffbfbdb21162dce60bef2482a9b6cdff7f1723d Mon Sep 17 00:00:00 2001 From: James Maslek Date: Thu, 27 Apr 2023 16:09:06 -0400 Subject: [PATCH 13/14] make -h actually work --- openbb_terminal/cryptocurrency/onchain/onchain_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbb_terminal/cryptocurrency/onchain/onchain_controller.py b/openbb_terminal/cryptocurrency/onchain/onchain_controller.py index 4e770df5f5e5..a1a631085d5b 100644 --- a/openbb_terminal/cryptocurrency/onchain/onchain_controller.py +++ b/openbb_terminal/cryptocurrency/onchain/onchain_controller.py @@ -152,7 +152,7 @@ def call_query(self, other_args: List[str]): dest="query", type=str, nargs="+", - required=True, + required=not any(["-h" in other_args,"--help" in other_args]), help="Query to make", ) From b1ddb512a8d620b359385b3087314fea0ddad5db Mon Sep 17 00:00:00 2001 From: James Maslek Date: Thu, 27 Apr 2023 16:09:47 -0400 Subject: [PATCH 14/14] black ./ --- openbb_terminal/cryptocurrency/onchain/onchain_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbb_terminal/cryptocurrency/onchain/onchain_controller.py b/openbb_terminal/cryptocurrency/onchain/onchain_controller.py index a1a631085d5b..9b3fea3f691d 100644 --- a/openbb_terminal/cryptocurrency/onchain/onchain_controller.py +++ b/openbb_terminal/cryptocurrency/onchain/onchain_controller.py @@ -152,7 +152,7 @@ def call_query(self, other_args: List[str]): dest="query", type=str, nargs="+", - required=not any(["-h" in other_args,"--help" in other_args]), + required=not any(["-h" in other_args, "--help" in other_args]), help="Query to make", )