freqtrade_origin/tests/strategy/test_default_strategy.py

71 lines
3.0 KiB
Python
Raw Normal View History

2020-12-19 16:59:49 +00:00
from datetime import datetime
2020-12-20 10:17:50 +00:00
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
2020-02-18 19:12:10 +00:00
from .strats.default_strategy import DefaultStrategy
2018-01-15 08:35:11 +00:00
def test_default_strategy_structure():
assert hasattr(DefaultStrategy, 'minimal_roi')
assert hasattr(DefaultStrategy, 'stoploss')
assert hasattr(DefaultStrategy, 'timeframe')
2018-01-15 08:35:11 +00:00
assert hasattr(DefaultStrategy, 'populate_indicators')
assert hasattr(DefaultStrategy, 'populate_buy_trend')
assert hasattr(DefaultStrategy, 'populate_sell_trend')
2021-08-08 09:38:34 +00:00
assert hasattr(DefaultStrategy, 'populate_short_trend')
assert hasattr(DefaultStrategy, 'populate_exit_short_trend')
2018-01-15 08:35:11 +00:00
2018-01-18 05:50:12 +00:00
2020-12-19 16:59:49 +00:00
def test_default_strategy(result, fee):
strategy = DefaultStrategy({})
2018-01-15 08:35:11 +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
indicators = strategy.populate_indicators(result, metadata)
2018-01-15 08:35:11 +00:00
assert type(indicators) is DataFrame
assert type(strategy.populate_buy_trend(indicators, metadata)) is DataFrame
assert type(strategy.populate_sell_trend(indicators, metadata)) is DataFrame
2021-08-08 09:38:34 +00:00
# TODO-lev: I think these two should be commented out in the strategy by default
# TODO-lev: so they can be tested, but the tests can't really remain
assert type(strategy.populate_short_trend(indicators, metadata)) is DataFrame
assert type(strategy.populate_exit_short_trend(indicators, metadata)) is DataFrame
2020-12-19 16:59:49 +00:00
trade = Trade(
open_rate=19_000,
amount=0.1,
pair='ETH/BTC',
fee_open=fee.return_value
)
assert strategy.confirm_trade_entry(pair='ETH/BTC', order_type='limit', amount=0.1,
rate=20000, time_in_force='gtc',
2021-08-08 09:38:34 +00:00
is_short=False, current_time=datetime.utcnow()) 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,
rate=20000, time_in_force='gtc', sell_reason='roi',
2021-08-08 09:38:34 +00:00
is_short=False, current_time=datetime.utcnow()) is True
2020-12-19 16:59:49 +00:00
2021-08-08 09:38:34 +00:00
# TODO-lev: Test for shorts?
2020-12-20 10:17:50 +00:00
assert strategy.custom_stoploss(pair='ETH/BTC', trade=trade, current_time=datetime.now(),
current_rate=20_000, current_profit=0.05) == strategy.stoploss
2021-08-08 09:38:34 +00:00
short_trade = Trade(
open_rate=21_000,
amount=0.1,
pair='ETH/BTC',
fee_open=fee.return_value
)
assert strategy.confirm_trade_entry(pair='ETH/BTC', order_type='limit', amount=0.1,
rate=20000, time_in_force='gtc',
is_short=True, current_time=datetime.utcnow()) is True
assert strategy.confirm_trade_exit(pair='ETH/BTC', trade=short_trade, order_type='limit',
amount=0.1, rate=20000, time_in_force='gtc',
sell_reason='roi', is_short=True,
current_time=datetime.utcnow()) is True