mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-11-29 08:33:07 +00:00
chore: update tests to modern typing syntax
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
from copy import deepcopy
|
||||
from pathlib import Path
|
||||
from typing import Tuple
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -10,8 +9,8 @@ from freqtrade.resolvers.exchange_resolver import ExchangeResolver
|
||||
from tests.conftest import EXMS, get_default_conf_usdt
|
||||
|
||||
|
||||
EXCHANGE_FIXTURE_TYPE = Tuple[Exchange, str]
|
||||
EXCHANGE_WS_FIXTURE_TYPE = Tuple[Exchange, str, str]
|
||||
EXCHANGE_FIXTURE_TYPE = tuple[Exchange, str]
|
||||
EXCHANGE_WS_FIXTURE_TYPE = tuple[Exchange, str, str]
|
||||
|
||||
|
||||
# Exchanges that should be tested online
|
||||
|
||||
@@ -2,7 +2,7 @@ import platform
|
||||
import sys
|
||||
from copy import deepcopy
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
@@ -112,7 +112,7 @@ def make_rl_config(conf):
|
||||
return conf
|
||||
|
||||
|
||||
def mock_pytorch_mlp_model_training_parameters() -> Dict[str, Any]:
|
||||
def mock_pytorch_mlp_model_training_parameters() -> dict[str, Any]:
|
||||
return {
|
||||
"learning_rate": 3e-4,
|
||||
"trainer_kwargs": {
|
||||
|
||||
@@ -5,7 +5,6 @@ import logging
|
||||
import time
|
||||
from copy import deepcopy
|
||||
from datetime import timedelta
|
||||
from typing import List
|
||||
from unittest.mock import ANY, MagicMock, PropertyMock, patch
|
||||
|
||||
import pytest
|
||||
@@ -5442,7 +5441,7 @@ def test_position_adjust(mocker, default_conf_usdt, fee) -> None:
|
||||
assert trade.amount == 10
|
||||
assert trade.stake_amount == 110
|
||||
assert not trade.fee_updated("buy")
|
||||
trades: List[Trade] = Trade.get_open_trades_without_assigned_fees()
|
||||
trades: list[Trade] = Trade.get_open_trades_without_assigned_fees()
|
||||
assert len(trades) == 1
|
||||
assert trade.is_open
|
||||
assert not trade.fee_updated("buy")
|
||||
@@ -5468,7 +5467,7 @@ def test_position_adjust(mocker, default_conf_usdt, fee) -> None:
|
||||
assert orders
|
||||
assert len(orders) == 2
|
||||
# Assert that the trade is found as open and without fees
|
||||
trades: List[Trade] = Trade.get_open_trades_without_assigned_fees()
|
||||
trades: list[Trade] = Trade.get_open_trades_without_assigned_fees()
|
||||
assert len(trades) == 1
|
||||
# Assert trade is as expected
|
||||
trade = Trade.session.scalars(select(Trade)).first()
|
||||
@@ -5525,7 +5524,7 @@ def test_position_adjust(mocker, default_conf_usdt, fee) -> None:
|
||||
assert order.order_id == "651"
|
||||
|
||||
# Assert that the trade is not found as open and without fees
|
||||
trades: List[Trade] = Trade.get_open_trades_without_assigned_fees()
|
||||
trades: list[Trade] = Trade.get_open_trades_without_assigned_fees()
|
||||
assert len(trades) == 1
|
||||
|
||||
# Add a second DCA
|
||||
@@ -5725,7 +5724,7 @@ def test_position_adjust2(mocker, default_conf_usdt, fee) -> None:
|
||||
exit_check=ExitCheckTuple(exit_type=ExitType.PARTIAL_EXIT),
|
||||
sub_trade_amt=amount,
|
||||
)
|
||||
trades: List[Trade] = trade.get_open_trades_without_assigned_fees()
|
||||
trades: list[Trade] = trade.get_open_trades_without_assigned_fees()
|
||||
assert len(trades) == 1
|
||||
# Assert trade is as expected (averaged dca)
|
||||
|
||||
|
||||
@@ -29,10 +29,10 @@ class BTContainer(NamedTuple):
|
||||
Minimal BacktestContainer defining Backtest inputs and results.
|
||||
"""
|
||||
|
||||
data: List[List[float]]
|
||||
data: list[list[float]]
|
||||
stop_loss: float
|
||||
roi: Dict[str, float]
|
||||
trades: List[BTrade]
|
||||
roi: dict[str, float]
|
||||
trades: list[BTrade]
|
||||
profit_perc: float
|
||||
trailing_stop: bool = False
|
||||
trailing_only_offset_is_reached: bool = False
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import logging
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import Dict, List
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
@@ -14,7 +13,7 @@ from tests.conftest import CURRENT_TEST_STRATEGY, log_has, log_has_re
|
||||
|
||||
|
||||
# Functions for recurrent object patching
|
||||
def create_results() -> List[Dict]:
|
||||
def create_results() -> list[dict]:
|
||||
return [{"loss": 1, "result": "foo", "params": {}, "is_best": True}]
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import logging
|
||||
from functools import reduce
|
||||
from typing import Dict
|
||||
|
||||
import talib.abstract as ta
|
||||
from pandas import DataFrame
|
||||
@@ -26,19 +25,19 @@ class freqai_rl_test_strat(IStrategy):
|
||||
can_short = False
|
||||
|
||||
def feature_engineering_expand_all(
|
||||
self, dataframe: DataFrame, period: int, metadata: Dict, **kwargs
|
||||
self, dataframe: DataFrame, period: int, metadata: dict, **kwargs
|
||||
):
|
||||
dataframe["%-rsi-period"] = ta.RSI(dataframe, timeperiod=period)
|
||||
|
||||
return dataframe
|
||||
|
||||
def feature_engineering_expand_basic(self, dataframe: DataFrame, metadata: Dict, **kwargs):
|
||||
def feature_engineering_expand_basic(self, dataframe: DataFrame, metadata: dict, **kwargs):
|
||||
dataframe["%-pct-change"] = dataframe["close"].pct_change()
|
||||
dataframe["%-raw_volume"] = dataframe["volume"]
|
||||
|
||||
return dataframe
|
||||
|
||||
def feature_engineering_standard(self, dataframe: DataFrame, metadata: Dict, **kwargs):
|
||||
def feature_engineering_standard(self, dataframe: DataFrame, metadata: dict, **kwargs):
|
||||
dataframe["%-day_of_week"] = dataframe["date"].dt.dayofweek
|
||||
dataframe["%-hour_of_day"] = dataframe["date"].dt.hour
|
||||
|
||||
@@ -49,7 +48,7 @@ class freqai_rl_test_strat(IStrategy):
|
||||
|
||||
return dataframe
|
||||
|
||||
def set_freqai_targets(self, dataframe: DataFrame, metadata: Dict, **kwargs):
|
||||
def set_freqai_targets(self, dataframe: DataFrame, metadata: dict, **kwargs):
|
||||
dataframe["&-action"] = 0
|
||||
|
||||
return dataframe
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import logging
|
||||
from functools import reduce
|
||||
from typing import Dict
|
||||
|
||||
import numpy as np
|
||||
import talib.abstract as ta
|
||||
@@ -58,7 +57,7 @@ class freqai_test_classifier(IStrategy):
|
||||
return informative_pairs
|
||||
|
||||
def feature_engineering_expand_all(
|
||||
self, dataframe: DataFrame, period: int, metadata: Dict, **kwargs
|
||||
self, dataframe: DataFrame, period: int, metadata: dict, **kwargs
|
||||
):
|
||||
dataframe["%-rsi-period"] = ta.RSI(dataframe, timeperiod=period)
|
||||
dataframe["%-mfi-period"] = ta.MFI(dataframe, timeperiod=period)
|
||||
@@ -66,20 +65,20 @@ class freqai_test_classifier(IStrategy):
|
||||
|
||||
return dataframe
|
||||
|
||||
def feature_engineering_expand_basic(self, dataframe: DataFrame, metadata: Dict, **kwargs):
|
||||
def feature_engineering_expand_basic(self, dataframe: DataFrame, metadata: dict, **kwargs):
|
||||
dataframe["%-pct-change"] = dataframe["close"].pct_change()
|
||||
dataframe["%-raw_volume"] = dataframe["volume"]
|
||||
dataframe["%-raw_price"] = dataframe["close"]
|
||||
|
||||
return dataframe
|
||||
|
||||
def feature_engineering_standard(self, dataframe: DataFrame, metadata: Dict, **kwargs):
|
||||
def feature_engineering_standard(self, dataframe: DataFrame, metadata: dict, **kwargs):
|
||||
dataframe["%-day_of_week"] = dataframe["date"].dt.dayofweek
|
||||
dataframe["%-hour_of_day"] = dataframe["date"].dt.hour
|
||||
|
||||
return dataframe
|
||||
|
||||
def set_freqai_targets(self, dataframe: DataFrame, metadata: Dict, **kwargs):
|
||||
def set_freqai_targets(self, dataframe: DataFrame, metadata: dict, **kwargs):
|
||||
self.freqai.class_names = ["down", "up"]
|
||||
dataframe["&s-up_or_down"] = np.where(
|
||||
dataframe["close"].shift(-100) > dataframe["close"], "up", "down"
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import logging
|
||||
from functools import reduce
|
||||
from typing import Dict
|
||||
|
||||
import numpy as np
|
||||
import talib.abstract as ta
|
||||
@@ -45,7 +44,7 @@ class freqai_test_multimodel_classifier_strat(IStrategy):
|
||||
max_roi_time_long = IntParameter(0, 800, default=400, space="sell", optimize=False, load=True)
|
||||
|
||||
def feature_engineering_expand_all(
|
||||
self, dataframe: DataFrame, period: int, metadata: Dict, **kwargs
|
||||
self, dataframe: DataFrame, period: int, metadata: dict, **kwargs
|
||||
):
|
||||
dataframe["%-rsi-period"] = ta.RSI(dataframe, timeperiod=period)
|
||||
dataframe["%-mfi-period"] = ta.MFI(dataframe, timeperiod=period)
|
||||
@@ -53,20 +52,20 @@ class freqai_test_multimodel_classifier_strat(IStrategy):
|
||||
|
||||
return dataframe
|
||||
|
||||
def feature_engineering_expand_basic(self, dataframe: DataFrame, metadata: Dict, **kwargs):
|
||||
def feature_engineering_expand_basic(self, dataframe: DataFrame, metadata: dict, **kwargs):
|
||||
dataframe["%-pct-change"] = dataframe["close"].pct_change()
|
||||
dataframe["%-raw_volume"] = dataframe["volume"]
|
||||
dataframe["%-raw_price"] = dataframe["close"]
|
||||
|
||||
return dataframe
|
||||
|
||||
def feature_engineering_standard(self, dataframe: DataFrame, metadata: Dict, **kwargs):
|
||||
def feature_engineering_standard(self, dataframe: DataFrame, metadata: dict, **kwargs):
|
||||
dataframe["%-day_of_week"] = dataframe["date"].dt.dayofweek
|
||||
dataframe["%-hour_of_day"] = dataframe["date"].dt.hour
|
||||
|
||||
return dataframe
|
||||
|
||||
def set_freqai_targets(self, dataframe: DataFrame, metadata: Dict, **kwargs):
|
||||
def set_freqai_targets(self, dataframe: DataFrame, metadata: dict, **kwargs):
|
||||
dataframe["&s-up_or_down"] = np.where(
|
||||
dataframe["close"].shift(-50) > dataframe["close"], "up", "down"
|
||||
)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import logging
|
||||
from functools import reduce
|
||||
from typing import Dict
|
||||
|
||||
import talib.abstract as ta
|
||||
from pandas import DataFrame
|
||||
@@ -44,7 +43,7 @@ class freqai_test_multimodel_strat(IStrategy):
|
||||
max_roi_time_long = IntParameter(0, 800, default=400, space="sell", optimize=False, load=True)
|
||||
|
||||
def feature_engineering_expand_all(
|
||||
self, dataframe: DataFrame, period: int, metadata: Dict, **kwargs
|
||||
self, dataframe: DataFrame, period: int, metadata: dict, **kwargs
|
||||
):
|
||||
dataframe["%-rsi-period"] = ta.RSI(dataframe, timeperiod=period)
|
||||
dataframe["%-mfi-period"] = ta.MFI(dataframe, timeperiod=period)
|
||||
@@ -52,20 +51,20 @@ class freqai_test_multimodel_strat(IStrategy):
|
||||
|
||||
return dataframe
|
||||
|
||||
def feature_engineering_expand_basic(self, dataframe: DataFrame, metadata: Dict, **kwargs):
|
||||
def feature_engineering_expand_basic(self, dataframe: DataFrame, metadata: dict, **kwargs):
|
||||
dataframe["%-pct-change"] = dataframe["close"].pct_change()
|
||||
dataframe["%-raw_volume"] = dataframe["volume"]
|
||||
dataframe["%-raw_price"] = dataframe["close"]
|
||||
|
||||
return dataframe
|
||||
|
||||
def feature_engineering_standard(self, dataframe: DataFrame, metadata: Dict, **kwargs):
|
||||
def feature_engineering_standard(self, dataframe: DataFrame, metadata: dict, **kwargs):
|
||||
dataframe["%-day_of_week"] = dataframe["date"].dt.dayofweek
|
||||
dataframe["%-hour_of_day"] = dataframe["date"].dt.hour
|
||||
|
||||
return dataframe
|
||||
|
||||
def set_freqai_targets(self, dataframe: DataFrame, metadata: Dict, **kwargs):
|
||||
def set_freqai_targets(self, dataframe: DataFrame, metadata: dict, **kwargs):
|
||||
dataframe["&-s_close"] = (
|
||||
dataframe["close"]
|
||||
.shift(-self.freqai_info["feature_parameters"]["label_period_candles"])
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import logging
|
||||
from functools import reduce
|
||||
from typing import Dict
|
||||
|
||||
import talib.abstract as ta
|
||||
from pandas import DataFrame
|
||||
@@ -44,7 +43,7 @@ class freqai_test_strat(IStrategy):
|
||||
max_roi_time_long = IntParameter(0, 800, default=400, space="sell", optimize=False, load=True)
|
||||
|
||||
def feature_engineering_expand_all(
|
||||
self, dataframe: DataFrame, period: int, metadata: Dict, **kwargs
|
||||
self, dataframe: DataFrame, period: int, metadata: dict, **kwargs
|
||||
):
|
||||
dataframe["%-rsi-period"] = ta.RSI(dataframe, timeperiod=period)
|
||||
dataframe["%-mfi-period"] = ta.MFI(dataframe, timeperiod=period)
|
||||
@@ -52,20 +51,20 @@ class freqai_test_strat(IStrategy):
|
||||
|
||||
return dataframe
|
||||
|
||||
def feature_engineering_expand_basic(self, dataframe: DataFrame, metadata: Dict, **kwargs):
|
||||
def feature_engineering_expand_basic(self, dataframe: DataFrame, metadata: dict, **kwargs):
|
||||
dataframe["%-pct-change"] = dataframe["close"].pct_change()
|
||||
dataframe["%-raw_volume"] = dataframe["volume"]
|
||||
dataframe["%-raw_price"] = dataframe["close"]
|
||||
|
||||
return dataframe
|
||||
|
||||
def feature_engineering_standard(self, dataframe: DataFrame, metadata: Dict, **kwargs):
|
||||
def feature_engineering_standard(self, dataframe: DataFrame, metadata: dict, **kwargs):
|
||||
dataframe["%-day_of_week"] = dataframe["date"].dt.dayofweek
|
||||
dataframe["%-hour_of_day"] = dataframe["date"].dt.hour
|
||||
|
||||
return dataframe
|
||||
|
||||
def set_freqai_targets(self, dataframe: DataFrame, metadata: Dict, **kwargs):
|
||||
def set_freqai_targets(self, dataframe: DataFrame, metadata: dict, **kwargs):
|
||||
dataframe["&-s_close"] = (
|
||||
dataframe["close"]
|
||||
.shift(-self.freqai_info["feature_parameters"]["label_period_candles"])
|
||||
|
||||
Reference in New Issue
Block a user