Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mypy support #156

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
6 changes: 3 additions & 3 deletions algobot/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:]:
Expand Down
2 changes: 1 addition & 1 deletion algobot/interface/configuration_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions algobot/strategies/__init__.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down
23 changes: 12 additions & 11 deletions algobot/traders/trader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -31,23 +31,23 @@ 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.
self.margin_enabled = margin_enabled # Boolean for whether margin trading is enabled or not.

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.
Expand All @@ -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.

Expand Down Expand Up @@ -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',
Expand Down