Skip to content

Commit 8916ca5

Browse files
committed
Formatting.
1 parent 3cb97b0 commit 8916ca5

File tree

2 files changed

+93
-100
lines changed

2 files changed

+93
-100
lines changed

NostalgiaForInfinityX5.py

+15-17
Original file line numberDiff line numberDiff line change
@@ -641,23 +641,6 @@ def __init__(self, config: dict) -> None:
641641

642642
self.update_signals_from_config(self.config)
643643

644-
645-
# Get Ticker Indicator
646-
# ---------------------------------------------------------------------------------------------
647-
def update_signals_from_config(self, config):
648-
# Update long entry signal parameters (if they exist in the config)
649-
if hasattr(self, "long_entry_signal_params") and "long_entry_signal_params" in config:
650-
for condition_key in self.long_entry_signal_params:
651-
if condition_key in config['long_entry_signal_params']:
652-
self.long_entry_signal_params[condition_key] = config['long_entry_signal_params'][condition_key]
653-
654-
# Update short entry signal parameters (if they exist in the config)
655-
if hasattr(self, "short_entry_signal_params") and "short_entry_signal_params" in config:
656-
for condition_key in self.short_entry_signal_params:
657-
if condition_key in config['short_entry_signal_params']:
658-
self.short_entry_signal_params[condition_key] = config['short_entry_signal_params'][condition_key]
659-
660-
661644
# Get Ticker Indicator
662645
# ---------------------------------------------------------------------------------------------
663646
def get_ticker_indicator(self):
@@ -6204,6 +6187,21 @@ def has_valid_entry_conditions(self, trade: Trade, exit_rate: float, last_candle
62046187
return last_candle["enter_short"] or self.short_grind_entry(last_candle, previous_candle, slice_profit, False)
62056188
return False
62066189

6190+
# Update signals (enable/disable) from config
6191+
# ---------------------------------------------------------------------------------------------
6192+
def update_signals_from_config(self, config):
6193+
# Update long entry signal parameters (if they exist in the config)
6194+
if hasattr(self, "long_entry_signal_params") and "long_entry_signal_params" in config:
6195+
for condition_key in self.long_entry_signal_params:
6196+
if condition_key in config["long_entry_signal_params"]:
6197+
self.long_entry_signal_params[condition_key] = config["long_entry_signal_params"][condition_key]
6198+
6199+
# Update short entry signal parameters (if they exist in the config)
6200+
if hasattr(self, "short_entry_signal_params") and "short_entry_signal_params" in config:
6201+
for condition_key in self.short_entry_signal_params:
6202+
if condition_key in config["short_entry_signal_params"]:
6203+
self.short_entry_signal_params[condition_key] = config["short_entry_signal_params"][condition_key]
6204+
62076205
# Set Profit Target
62086206
# ---------------------------------------------------------------------------------------------
62096207
def _set_profit_target(

tests/unit/test_NFIX5.py

+78-83
Original file line numberDiff line numberDiff line change
@@ -3,94 +3,89 @@
33
from NostalgiaForInfinityX5 import NostalgiaForInfinityX5
44
from pathlib import Path
55

6+
67
@pytest.fixture
78
def mock_config(tmp_path):
8-
class RunModeMock:
9-
def __init__(self, value):
10-
self.value = value
9+
class RunModeMock:
10+
def __init__(self, value):
11+
self.value = value
12+
13+
return {
14+
"exchange": {
15+
"name": "binance",
16+
"ccxt_config": {
17+
"apiKey": "dummy_key",
18+
"secret": "dummy_secret",
19+
"password": None,
20+
},
21+
"pair_whitelist": ["BTC/USDT"],
22+
"pair_blacklist": [],
23+
},
24+
"stake_currency": "USDT",
25+
"stake_amount": 10,
26+
"dry_run": True,
27+
"timeframe": "5m",
28+
"max_open_trades": 5,
29+
"user_data_dir": tmp_path, # Use pytest's temporary directory
30+
"runmode": RunModeMock("backtest"), # Simulate the execution mode
31+
}
1132

12-
return {
13-
"exchange": {
14-
"name": "binance",
15-
"ccxt_config": {
16-
"apiKey": "dummy_key",
17-
"secret": "dummy_secret",
18-
"password": None,
19-
},
20-
"pair_whitelist": ["BTC/USDT"],
21-
"pair_blacklist": [],
22-
},
23-
"stake_currency": "USDT",
24-
"stake_amount": 10,
25-
"dry_run": True,
26-
"timeframe": "5m",
27-
"max_open_trades": 5,
28-
"user_data_dir": tmp_path, # Use pytest's temporary directory
29-
"runmode": RunModeMock("backtest"), # Simulate the execution mode
30-
}
3133

3234
def test_update_signals_from_config(mock_config):
33-
"""Test that the update_signals_from_config function correctly updates signals"""
34-
strategy = NostalgiaForInfinityX5(mock_config) # mock_config is injected by pytest
35+
"""Test that the update_signals_from_config function correctly updates signals"""
36+
strategy = NostalgiaForInfinityX5(mock_config) # mock_config is injected by pytest
37+
38+
# Test setup with actual signals
39+
test_config = {
40+
"long_entry_signal_params": {
41+
"long_entry_condition_1_enable": False,
42+
"long_entry_condition_2_enable": True,
43+
"long_entry_condition_3_enable": False,
44+
"long_entry_condition_4_enable": True,
45+
"long_entry_condition_5_enable": False,
46+
"long_entry_condition_6_enable": True,
47+
"long_entry_condition_41_enable": False,
48+
"long_entry_condition_42_enable": True,
49+
"long_entry_condition_43_enable": False,
50+
"long_entry_condition_120_enable": True,
51+
"long_entry_condition_141_enable": False,
52+
"long_entry_condition_142_enable": True,
53+
"long_entry_condition_143_enable": False,
54+
},
55+
"short_entry_signal_params": {"short_entry_condition_501_enable": False},
56+
}
3557

36-
# Test setup with actual signals
37-
test_config = {
38-
'long_entry_signal_params': {
39-
'long_entry_condition_1_enable': False,
40-
'long_entry_condition_2_enable': True,
41-
'long_entry_condition_3_enable': False,
42-
'long_entry_condition_4_enable': True,
43-
'long_entry_condition_5_enable': False,
44-
'long_entry_condition_6_enable': True,
45-
'long_entry_condition_41_enable': False,
46-
'long_entry_condition_42_enable': True,
47-
'long_entry_condition_43_enable': False,
48-
'long_entry_condition_120_enable': True,
49-
'long_entry_condition_141_enable': False,
50-
'long_entry_condition_142_enable': True,
51-
'long_entry_condition_143_enable': False
52-
},
53-
'short_entry_signal_params': {
54-
'short_entry_condition_501_enable': False
55-
}
56-
}
57-
58-
# Save initial state of the signals
59-
initial_signals = {
60-
'long': dict(strategy.long_entry_signal_params),
61-
'short': dict(strategy.short_entry_signal_params)
62-
}
58+
# Save initial state of the signals
59+
initial_signals = {
60+
"long": dict(strategy.long_entry_signal_params),
61+
"short": dict(strategy.short_entry_signal_params),
62+
}
6363

64-
strategy.update_signals_from_config(test_config)
65-
66-
# Verify that the long signals were updated correctly
67-
for signal_name, value in test_config['long_entry_signal_params'].items():
68-
assert strategy.long_entry_signal_params[signal_name] == value, (
69-
f"Mismatch in {signal_name}: "
70-
f"expected {value}, got {strategy.long_entry_signal_params[signal_name]}"
64+
strategy.update_signals_from_config(test_config)
65+
66+
# Verify that the long signals were updated correctly
67+
for signal_name, value in test_config["long_entry_signal_params"].items():
68+
assert strategy.long_entry_signal_params[signal_name] == value, (
69+
f"Mismatch in {signal_name}: " f"expected {value}, got {strategy.long_entry_signal_params[signal_name]}"
7170
)
72-
73-
# Verify that the short signals were updated correctly
74-
for signal_name, value in test_config['short_entry_signal_params'].items():
75-
assert strategy.short_entry_signal_params[signal_name] == value
76-
77-
# Verify that signals not included in the config retain their original values
78-
for signal_name in initial_signals['long']:
79-
if signal_name not in test_config['long_entry_signal_params']:
80-
assert strategy.long_entry_signal_params[signal_name] == initial_signals['long'][signal_name]
81-
82-
for signal_name in initial_signals['short']:
83-
if signal_name not in test_config['short_entry_signal_params']:
84-
assert strategy.short_entry_signal_params[signal_name] == initial_signals['short'][signal_name]
85-
86-
# Test with partial configuration
87-
partial_config = {
88-
'long_entry_signal_params': {
89-
'long_entry_condition_1_enable': True
90-
}
91-
}
92-
93-
strategy.update_signals_from_config(partial_config)
94-
assert strategy.long_entry_signal_params['long_entry_condition_1_enable'] is True
95-
# Verify that other signals remain unchanged
96-
assert strategy.long_entry_signal_params['long_entry_condition_2_enable'] is True
71+
72+
# Verify that the short signals were updated correctly
73+
for signal_name, value in test_config["short_entry_signal_params"].items():
74+
assert strategy.short_entry_signal_params[signal_name] == value
75+
76+
# Verify that signals not included in the config retain their original values
77+
for signal_name in initial_signals["long"]:
78+
if signal_name not in test_config["long_entry_signal_params"]:
79+
assert strategy.long_entry_signal_params[signal_name] == initial_signals["long"][signal_name]
80+
81+
for signal_name in initial_signals["short"]:
82+
if signal_name not in test_config["short_entry_signal_params"]:
83+
assert strategy.short_entry_signal_params[signal_name] == initial_signals["short"][signal_name]
84+
85+
# Test with partial configuration
86+
partial_config = {"long_entry_signal_params": {"long_entry_condition_1_enable": True}}
87+
88+
strategy.update_signals_from_config(partial_config)
89+
assert strategy.long_entry_signal_params["long_entry_condition_1_enable"] is True
90+
# Verify that other signals remain unchanged
91+
assert strategy.long_entry_signal_params["long_entry_condition_2_enable"] is True

0 commit comments

Comments
 (0)