Update buy_tag column to long_tag

This commit is contained in:
Matthias 2021-09-25 19:31:06 +02:00
parent a0ef89d910
commit 2a678bdbb4
6 changed files with 10 additions and 8 deletions

View File

@ -31,6 +31,7 @@ BT_DATA_COLUMNS = ['pair', 'stake_amount', 'amount', 'open_date', 'close_date',
'profit_ratio', 'profit_abs', 'sell_reason', 'profit_ratio', 'profit_abs', 'sell_reason',
'initial_stop_loss_abs', 'initial_stop_loss_ratio', 'stop_loss_abs', 'initial_stop_loss_abs', 'initial_stop_loss_ratio', 'stop_loss_abs',
'stop_loss_ratio', 'min_rate', 'max_rate', 'is_open', 'buy_tag'] 'stop_loss_ratio', 'min_rate', 'max_rate', 'is_open', 'buy_tag']
# TODO-lev: usage of the above might need compatibility code (buy_tag, is_short?, ...?)
def get_latest_optimize_filename(directory: Union[Path, str], variant: str) -> str: def get_latest_optimize_filename(directory: Union[Path, str], variant: str) -> str:

View File

@ -15,7 +15,7 @@ class SignalTagType(Enum):
""" """
Enum for signal columns Enum for signal columns
""" """
BUY_TAG = "buy_tag" LONG_TAG = "long_tag"
SHORT_TAG = "short_tag" SHORT_TAG = "short_tag"

View File

@ -45,7 +45,7 @@ LONG_IDX = 5
ELONG_IDX = 6 # Exit long ELONG_IDX = 6 # Exit long
SHORT_IDX = 7 SHORT_IDX = 7
ESHORT_IDX = 8 # Exit short ESHORT_IDX = 8 # Exit short
BUY_TAG_IDX = 9 ENTER_TAG_IDX = 9
SHORT_TAG_IDX = 10 SHORT_TAG_IDX = 10
@ -454,7 +454,8 @@ class Backtesting:
if stake_amount and (not min_stake_amount or stake_amount > min_stake_amount): if stake_amount and (not min_stake_amount or stake_amount > min_stake_amount):
# Enter trade # Enter trade
has_buy_tag = len(row) >= BUY_TAG_IDX + 1 # TODO-lev: SHORT_TAG ...
has_buy_tag = len(row) >= ENTER_TAG_IDX + 1
trade = LocalTrade( trade = LocalTrade(
pair=pair, pair=pair,
open_rate=row[OPEN_IDX], open_rate=row[OPEN_IDX],
@ -464,7 +465,7 @@ class Backtesting:
fee_open=self.fee, fee_open=self.fee,
fee_close=self.fee, fee_close=self.fee,
is_open=True, is_open=True,
buy_tag=row[BUY_TAG_IDX] if has_buy_tag else None, buy_tag=row[ENTER_TAG_IDX] if has_buy_tag else None,
exchange=self._exchange_name, exchange=self._exchange_name,
is_short=(direction == 'short'), is_short=(direction == 'short'),
) )

View File

@ -519,7 +519,7 @@ class IStrategy(ABC, HyperStrategyMixin):
dataframe[SignalType.EXIT_LONG.value] = 0 dataframe[SignalType.EXIT_LONG.value] = 0
dataframe[SignalType.ENTER_SHORT.value] = 0 dataframe[SignalType.ENTER_SHORT.value] = 0
dataframe[SignalType.EXIT_SHORT.value] = 0 dataframe[SignalType.EXIT_SHORT.value] = 0
dataframe[SignalTagType.BUY_TAG.value] = None dataframe[SignalTagType.LONG_TAG.value] = None
dataframe[SignalTagType.SHORT_TAG.value] = None dataframe[SignalTagType.SHORT_TAG.value] = None
# Other Defs in strategy that want to be called every loop here # Other Defs in strategy that want to be called every loop here
@ -690,7 +690,7 @@ class IStrategy(ABC, HyperStrategyMixin):
enter_tag_value: Optional[str] = None enter_tag_value: Optional[str] = None
if enter_long == 1 and not any([exit_long, enter_short]): if enter_long == 1 and not any([exit_long, enter_short]):
enter_signal = SignalDirection.LONG enter_signal = SignalDirection.LONG
enter_tag_value = latest.get(SignalTagType.BUY_TAG.value, None) enter_tag_value = latest.get(SignalTagType.LONG_TAG.value, None)
if enter_short == 1 and not any([exit_short, enter_long]): if enter_short == 1 and not any([exit_short, enter_long]):
enter_signal = SignalDirection.SHORT enter_signal = SignalDirection.SHORT
enter_tag_value = latest.get(SignalTagType.SHORT_TAG.value, None) enter_tag_value = latest.get(SignalTagType.SHORT_TAG.value, None)

View File

@ -167,7 +167,7 @@ def test__pprint_dict():
def test_get_strategy_filename(default_conf): def test_get_strategy_filename(default_conf):
x = HyperoptTools.get_strategy_filename(default_conf, CURRENT_TEST_STRATEGY) x = HyperoptTools.get_strategy_filename(default_conf, 'StrategyTestV3')
assert isinstance(x, Path) assert isinstance(x, Path)
assert x == Path(__file__).parents[1] / 'strategy/strats/strategy_test_v3.py' assert x == Path(__file__).parents[1] / 'strategy/strats/strategy_test_v3.py'

View File

@ -59,7 +59,7 @@ def test_returns_latest_signal(ohlcv_history):
assert _STRATEGY.get_exit_signal('ETH/BTC', '5m', mocked_history, True) == (False, False) assert _STRATEGY.get_exit_signal('ETH/BTC', '5m', mocked_history, True) == (False, False)
mocked_history.loc[1, 'exit_long'] = 0 mocked_history.loc[1, 'exit_long'] = 0
mocked_history.loc[1, 'enter_long'] = 1 mocked_history.loc[1, 'enter_long'] = 1
mocked_history.loc[1, 'buy_tag'] = 'buy_signal_01' mocked_history.loc[1, 'long_tag'] = 'buy_signal_01'
assert _STRATEGY.get_entry_signal( assert _STRATEGY.get_entry_signal(
'ETH/BTC', '5m', mocked_history) == (SignalDirection.LONG, 'buy_signal_01') 'ETH/BTC', '5m', mocked_history) == (SignalDirection.LONG, 'buy_signal_01')