2020-12-19 16:59:49 +00:00
|
|
|
from datetime import datetime
|
2020-12-20 10:17:50 +00:00
|
|
|
|
2021-11-14 01:50:53 +00:00
|
|
|
import pytest
|
2018-01-15 08:35:11 +00:00
|
|
|
from pandas import DataFrame
|
2018-03-17 21:44:47 +00:00
|
|
|
|
2020-12-20 10:17:50 +00:00
|
|
|
from freqtrade.persistence.models import Trade
|
|
|
|
|
2021-09-21 18:18:14 +00:00
|
|
|
from .strats.strategy_test_v3 import StrategyTestV3
|
2018-01-15 08:35:11 +00:00
|
|
|
|
|
|
|
|
2021-11-14 08:02:25 +00:00
|
|
|
def test_strategy_test_v3_structure():
|
2021-09-21 18:18:14 +00:00
|
|
|
assert hasattr(StrategyTestV3, 'minimal_roi')
|
|
|
|
assert hasattr(StrategyTestV3, 'stoploss')
|
|
|
|
assert hasattr(StrategyTestV3, 'timeframe')
|
|
|
|
assert hasattr(StrategyTestV3, 'populate_indicators')
|
2022-03-12 08:31:14 +00:00
|
|
|
assert hasattr(StrategyTestV3, 'populate_entry_trend')
|
|
|
|
assert hasattr(StrategyTestV3, 'populate_exit_trend')
|
2018-01-15 08:35:11 +00:00
|
|
|
|
2018-01-18 05:50:12 +00:00
|
|
|
|
2021-11-14 01:50:53 +00:00
|
|
|
@pytest.mark.parametrize('is_short,side', [
|
|
|
|
(True, 'short'),
|
|
|
|
(False, 'long'),
|
|
|
|
])
|
2021-11-14 08:02:25 +00:00
|
|
|
def test_strategy_test_v3(result, fee, is_short, side):
|
2021-09-21 18:18:14 +00:00
|
|
|
strategy = StrategyTestV3({})
|
2018-01-15 08:35:11 +00:00
|
|
|
|
2018-07-29 19:07:21 +00:00
|
|
|
metadata = {'pair': 'ETH/BTC'}
|
2018-01-15 08:35:11 +00:00
|
|
|
assert type(strategy.minimal_roi) is dict
|
|
|
|
assert type(strategy.stoploss) is float
|
2020-06-02 07:36:04 +00:00
|
|
|
assert type(strategy.timeframe) is str
|
2018-07-29 19:07:21 +00:00
|
|
|
indicators = strategy.populate_indicators(result, metadata)
|
2018-01-15 08:35:11 +00:00
|
|
|
assert type(indicators) is DataFrame
|
2018-07-29 19:07:21 +00:00
|
|
|
assert type(strategy.populate_buy_trend(indicators, metadata)) is DataFrame
|
|
|
|
assert type(strategy.populate_sell_trend(indicators, metadata)) is DataFrame
|
2022-04-25 23:46:40 +00:00
|
|
|
assert strategy.bot_started is True
|
2020-12-19 16:59:49 +00:00
|
|
|
|
|
|
|
trade = Trade(
|
|
|
|
open_rate=19_000,
|
|
|
|
amount=0.1,
|
|
|
|
pair='ETH/BTC',
|
2021-11-14 01:50:53 +00:00
|
|
|
fee_open=fee.return_value,
|
|
|
|
is_short=is_short
|
2020-12-19 16:59:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
assert strategy.confirm_trade_entry(pair='ETH/BTC', order_type='limit', amount=0.1,
|
2021-05-02 09:20:25 +00:00
|
|
|
rate=20000, time_in_force='gtc',
|
2021-11-14 01:50:53 +00:00
|
|
|
current_time=datetime.utcnow(),
|
2022-01-29 13:19:30 +00:00
|
|
|
side=side, entry_tag=None) is True
|
2020-12-19 16:59:49 +00:00
|
|
|
assert strategy.confirm_trade_exit(pair='ETH/BTC', trade=trade, order_type='limit', amount=0.1,
|
2022-03-25 05:37:40 +00:00
|
|
|
rate=20000, time_in_force='gtc', exit_reason='roi',
|
|
|
|
sell_reason='roi',
|
2021-11-14 01:50:53 +00:00
|
|
|
current_time=datetime.utcnow(),
|
|
|
|
side=side) is True
|
2020-12-19 16:59:49 +00:00
|
|
|
|
2020-12-20 10:17:50 +00:00
|
|
|
assert strategy.custom_stoploss(pair='ETH/BTC', trade=trade, current_time=datetime.now(),
|
2021-05-02 09:17:59 +00:00
|
|
|
current_rate=20_000, current_profit=0.05) == strategy.stoploss
|