diff --git a/.coveragerc b/.coveragerc index d640f2996a1..81e405bf455 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,4 +1,5 @@ [coverage:run] omit = env/* + tests/* source = . diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b74f5fdfeb7..81df95451bb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.4.0 + rev: v4.0.1 hooks: - id: check-yaml - id: end-of-file-fixer @@ -8,16 +8,16 @@ repos: - id: check-merge-conflict - id: detect-private-key - repo: https://github.com/psf/black - rev: 21.5b1 + rev: 21.7b0 hooks: - id: black - repo: https://github.com/pycqa/flake8 - rev: 3.9.1 + rev: 3.9.2 hooks: - id: flake8 entry: flake8 --max-line-length=122 --ignore=E203,W503 - repo: https://github.com/codespell-project/codespell - rev: v2.0.0 + rev: v2.1.0 hooks: - id: codespell entry: codespell @@ -28,7 +28,7 @@ repos: - id: mypy args: [ --ignore-missing-imports ] - repo: https://github.com/pre-commit/mirrors-pylint - rev: 'v3.0.0a3' + rev: 'v3.0.0a4' hooks: - id: pylint entry: pylint terminal.py gamestonk_terminal tests @@ -39,7 +39,7 @@ repos: args: [ '--baseline', '.secrets.baseline' ] exclude: package.lock.json - repo: https://github.com/asottile/pyupgrade - rev: v2.18.2 + rev: v2.23.3 hooks: - id: pyupgrade args: [ --py36-plus ] diff --git a/gamestonk_terminal/__init__.py b/gamestonk_terminal/__init__.py index e69de29bb2d..5fb8cfce141 100644 --- a/gamestonk_terminal/__init__.py +++ b/gamestonk_terminal/__init__.py @@ -0,0 +1,10 @@ +# flake8: noqa +from . import common +from . import cryptocurrency +from . import economy +from . import etf +from . import forex +from . import options +from . import portfolio +from . import resources +from . import stocks diff --git a/gamestonk_terminal/forex/__init.py__ b/gamestonk_terminal/common/__init__.py similarity index 100% rename from gamestonk_terminal/forex/__init.py__ rename to gamestonk_terminal/common/__init__.py diff --git a/gamestonk_terminal/common/behavioural_analysis/__init__.py b/gamestonk_terminal/common/behavioural_analysis/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/gamestonk_terminal/common/exploratory_data_analysis/__init__.py b/gamestonk_terminal/common/exploratory_data_analysis/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/gamestonk_terminal/common/exploratory_data_analysis/eda_api.py b/gamestonk_terminal/common/exploratory_data_analysis/eda_api.py index 2a59d426eac..4dc1df1c6d9 100644 --- a/gamestonk_terminal/common/exploratory_data_analysis/eda_api.py +++ b/gamestonk_terminal/common/exploratory_data_analysis/eda_api.py @@ -11,6 +11,8 @@ from pandas.plotting import register_matplotlib_converters import numpy as np import seaborn as sns import statsmodels.api as sm + +# pylint: disable=R0402 import matplotlib.gridspec as gridspec from statsmodels.tsa.seasonal import seasonal_decompose from gamestonk_terminal.helper_funcs import ( diff --git a/gamestonk_terminal/common/prediction_techniques/__init__.py b/gamestonk_terminal/common/prediction_techniques/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/gamestonk_terminal/common/residuals_analysis/__init__.py b/gamestonk_terminal/common/residuals_analysis/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/gamestonk_terminal/common/residuals_analysis/residuals_api.py b/gamestonk_terminal/common/residuals_analysis/residuals_api.py index 89e3117b754..f7f3306876f 100644 --- a/gamestonk_terminal/common/residuals_analysis/residuals_api.py +++ b/gamestonk_terminal/common/residuals_analysis/residuals_api.py @@ -8,13 +8,14 @@ from matplotlib import pyplot as plt import pandas as pd from pandas.plotting import register_matplotlib_converters import seaborn as sns -import scipy.stats as stats +from scipy import stats import statsmodels.api as sm + +# pylint: disable=R0402 import matplotlib.gridspec as gridspec from statsmodels.graphics.gofplots import qqplot from statsmodels.tsa.stattools import adfuller, kpss, bds from statsmodels.stats.diagnostic import het_arch -from scipy.stats import skewtest, kurtosistest, skew, kurtosis from gamestonk_terminal.helper_funcs import ( parse_known_args_and_warn, plot_autoscale, @@ -352,11 +353,11 @@ def normality( # Kurtosis # Measures height and sharpness of the central peak relative to that of a standard bell curve - k, kpval = kurtosistest(residuals) + k, kpval = stats.kurtosistest(residuals) # Skewness # Measure of the asymmetry of the probability distribution of a random variable about its mean - s, spval = skewtest(residuals) + s, spval = stats.skewtest(residuals) # Jarque-Bera goodness of fit test on sample data # Tests if the sample data has the skewness and kurtosis matching a normal distribution @@ -380,9 +381,9 @@ def normality( ) print("") - kurtosis_val = kurtosis(residuals, fisher=True) + kurtosis_val = stats.kurtosis(residuals, fisher=True) print("Kurtosis value: %.4f" % kurtosis_val) - skew_val = skew(residuals) + skew_val = stats.skew(residuals) print("Skewness value: %.4f" % skew_val) print("") diff --git a/gamestonk_terminal/common/technical_analysis/__init__.py b/gamestonk_terminal/common/technical_analysis/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/gamestonk_terminal/cryptocurrency/technical_analysis/__init__.py b/gamestonk_terminal/cryptocurrency/technical_analysis/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/gamestonk_terminal/economy/report/__init__.py b/gamestonk_terminal/economy/report/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/gamestonk_terminal/forex/__init__.py b/gamestonk_terminal/forex/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/gamestonk_terminal/forex/behavioural_analysis/__init__.py b/gamestonk_terminal/forex/behavioural_analysis/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/gamestonk_terminal/forex/exploratory_data_analysis/__init__.py b/gamestonk_terminal/forex/exploratory_data_analysis/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/gamestonk_terminal/forex/fx_view.py b/gamestonk_terminal/forex/fx_view.py index 864acf2ade5..d612e48514b 100644 --- a/gamestonk_terminal/forex/fx_view.py +++ b/gamestonk_terminal/forex/fx_view.py @@ -1,14 +1,27 @@ +from datetime import datetime import argparse -from oandapyV20 import API from typing import List -import oandapyV20.endpoints.pricing as pricing -import oandapyV20.endpoints.accounts as accounts -import oandapyV20.endpoints.orders as orders -import oandapyV20.endpoints.instruments as instruments -import oandapyV20.endpoints.positions as positions -import oandapyV20.endpoints.trades as trades -import oandapyV20.endpoints.forexlabs as labs + + +import pandas as pd +import pandas_ta as ta +import mplfinance as mpf +import matplotlib.pyplot as plt +import matplotlib.ticker as mticker +import seaborn as sns + +from oandapyV20 import API from oandapyV20.exceptions import V20Error +from oandapyV20.endpoints import ( + pricing, + accounts, + orders, + instruments, + positions, + trades, + forexlabs, +) + from gamestonk_terminal import config_terminal as cfg from gamestonk_terminal import config_plot as cfgPlot from gamestonk_terminal import feature_flags as gtff @@ -17,13 +30,6 @@ from gamestonk_terminal.helper_funcs import ( plot_autoscale, check_non_negative, ) -import pandas as pd -import pandas_ta as ta -import mplfinance as mpf -import matplotlib.pyplot as plt -import matplotlib.ticker as mticker -import seaborn as sns -from datetime import datetime client = API(access_token=cfg.OANDA_TOKEN, environment="live") @@ -51,6 +57,7 @@ def get_fx_price(accountID, instrument, other_args: List[str]): print("") except V20Error as e: + # pylint: disable=W0123 d_error = eval(e.msg) print(d_error["errorMessage"], "\n") @@ -106,6 +113,7 @@ def get_account_summary(accountID, other_args: List[str]): print("") except V20Error as e: + # pylint: disable=W0123 d_error = eval(e.msg) print(d_error["errorMessage"], "\n") @@ -154,6 +162,7 @@ def list_orders(accountID, other_args: List[str]): except KeyError: print("No orders were found\n") except V20Error as e: + # pylint: disable=W0123 d_error = eval(e.msg) print(d_error["errorMessage"], "\n") @@ -182,6 +191,7 @@ def get_order_book(instrument, other_args): print("") except V20Error as e: + # pylint: disable=W0123 d_error = eval(e.msg) print(d_error["errorMessage"], "\n") @@ -207,6 +217,7 @@ def get_position_book(instrument, other_args): print("") except V20Error as e: + # pylint: disable=W0123 d_error = eval(e.msg) print(d_error["errorMessage"], "\n") @@ -241,7 +252,7 @@ def create_order(accountID, instrument, other_args: List[str]): ns_parser = parse_known_args_and_warn(parser, other_args) if not ns_parser: return - if "JPY" or "THB" or "HUF" in instrument: + if "JPY" in instrument or "THB" in instrument or "HUF" in instrument: ns_parser.price = round(ns_parser.price, 3) else: ns_parser.price = round(ns_parser.price, 5) @@ -274,6 +285,7 @@ def create_order(accountID, instrument, other_args: List[str]): print("") except V20Error as e: + # pylint: disable=W0123 d_error = eval(e.msg) print(d_error["errorMessage"], "\n") except Exception as e: @@ -307,6 +319,7 @@ def cancel_pending_order(accountID, other_args: List[str]): print(f"Order {order_id} canceled.") print("") except V20Error as e: + # pylint: disable=W0123 d_error = eval(e.msg) print(d_error["errorMessage"], "\n") @@ -347,6 +360,7 @@ def get_pending_orders(accountID, other_args): print("") except V20Error as e: + # pylint: disable=W0123 d_error = eval(e.msg) print(d_error["errorMessage"], "\n") @@ -386,6 +400,7 @@ def get_open_positions(accountID, other_args): print("") except V20Error as e: + # pylint: disable=W0123 d_error = eval(e.msg) print(d_error["errorMessage"], "\n") @@ -492,6 +507,7 @@ def close_trade(accountID, other_args: List[str]): print("") except V20Error as e: + # pylint: disable=W0123 d_error = eval(e.msg) print(d_error["errorMessage"], "\n") except Exception as e: @@ -599,6 +615,7 @@ def show_candles(accountID, instrument, other_args: List[str]): if gtff.USE_ION: plt.ion() + # pylint: disable=W0612 fig, ax = mpf.plot( df, type="candle", @@ -611,11 +628,13 @@ def show_candles(accountID, instrument, other_args: List[str]): ax[0].set_title(f"{instrument} {ns_parser.granularity}") ax[0].legend(legends) + # pylint: disable=C0200 for i in range(0, len(subplot_legends), 2): ax[subplot_legends[i]].legend(subplot_legends[i + 1]) print("") except V20Error as e: + # pylint: disable=W0123 d_error = eval(e.msg) print(d_error["errorMessage"], "\n") except TypeError as e: @@ -709,10 +728,11 @@ def calendar(instrument, other_args: List[str]): parameters = {"instrument": instrument, "period": str(ns_parser.days * 86400 * -1)} try: - request = labs.Calendar(params=parameters) + request = forexlabs.Calendar(params=parameters) response = client.request(request) l_data = [] + # pylint: disable=C0200 for i in range(len(response)): if "forecast" in response[i]: forecast = response[i]["forecast"] @@ -765,10 +785,13 @@ def calendar(instrument, other_args: List[str]): print("") except V20Error as e: + # pylint: disable=W0123 d_error = eval(e.msg) print(d_error["message"], "\n") +# pylint: disable=W0613 +# pylint: disable=R1710 def get_candles_dataframe(accountID, instrument, parameters): if not parameters: parameters = { @@ -797,10 +820,12 @@ def get_candles_dataframe(accountID, instrument, parameters): df.index = pd.to_datetime(df.index) return df except V20Error as e: + # pylint: disable=W0123 d_error = eval(e.msg) print(d_error["errorMessage"], "\n") +# pylint: disable=R1710 def load(other_args: List[str]): """Load a forex instrument to use""" parser = argparse.ArgumentParser( @@ -875,6 +900,7 @@ def book_plot(df, instrument, book_type): plt.show() +# pylint: disable=R1710 def format_instrument(instrument, char): try: if char not in instrument: diff --git a/gamestonk_terminal/menu.py b/gamestonk_terminal/menu.py index 7bb33f6d03b..646a47bb3eb 100644 --- a/gamestonk_terminal/menu.py +++ b/gamestonk_terminal/menu.py @@ -20,11 +20,11 @@ def inputhook(inputhook_context): history_file = os.path.join(os.path.expanduser("~"), ".gamestonk_terminal.his") try: - session = PromptSession(history=FileHistory(history_file)) + session = PromptSession(history=FileHistory(history_file)) # type: ignore set_eventloop_with_inputhook(inputhook) # pylint: disable=unused-variable except Exception as e: # noqa: F841 print( "WARNING: Prompt toolkit is turned on but did not initialize successfully. Falling back to input()..." ) - session = None + session = None # type: ignore diff --git a/gamestonk_terminal/portfolio/__init__.py b/gamestonk_terminal/portfolio/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/gamestonk_terminal/portfolio/brokers/degiro/__init__.py b/gamestonk_terminal/portfolio/brokers/degiro/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/gamestonk_terminal/portfolio/brokers/degiro/degiro_model.py b/gamestonk_terminal/portfolio/brokers/degiro/degiro_model.py index 154a9a67245..2fea6e6974a 100644 --- a/gamestonk_terminal/portfolio/brokers/degiro/degiro_model.py +++ b/gamestonk_terminal/portfolio/brokers/degiro/degiro_model.py @@ -5,7 +5,7 @@ from typing import Union # IMPORTATION THIRDPARTY import pandas as pd -import degiro_connector.trading.helpers.payload_handler as payload_handler +from degiro_connector.trading.helpers import payload_handler from degiro_connector.trading.api import API as TradingAPI from degiro_connector.trading.pb.trading_pb2 import ( diff --git a/gamestonk_terminal/portfolio/brokers/degiro/degiro_view.py b/gamestonk_terminal/portfolio/brokers/degiro/degiro_view.py index ec621cfa10c..0b40612c189 100644 --- a/gamestonk_terminal/portfolio/brokers/degiro/degiro_view.py +++ b/gamestonk_terminal/portfolio/brokers/degiro/degiro_view.py @@ -1,7 +1,7 @@ # IMPORTATION THIRDPARTY from argparse import Namespace import pandas as pd -import degiro_connector.trading.helpers.payload_handler as payload_handler +from degiro_connector.trading.helpers import payload_handler from degiro_connector.trading.pb.trading_pb2 import ( Credentials, diff --git a/gamestonk_terminal/resources/__init__.py b/gamestonk_terminal/resources/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/gamestonk_terminal/stocks/__init__.py b/gamestonk_terminal/stocks/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/gamestonk_terminal/stocks/fundamental_analysis/financial_modeling_prep/__init__.py b/gamestonk_terminal/stocks/fundamental_analysis/financial_modeling_prep/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/gamestonk_terminal/stocks/government/__init__.py b/gamestonk_terminal/stocks/government/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/gamestonk_terminal/stocks/insider/__init__.py b/gamestonk_terminal/stocks/insider/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/gamestonk_terminal/stocks/insider/presets/__init__.py b/gamestonk_terminal/stocks/insider/presets/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/gamestonk_terminal/stocks/research/__init__.py b/gamestonk_terminal/stocks/research/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/gamestonk_terminal/stocks/residuals_analysis/__init__.py b/gamestonk_terminal/stocks/residuals_analysis/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/gamestonk_terminal/stocks/screener/__init__.py b/gamestonk_terminal/stocks/screener/__init__.py new file mode 100644 index 00000000000..e69de29bb2d