From 3fb1dd02f1204996da2c5cfc326cd719b64839a0 Mon Sep 17 00:00:00 2001 From: xmatthias Date: Thu, 31 May 2018 22:00:46 +0200 Subject: [PATCH] add typehints and type: ignores --- freqtrade/analyze.py | 6 +++--- freqtrade/exchange/__init__.py | 2 +- freqtrade/optimize/hyperopt.py | 8 ++++---- freqtrade/strategy/resolver.py | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/freqtrade/analyze.py b/freqtrade/analyze.py index 5756b845c..6334fd846 100644 --- a/freqtrade/analyze.py +++ b/freqtrade/analyze.py @@ -95,7 +95,7 @@ class Analyze(object): Return ticker interval to use :return: Ticker interval value to use """ - return self.strategy.ticker_interval + return self.strategy.ticker_interval # type: ignore def analyze_ticker(self, ticker_history: List[Dict]) -> DataFrame: """ @@ -195,13 +195,13 @@ class Analyze(object): :return True if bot should sell at current rate """ current_profit = trade.calc_profit_percent(current_rate) - if self.strategy.stoploss is not None and current_profit < self.strategy.stoploss: + if self.strategy.stoploss is not None and current_profit < self.strategy.stoploss: # type: ignore logger.debug('Stop loss hit.') return True # Check if time matches and current rate is above threshold time_diff = (current_time.timestamp() - trade.open_date.timestamp()) / 60 - for duration, threshold in self.strategy.minimal_roi.items(): + for duration, threshold in self.strategy.minimal_roi.items(): # type: ignore if time_diff <= duration: return False if current_profit > threshold: diff --git a/freqtrade/exchange/__init__.py b/freqtrade/exchange/__init__.py index 109e3f7b2..b186f3611 100644 --- a/freqtrade/exchange/__init__.py +++ b/freqtrade/exchange/__init__.py @@ -290,7 +290,7 @@ def get_ticker_history(pair: str, tick_interval: str, since_ms: Optional[int] = # chached data was already downloaded till_time_ms = min(till_time_ms, arrow.utcnow().shift(minutes=-10).timestamp * 1000) - data = [] + data: List[Dict[Any, Any]] = [] while not since_ms or since_ms < till_time_ms: data_part = _API.fetch_ohlcv(pair, timeframe=tick_interval, since=since_ms) diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index 20fa5380d..b4f534d7c 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -14,7 +14,7 @@ from argparse import Namespace from functools import reduce from math import exp from operator import itemgetter -from typing import Dict, Any, Callable +from typing import Dict, Any, Callable, Optional import numpy import talib.abstract as ta @@ -60,7 +60,7 @@ class Hyperopt(Backtesting): self.expected_max_profit = 3.0 # Configuration and data used by hyperopt - self.processed = None + self.processed: Optional[Dict[str, Any]] = None # Hyperopt Trials self.trials_file = os.path.join('user_data', 'hyperopt_trials.pickle') @@ -344,7 +344,7 @@ class Hyperopt(Backtesting): """ Return the space to use during Hyperopt """ - spaces = {} + spaces: Dict = {} if self.has_space('buy'): spaces = {**spaces, **Hyperopt.indicator_space()} if self.has_space('roi'): @@ -503,7 +503,7 @@ class Hyperopt(Backtesting): ) if self.has_space('buy'): - self.analyze.populate_indicators = Hyperopt.populate_indicators + self.analyze.populate_indicators = Hyperopt.populate_indicators # type: ignore self.processed = self.tickerdata_to_dataframe(data) if self.config.get('mongodb'): diff --git a/freqtrade/strategy/resolver.py b/freqtrade/strategy/resolver.py index 23380dad9..28465210c 100644 --- a/freqtrade/strategy/resolver.py +++ b/freqtrade/strategy/resolver.py @@ -101,7 +101,7 @@ class StrategyResolver(object): # Generate spec based on absolute path spec = importlib.util.spec_from_file_location('user_data.strategies', module_path) module = importlib.util.module_from_spec(spec) - spec.loader.exec_module(module) + spec.loader.exec_module(module) # type: ignore valid_strategies_gen = ( obj for name, obj in inspect.getmembers(module, inspect.isclass)