diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7924e595..f470170a 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: v4.0.1 + rev: v4.1.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -11,10 +11,16 @@ repos: hooks: - id: flake8 - repo: https://github.com/PyCQA/isort - rev: 5.9.3 + rev: 5.10.1 hooks: - id: isort + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.931 + hooks: + - id: mypy + additional_dependencies: [types-requests, types-setuptools] + exclude: tests - repo: https://github.com/pycqa/pylint - rev: v2.11.1 + rev: v2.12.2 hooks: - id: pylint diff --git a/algobot/helpers.py b/algobot/helpers.py index c15b0d41..3fbb168c 100644 --- a/algobot/helpers.py +++ b/algobot/helpers.py @@ -176,7 +176,7 @@ def open_file_or_folder(target_path: str): """ # pylint: disable=consider-using-with, no-member if platform.system() == "Windows": - os.startfile(target_path) + os.startfile(target_path) # type: ignore elif platform.system() == "Darwin": subprocess.Popen(["open", target_path]) else: @@ -249,8 +249,8 @@ def get_ups_and_downs(data: List[Dict[str, float]], parameter: str) -> Tuple[lis :param parameter: Parameter from which data is retrieved. :return: Tuple of list of ups and downs. """ - ups = [0] - downs = [0] + ups: List[float] = [0] + downs: List[float] = [0] previous = data[0] for period in data[1:]: diff --git a/algobot/interface/configuration_helpers.py b/algobot/interface/configuration_helpers.py index 7b411073..23f3a36d 100644 --- a/algobot/interface/configuration_helpers.py +++ b/algobot/interface/configuration_helpers.py @@ -134,7 +134,7 @@ def get_h_line() -> QFrame: return line -def get_default_widget(widget: [QSpinBox, QDoubleSpinBox], default: Union[int, float], minimum: Optional[int] = 0, +def get_default_widget(widget: Union[QSpinBox, QDoubleSpinBox], default: Union[int, float], minimum: Optional[int] = 0, maximum: Optional[int] = 999) -> Union[QSpinBox, QDoubleSpinBox]: """ Returns a default QSpinbox or QDoubleSpinbox widget with default, minimum, and maximum values provided. diff --git a/algobot/strategies/__init__.py b/algobot/strategies/__init__.py index fbc225c6..669520ea 100644 --- a/algobot/strategies/__init__.py +++ b/algobot/strategies/__init__.py @@ -1,11 +1,10 @@ """ Initialization of all strategies. """ -from collections import namedtuple from dataclasses import dataclass from os import listdir from os.path import basename, dirname -from typing import Any, Callable, List, Type +from typing import Any, Callable, List, NamedTuple, Type import talib @@ -33,7 +32,7 @@ class TALIBEntry: """ Entry class for TALIB Map defined below. """ - def __init__(self, name: str, stream: Callable, talib_func: Callable, args: List[namedtuple]): + def __init__(self, name: str, stream: Callable, talib_func: Callable, args: List[NamedTuple]): self.name = name self.stream = stream self.talib = talib_func diff --git a/algobot/traders/trader.py b/algobot/traders/trader.py index dc27f9b9..2d6e9ecc 100644 --- a/algobot/traders/trader.py +++ b/algobot/traders/trader.py @@ -3,7 +3,7 @@ """ from datetime import datetime -from typing import Any, Dict, List, Union +from typing import Any, Dict, List, Optional, Union from algobot.enums import BEARISH, BULLISH, ENTER_LONG, ENTER_SHORT, EXIT_LONG, EXIT_SHORT, LONG, SHORT, STOP, TRAILING from algobot.helpers import get_label_string @@ -31,7 +31,7 @@ def __init__(self, symbol, precision, starting_balance, margin_enabled: bool = T self.starting_time = datetime.utcnow() # Starting time in UTC. self.ending_time = None # Ending time for previous bot run. self.current_period = None # Current time period the bot is in used for backtesting. - self.current_position = None # Current position value. + self.current_position: Optional[str] = None # Current position value. self.min_period = 0 # Minimum amount of periods required for trend retrieval. self.previous_position = None # Previous position to validate for a new trend. self.trend = None # Current trend information. @@ -39,15 +39,15 @@ def __init__(self, symbol, precision, starting_balance, margin_enabled: bool = T self.take_profit_point = None # Price at which bot will exit trade to secure profits. self.trailing_take_profit_activated = False # Boolean that'll turn true if a stop order is activated. - self.take_profit_type = None # Type of take profit: trailing or stop. - self.take_profit_percentage_decimal = None # Percentage of profit to exit trade at. + self.take_profit_type: Optional[int] = None # Type of take profit: trailing or stop. + self.take_profit_percentage_decimal: Optional[float] = None # Percentage of profit to exit trade at. # Prices information. - self.current_price = None # Current price of coin. - self.buy_long_price = None # Price we last bought our target coin at in long position. - self.sell_short_price = None # Price we last sold target coin at in short position. - self.long_trailing_price = None # Price coin has to be above for long position. - self.short_trailing_price = None # Price coin has to be below for short position. + self.current_price: Optional[float] = None # Current price of coin. + self.buy_long_price: Optional[float] = None # Price we last bought our target coin at in long position. + self.sell_short_price: Optional[float] = None # Price we last sold target coin at in short position. + self.long_trailing_price: Optional[float] = None # Price coin has to be above for long position. + self.short_trailing_price: Optional[float] = None # Price coin has to be below for short position. # Stop loss information. self.smart_stop_loss_initial_counter = 0 # Smart stop loss initial counter. @@ -58,7 +58,8 @@ def __init__(self, symbol, precision, starting_balance, margin_enabled: bool = T self.stop_loss = None # Price at which bot will exit trade due to stop loss limits. self.stop_loss_exit = False # Boolean that'll determine whether last position was exited from a stop loss. self.loss_percentage_decimal = None # Loss percentage in decimal for stop loss. - self.loss_strategy = None # Type of loss type we are using: whether it's trailing loss or stop loss. + # Type of loss type we are using: whether it's trailing loss or stop loss. + self.loss_strategy: Optional[str] = None self.safety_timer = None # Timer to check if there's a true trend towards stop loss. self.scheduled_safety_timer = None # Next time to check if it's a true stop loss. @@ -370,7 +371,7 @@ def get_safe_rounded_percentage(self, decimal_value: float) -> str: """ return self.get_safe_rounded_string(decimal_value, direction='right', multiplier=100, symbol='%') - def get_safe_rounded_string(self, value: float, + def get_safe_rounded_string(self, value: Optional[float], round_digits: int = None, symbol: str = '$', direction: str = 'left',