freqtrade_origin/tests/strategy/test_default_strategy.py

83 lines
2.3 KiB
Python
Raw Normal View History

2023-05-14 06:42:30 +00:00
from datetime import datetime, timezone
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
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():
2024-05-12 13:45:55 +00:00
assert hasattr(StrategyTestV3, "minimal_roi")
assert hasattr(StrategyTestV3, "stoploss")
assert hasattr(StrategyTestV3, "timeframe")
assert hasattr(StrategyTestV3, "populate_indicators")
assert hasattr(StrategyTestV3, "populate_entry_trend")
assert hasattr(StrategyTestV3, "populate_exit_trend")
@pytest.mark.parametrize(
"is_short,side",
[
(True, "short"),
(False, "long"),
],
)
2022-09-19 18:59:40 +00:00
def test_strategy_test_v3(dataframe_1m, fee, is_short, side):
strategy = StrategyTestV3({})
2018-01-15 08:35:11 +00:00
2024-05-12 13:45:55 +00:00
metadata = {"pair": "ETH/BTC"}
2023-08-14 07:11:19 +00:00
assert isinstance(strategy.minimal_roi, dict)
assert isinstance(strategy.stoploss, float)
assert isinstance(strategy.timeframe, str)
2022-09-19 18:59:40 +00:00
indicators = strategy.populate_indicators(dataframe_1m, metadata)
2023-08-14 07:11:19 +00:00
assert isinstance(indicators, DataFrame)
assert isinstance(strategy.populate_buy_trend(indicators, metadata), DataFrame)
assert isinstance(strategy.populate_sell_trend(indicators, metadata), DataFrame)
2020-12-19 16:59:49 +00:00
trade = Trade(
2024-05-12 13:45:55 +00:00
open_rate=19_000, amount=0.1, pair="ETH/BTC", fee_open=fee.return_value, is_short=is_short
)
assert (
strategy.confirm_trade_entry(
pair="ETH/BTC",
order_type="limit",
amount=0.1,
rate=20000,
time_in_force="gtc",
current_time=datetime.now(timezone.utc),
side=side,
entry_tag=None,
)
is True
)
assert (
strategy.confirm_trade_exit(
pair="ETH/BTC",
trade=trade,
order_type="limit",
amount=0.1,
rate=20000,
time_in_force="gtc",
exit_reason="roi",
sell_reason="roi",
current_time=datetime.now(timezone.utc),
side=side,
)
is True
2020-12-19 16:59:49 +00:00
)
2024-05-12 13:45:55 +00:00
assert (
strategy.custom_stoploss(
pair="ETH/BTC",
trade=trade,
current_time=datetime.now(),
current_rate=20_000,
current_profit=0.05,
after_fill=False,
)
== strategy.stoploss
)