Flake8 compatibility

This commit is contained in:
Reigo Reinmets 2021-12-18 11:00:25 +02:00
parent cc28f73d7f
commit 30673f84f9
5 changed files with 22 additions and 33 deletions

View File

@ -351,11 +351,13 @@ class Backtesting:
else:
return sell_row[OPEN_IDX]
def _get_adjust_trade_entry_for_candle(self, trade: LocalTrade, row: Tuple) -> Optional[LocalTrade]:
def _get_adjust_trade_entry_for_candle(self, trade: LocalTrade, row: Tuple
) -> Optional[LocalTrade]:
current_profit = trade.calc_profit_ratio(row[OPEN_IDX])
stake_amount = strategy_safe_wrapper(self.strategy.adjust_trade_position, default_retval=None)(
stake_amount = strategy_safe_wrapper(self.strategy.adjust_trade_position,
default_retval=None)(
pair=trade.pair, trade=trade, current_time=row[DATE_IDX].to_pydatetime(),
current_rate=row[OPEN_IDX], current_profit=current_profit)
@ -372,11 +374,15 @@ class Backtesting:
available_amount = self.wallets.get_available_stake_amount()
try:
min_stake_amount = self.exchange.get_min_pair_stake_amount(trade.pair, propose_rate, -0.05) or 0
stake_amount = self.wallets.validate_stake_amount(trade.pair, stake_amount, min_stake_amount)
stake_amount = self.wallets._check_available_stake_amount(stake_amount, available_amount)
min_stake_amount = self.exchange.get_min_pair_stake_amount(
trade.pair, propose_rate, -0.05) or 0
stake_amount = self.wallets.validate_stake_amount(trade.pair,
stake_amount, min_stake_amount)
stake_amount = self.wallets._check_available_stake_amount(stake_amount,
available_amount)
except DependencyException:
logger.debug(f"{trade.pair} adjustment failed, wallet is smaller than asked stake {stake_amount}")
logger.debug(f"{trade.pair} adjustment failed, "
f"wallet is smaller than asked stake {stake_amount}")
return trade
amount = stake_amount / current_price
@ -399,7 +405,7 @@ class Backtesting:
)
trade.orders.append(buy_order)
trade.recalc_trade_from_orders()
self.wallets.update();
self.wallets.update()
return trade
def _get_sell_trade_entry_for_candle(self, trade: LocalTrade,

View File

@ -381,10 +381,9 @@ class IStrategy(ABC, HyperStrategyMixin):
"""
return proposed_stake
def adjust_trade_position(self, pair: str, trade: Trade,
current_time: datetime, current_rate: float, current_profit: float,
**kwargs) -> Optional[float]:
def adjust_trade_position(self, pair: str, trade: Trade, current_time: datetime,
current_rate: float, current_profit: float, **kwargs
) -> Optional[float]:
"""
Custom trade adjustment logic, returning the stake amount that a trade should be increased.
This means extra buy orders with additional fees.

View File

@ -1,30 +1,15 @@
# pragma pylint: disable=missing-docstring, W0212, line-too-long, C0103, unused-argument
import random
from datetime import datetime, timedelta, timezone
from pathlib import Path
from unittest.mock import MagicMock, PropertyMock
import logging
import numpy as np
import pandas as pd
import pytest
from arrow import Arrow
from freqtrade.commands.optimize_commands import setup_optimize_configuration, start_backtesting
from freqtrade.configuration import TimeRange
from freqtrade.data import history
from freqtrade.data.btanalysis import BT_DATA_COLUMNS, evaluate_result_multi
from freqtrade.data.converter import clean_ohlcv_dataframe
from freqtrade.data.dataprovider import DataProvider
from freqtrade.data.history import get_timerange
from freqtrade.enums import RunMode, SellType
from freqtrade.exceptions import DependencyException, OperationalException
from freqtrade.enums import SellType
from freqtrade.optimize.backtesting import Backtesting
from freqtrade.persistence import LocalTrade
from freqtrade.resolvers import StrategyResolver
from tests.conftest import (get_args, log_has, log_has_re, patch_exchange,
patched_configuration_load_config_file)
from tests.conftest import (patch_exchange)
def test_backtest_position_adjustment(default_conf, fee, mocker, testdatadir) -> None:
default_conf['use_sell_signal'] = False

View File

@ -8,6 +8,7 @@ from freqtrade.strategy.interface import IStrategy
from freqtrade.persistence import Trade
from datetime import datetime
class StrategyTestV2(IStrategy):
"""
Strategy used by tests freqtrade bot.
@ -163,7 +164,7 @@ class StrategyTestV2(IStrategy):
for order in trade.orders:
if order.ft_is_open:
return None
return self.wallets.get_trade_stake_amount(pair, None)
return None

View File

@ -1506,6 +1506,7 @@ def test_recalc_trade_from_orders(fee):
assert pytest.approx(trade.fee_open_cost) == o1_fee_cost + o2_fee_cost + o3_fee_cost
assert pytest.approx(trade.open_trade_value) == o1_trade_val + o2_trade_val + o3_trade_val
def test_recalc_trade_from_orders_ignores_bad_orders(fee):
o1_amount = 100
@ -1631,6 +1632,3 @@ def test_recalc_trade_from_orders_ignores_bad_orders(fee):
assert trade.open_rate == o1_rate
assert trade.fee_open_cost == o1_fee_cost
assert trade.open_trade_value == o1_trade_val