Merge branch 'feat/short' into funding-fee-dry-run
This commit is contained in:
@@ -488,7 +488,7 @@ def leverage_trade(fee):
|
||||
open_order_id='dry_run_leverage_buy_12368',
|
||||
strategy='DefaultStrategy',
|
||||
timeframe=5,
|
||||
sell_reason='sell_signal', # TODO-lev: Update to exit/close reason
|
||||
sell_reason='sell_signal',
|
||||
open_date=datetime.now(tz=timezone.utc) - timedelta(minutes=300),
|
||||
close_date=datetime.now(tz=timezone.utc),
|
||||
interest_rate=0.0005
|
||||
|
@@ -3253,16 +3253,16 @@ def test_validate_trading_mode_and_collateral(
|
||||
("binance", "spot", {}),
|
||||
("binance", "margin", {"options": {"defaultType": "margin"}}),
|
||||
("binance", "futures", {"options": {"defaultType": "future"}}),
|
||||
("kraken", "spot", {}),
|
||||
("kraken", "margin", {}),
|
||||
("kraken", "futures", {}),
|
||||
("ftx", "spot", {}),
|
||||
("ftx", "margin", {}),
|
||||
("ftx", "futures", {}),
|
||||
("bittrex", "spot", {}),
|
||||
("gateio", "spot", {}),
|
||||
("gateio", "margin", {"options": {"defaultType": "margin"}}),
|
||||
("bibox", "spot", {"has": {"fetchCurrencies": False}}),
|
||||
("bibox", "margin", {"has": {"fetchCurrencies": False}, "options": {"defaultType": "margin"}}),
|
||||
("bibox", "futures", {"has": {"fetchCurrencies": False}, "options": {"defaultType": "swap"}}),
|
||||
("bybit", "futures", {"options": {"defaultType": "linear"}}),
|
||||
("ftx", "futures", {"options": {"defaultType": "swap"}}),
|
||||
("gateio", "futures", {"options": {"defaultType": "swap"}}),
|
||||
("hitbtc", "futures", {"options": {"defaultType": "swap"}}),
|
||||
("kraken", "futures", {"options": {"defaultType": "swap"}}),
|
||||
("kucoin", "futures", {"options": {"defaultType": "swap"}}),
|
||||
("okex", "futures", {"options": {"defaultType": "swap"}}),
|
||||
])
|
||||
def test__ccxt_config(
|
||||
default_conf,
|
||||
|
@@ -586,10 +586,10 @@ def test_api_trades(botclient, mocker, fee, markets, is_short):
|
||||
assert rc.json()['total_trades'] == 2
|
||||
|
||||
|
||||
# TODO-lev: @pytest.mark.parametrize('is_short', [True, False])
|
||||
def test_api_trade_single(botclient, mocker, fee, ticker, markets):
|
||||
@pytest.mark.parametrize('is_short', [True, False])
|
||||
def test_api_trade_single(botclient, mocker, fee, ticker, markets, is_short):
|
||||
ftbot, client = botclient
|
||||
patch_get_signal(ftbot)
|
||||
patch_get_signal(ftbot, enter_long=not is_short, enter_short=is_short)
|
||||
mocker.patch.multiple(
|
||||
'freqtrade.exchange.Exchange',
|
||||
markets=PropertyMock(return_value=markets),
|
||||
@@ -599,7 +599,7 @@ def test_api_trade_single(botclient, mocker, fee, ticker, markets):
|
||||
assert_response(rc, 404)
|
||||
assert rc.json()['detail'] == 'Trade not found.'
|
||||
|
||||
create_mock_trades(fee, False)
|
||||
create_mock_trades(fee, is_short=is_short)
|
||||
Trade.query.session.flush()
|
||||
|
||||
rc = client_get(client, f"{BASE_URI}/trade/3")
|
||||
@@ -607,10 +607,10 @@ def test_api_trade_single(botclient, mocker, fee, ticker, markets):
|
||||
assert rc.json()['trade_id'] == 3
|
||||
|
||||
|
||||
# TODO-lev: @pytest.mark.parametrize('is_short', [True, False])
|
||||
def test_api_delete_trade(botclient, mocker, fee, markets):
|
||||
@pytest.mark.parametrize('is_short', [True, False])
|
||||
def test_api_delete_trade(botclient, mocker, fee, markets, is_short):
|
||||
ftbot, client = botclient
|
||||
patch_get_signal(ftbot)
|
||||
patch_get_signal(ftbot, enter_long=not is_short, enter_short=is_short)
|
||||
stoploss_mock = MagicMock()
|
||||
cancel_mock = MagicMock()
|
||||
mocker.patch.multiple(
|
||||
@@ -749,10 +749,10 @@ def test_api_profit(botclient, mocker, ticker, fee, markets):
|
||||
}
|
||||
|
||||
|
||||
# TODO-lev: @pytest.mark.parametrize('is_short', [True, False])
|
||||
def test_api_stats(botclient, mocker, ticker, fee, markets,):
|
||||
@pytest.mark.parametrize('is_short', [True, False])
|
||||
def test_api_stats(botclient, mocker, ticker, fee, markets, is_short):
|
||||
ftbot, client = botclient
|
||||
patch_get_signal(ftbot)
|
||||
patch_get_signal(ftbot, enter_long=not is_short, enter_short=is_short)
|
||||
mocker.patch.multiple(
|
||||
'freqtrade.exchange.Exchange',
|
||||
get_balances=MagicMock(return_value=ticker),
|
||||
@@ -766,7 +766,7 @@ def test_api_stats(botclient, mocker, ticker, fee, markets,):
|
||||
assert 'durations' in rc.json()
|
||||
assert 'sell_reasons' in rc.json()
|
||||
|
||||
create_mock_trades(fee, False)
|
||||
create_mock_trades(fee, is_short=is_short)
|
||||
|
||||
rc = client_get(client, f"{BASE_URI}/stats")
|
||||
assert_response(rc, 200)
|
||||
|
@@ -1294,8 +1294,8 @@ def test_telegram_trades(mocker, update, default_conf, fee):
|
||||
msg_mock.call_args_list[0][0][0]))
|
||||
|
||||
|
||||
# TODO-lev: @pytest.mark.parametrize('is_short', [True, False])
|
||||
def test_telegram_delete_trade(mocker, update, default_conf, fee):
|
||||
@pytest.mark.parametrize('is_short', [True, False])
|
||||
def test_telegram_delete_trade(mocker, update, default_conf, fee, is_short):
|
||||
|
||||
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
|
||||
context = MagicMock()
|
||||
@@ -1305,7 +1305,7 @@ def test_telegram_delete_trade(mocker, update, default_conf, fee):
|
||||
assert "Trade-id not set." in msg_mock.call_args_list[0][0][0]
|
||||
|
||||
msg_mock.reset_mock()
|
||||
create_mock_trades(fee, False)
|
||||
create_mock_trades(fee, is_short)
|
||||
|
||||
context = MagicMock()
|
||||
context.args = [1]
|
||||
|
@@ -1,5 +1,6 @@
|
||||
from datetime import datetime
|
||||
|
||||
import pytest
|
||||
from pandas import DataFrame
|
||||
|
||||
from freqtrade.persistence.models import Trade
|
||||
@@ -7,7 +8,7 @@ from freqtrade.persistence.models import Trade
|
||||
from .strats.strategy_test_v3 import StrategyTestV3
|
||||
|
||||
|
||||
def test_strategy_test_v2_structure():
|
||||
def test_strategy_test_v3_structure():
|
||||
assert hasattr(StrategyTestV3, 'minimal_roi')
|
||||
assert hasattr(StrategyTestV3, 'stoploss')
|
||||
assert hasattr(StrategyTestV3, 'timeframe')
|
||||
@@ -16,7 +17,11 @@ def test_strategy_test_v2_structure():
|
||||
assert hasattr(StrategyTestV3, 'populate_sell_trend')
|
||||
|
||||
|
||||
def test_strategy_test_v2(result, fee):
|
||||
@pytest.mark.parametrize('is_short,side', [
|
||||
(True, 'short'),
|
||||
(False, 'long'),
|
||||
])
|
||||
def test_strategy_test_v3(result, fee, is_short, side):
|
||||
strategy = StrategyTestV3({})
|
||||
|
||||
metadata = {'pair': 'ETH/BTC'}
|
||||
@@ -32,16 +37,18 @@ def test_strategy_test_v2(result, fee):
|
||||
open_rate=19_000,
|
||||
amount=0.1,
|
||||
pair='ETH/BTC',
|
||||
fee_open=fee.return_value
|
||||
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.utcnow(), side='long') is True
|
||||
current_time=datetime.utcnow(),
|
||||
side=side) is True
|
||||
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',
|
||||
current_time=datetime.utcnow()) is True
|
||||
current_time=datetime.utcnow(),
|
||||
side=side) is True
|
||||
|
||||
# TODO-lev: Test for shorts?
|
||||
assert strategy.custom_stoploss(pair='ETH/BTC', trade=trade, current_time=datetime.now(),
|
||||
current_rate=20_000, current_profit=0.05) == strategy.stoploss
|
||||
|
@@ -1907,12 +1907,12 @@ def test_get_total_closed_profit(fee, use_db):
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_persistence")
|
||||
# TODO-lev: @pytest.mark.parametrize('is_short', [True, False])
|
||||
@pytest.mark.parametrize('is_short', [True, False])
|
||||
@pytest.mark.parametrize('use_db', [True, False])
|
||||
def test_get_trades_proxy(fee, use_db):
|
||||
def test_get_trades_proxy(fee, use_db, is_short):
|
||||
Trade.use_db = use_db
|
||||
Trade.reset_trades()
|
||||
create_mock_trades(fee, False, use_db)
|
||||
create_mock_trades(fee, is_short, use_db)
|
||||
trades = Trade.get_trades_proxy()
|
||||
assert len(trades) == 6
|
||||
|
||||
@@ -2042,48 +2042,48 @@ def test_update_order_from_ccxt(caplog):
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_persistence")
|
||||
# TODO-lev: @pytest.mark.parametrize('is_short', [True, False])
|
||||
def test_select_order(fee):
|
||||
create_mock_trades(fee, False)
|
||||
@pytest.mark.parametrize('is_short', [True, False])
|
||||
def test_select_order(fee, is_short):
|
||||
create_mock_trades(fee, is_short)
|
||||
|
||||
trades = Trade.get_trades().all()
|
||||
|
||||
# Open buy order, no sell order
|
||||
order = trades[0].select_order('buy', True)
|
||||
order = trades[0].select_order(trades[0].enter_side, True)
|
||||
assert order is None
|
||||
order = trades[0].select_order('buy', False)
|
||||
order = trades[0].select_order(trades[0].enter_side, False)
|
||||
assert order is not None
|
||||
order = trades[0].select_order('sell', None)
|
||||
order = trades[0].select_order(trades[0].exit_side, None)
|
||||
assert order is None
|
||||
|
||||
# closed buy order, and open sell order
|
||||
order = trades[1].select_order('buy', True)
|
||||
order = trades[1].select_order(trades[1].enter_side, True)
|
||||
assert order is None
|
||||
order = trades[1].select_order('buy', False)
|
||||
order = trades[1].select_order(trades[1].enter_side, False)
|
||||
assert order is not None
|
||||
order = trades[1].select_order('buy', None)
|
||||
order = trades[1].select_order(trades[1].enter_side, None)
|
||||
assert order is not None
|
||||
order = trades[1].select_order('sell', True)
|
||||
order = trades[1].select_order(trades[1].exit_side, True)
|
||||
assert order is None
|
||||
order = trades[1].select_order('sell', False)
|
||||
order = trades[1].select_order(trades[1].exit_side, False)
|
||||
assert order is not None
|
||||
|
||||
# Has open buy order
|
||||
order = trades[3].select_order('buy', True)
|
||||
order = trades[3].select_order(trades[3].enter_side, True)
|
||||
assert order is not None
|
||||
order = trades[3].select_order('buy', False)
|
||||
order = trades[3].select_order(trades[3].enter_side, False)
|
||||
assert order is None
|
||||
|
||||
# Open sell order
|
||||
order = trades[4].select_order('buy', True)
|
||||
order = trades[4].select_order(trades[4].enter_side, True)
|
||||
assert order is None
|
||||
order = trades[4].select_order('buy', False)
|
||||
order = trades[4].select_order(trades[4].enter_side, False)
|
||||
assert order is not None
|
||||
|
||||
order = trades[4].select_order('sell', True)
|
||||
order = trades[4].select_order(trades[4].exit_side, True)
|
||||
assert order is not None
|
||||
assert order.ft_order_side == 'stoploss'
|
||||
order = trades[4].select_order('sell', False)
|
||||
order = trades[4].select_order(trades[4].exit_side, False)
|
||||
assert order is None
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user