Merge branch 'develop' into fut/stop_price_type
This commit is contained in:
@@ -522,8 +522,15 @@ def test__set_leverage_binance(mocker, default_conf):
|
||||
api_mock.set_leverage = MagicMock()
|
||||
type(api_mock).has = PropertyMock(return_value={'setLeverage': True})
|
||||
default_conf['dry_run'] = False
|
||||
exchange = get_patched_exchange(mocker, default_conf, id="binance")
|
||||
exchange._set_leverage(3.0, trading_mode=TradingMode.MARGIN)
|
||||
default_conf['trading_mode'] = TradingMode.FUTURES
|
||||
default_conf['margin_mode'] = MarginMode.ISOLATED
|
||||
|
||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, id="binance")
|
||||
exchange._set_leverage(3.2, 'BTC/USDT:USDT')
|
||||
assert api_mock.set_leverage.call_count == 1
|
||||
# Leverage is rounded to 3.
|
||||
assert api_mock.set_leverage.call_args_list[0][1]['leverage'] == 3
|
||||
assert api_mock.set_leverage.call_args_list[0][1]['symbol'] == 'BTC/USDT:USDT'
|
||||
|
||||
ccxt_exceptionhandlers(
|
||||
mocker,
|
||||
|
@@ -468,9 +468,13 @@ class TestCCXTExchange():
|
||||
|
||||
def test_ccxt__async_get_candle_history(self, exchange: EXCHANGE_FIXTURE_TYPE):
|
||||
exc, exchangename = exchange
|
||||
# For some weired reason, this test returns random lengths for bittrex.
|
||||
if not exc._ft_has['ohlcv_has_history'] or exchangename in ('bittrex'):
|
||||
return
|
||||
if exchangename in ('binanceus', 'bittrex'):
|
||||
# TODO: reenable binanceus test once downtime "ages out" (2023-02-06)
|
||||
# For some weired reason, this test returns random lengths for bittrex.
|
||||
pytest.skip("Exchange doesn't provide stable ohlcv history")
|
||||
|
||||
if not exc._ft_has['ohlcv_has_history']:
|
||||
pytest.skip("Exchange does not support candle history")
|
||||
pair = EXCHANGES[exchangename]['pair']
|
||||
timeframe = EXCHANGES[exchangename]['timeframe']
|
||||
self.ccxt__async_get_candle_history(
|
||||
|
@@ -706,6 +706,46 @@ def test_api_delete_trade(botclient, mocker, fee, markets, is_short):
|
||||
assert_response(rc, 502)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('is_short', [True, False])
|
||||
def test_api_delete_open_order(botclient, mocker, fee, markets, ticker, is_short):
|
||||
ftbot, client = botclient
|
||||
patch_get_signal(ftbot, enter_long=not is_short, enter_short=is_short)
|
||||
stoploss_mock = MagicMock()
|
||||
cancel_mock = MagicMock()
|
||||
mocker.patch.multiple(
|
||||
'freqtrade.exchange.Exchange',
|
||||
markets=PropertyMock(return_value=markets),
|
||||
fetch_ticker=ticker,
|
||||
cancel_order=cancel_mock,
|
||||
cancel_stoploss_order=stoploss_mock,
|
||||
)
|
||||
|
||||
rc = client_delete(client, f"{BASE_URI}/trades/10/open-order")
|
||||
assert_response(rc, 502)
|
||||
assert 'Invalid trade_id.' in rc.json()['error']
|
||||
|
||||
create_mock_trades(fee, is_short=is_short)
|
||||
Trade.commit()
|
||||
|
||||
rc = client_delete(client, f"{BASE_URI}/trades/5/open-order")
|
||||
assert_response(rc, 502)
|
||||
assert 'No open order for trade_id' in rc.json()['error']
|
||||
trade = Trade.get_trades([Trade.id == 6]).first()
|
||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order',
|
||||
side_effect=ExchangeError)
|
||||
rc = client_delete(client, f"{BASE_URI}/trades/6/open-order")
|
||||
assert_response(rc, 502)
|
||||
assert 'Order not found.' in rc.json()['error']
|
||||
|
||||
trade = Trade.get_trades([Trade.id == 6]).first()
|
||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order',
|
||||
return_value=trade.orders[-1].to_ccxt_object())
|
||||
|
||||
rc = client_delete(client, f"{BASE_URI}/trades/6/open-order")
|
||||
assert_response(rc)
|
||||
assert cancel_mock.call_count == 1
|
||||
|
||||
|
||||
def test_api_logs(botclient):
|
||||
ftbot, client = botclient
|
||||
rc = client_get(client, f"{BASE_URI}/logs")
|
||||
|
@@ -99,7 +99,7 @@ def test_telegram_init(default_conf, mocker, caplog) -> None:
|
||||
message_str = ("rpc.telegram is listening for following commands: [['status'], ['profit'], "
|
||||
"['balance'], ['start'], ['stop'], "
|
||||
"['forcesell', 'forceexit', 'fx'], ['forcebuy', 'forcelong'], ['forceshort'], "
|
||||
"['trades'], ['delete'], ['performance'], "
|
||||
"['trades'], ['delete'], ['coo', 'cancel_open_order'], ['performance'], "
|
||||
"['buys', 'entries'], ['sells', 'exits'], ['mix_tags'], "
|
||||
"['stats'], ['daily'], ['weekly'], ['monthly'], "
|
||||
"['count'], ['locks'], ['unlock', 'delete_locks'], "
|
||||
@@ -1678,6 +1678,40 @@ def test_telegram_delete_trade(mocker, update, default_conf, fee, is_short):
|
||||
assert "Please make sure to take care of this asset" in msg_mock.call_args_list[0][0][0]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('is_short', [True, False])
|
||||
def test_telegram_delete_open_order(mocker, update, default_conf, fee, is_short, ticker):
|
||||
|
||||
mocker.patch.multiple(
|
||||
'freqtrade.exchange.Exchange',
|
||||
fetch_ticker=ticker,
|
||||
)
|
||||
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
|
||||
context = MagicMock()
|
||||
context.args = []
|
||||
|
||||
telegram._cancel_open_order(update=update, context=context)
|
||||
assert "Trade-id not set." in msg_mock.call_args_list[0][0][0]
|
||||
|
||||
msg_mock.reset_mock()
|
||||
create_mock_trades(fee, is_short=is_short)
|
||||
|
||||
context = MagicMock()
|
||||
context.args = [5]
|
||||
telegram._cancel_open_order(update=update, context=context)
|
||||
assert "No open order for trade_id" in msg_mock.call_args_list[0][0][0]
|
||||
|
||||
msg_mock.reset_mock()
|
||||
|
||||
trade = Trade.get_trades([Trade.id == 6]).first()
|
||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order',
|
||||
return_value=trade.orders[-1].to_ccxt_object())
|
||||
context = MagicMock()
|
||||
context.args = [6]
|
||||
telegram._cancel_open_order(update=update, context=context)
|
||||
assert msg_mock.call_count == 1
|
||||
assert "Open order canceled." in msg_mock.call_args_list[0][0][0]
|
||||
|
||||
|
||||
def test_help_handle(default_conf, update, mocker) -> None:
|
||||
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
|
||||
|
||||
|
@@ -5028,7 +5028,7 @@ def test_startup_update_open_orders(mocker, default_conf_usdt, fee, caplog, is_s
|
||||
assert log_has_re(r"Error updating Order .*", caplog)
|
||||
|
||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order', side_effect=InvalidOrderException)
|
||||
hto_mock = mocker.patch('freqtrade.freqtradebot.FreqtradeBot.handle_timedout_order')
|
||||
hto_mock = mocker.patch('freqtrade.freqtradebot.FreqtradeBot.handle_cancel_order')
|
||||
# Orders which are no longer found after X days should be assumed as canceled.
|
||||
freqtrade.startup_update_open_orders()
|
||||
assert log_has_re(r"Order is older than \d days.*", caplog)
|
||||
|
Reference in New Issue
Block a user