Add fetch_order_or_stoploss wrapper
This commit is contained in:
parent
fc2104bfad
commit
f2b390a271
@ -1039,6 +1039,17 @@ class Exchange:
|
|||||||
# Assign method to fetch_stoploss_order to allow easy overriding in other classes
|
# Assign method to fetch_stoploss_order to allow easy overriding in other classes
|
||||||
fetch_stoploss_order = fetch_order
|
fetch_stoploss_order = fetch_order
|
||||||
|
|
||||||
|
def fetch_order_or_stoploss_order(self, order_id: str, pair: str,
|
||||||
|
stoploss_order: bool = False) -> Dict:
|
||||||
|
"""
|
||||||
|
Simple wrapper calling either fetch_order or fetch_stoploss_order depending on
|
||||||
|
the stoploss_order parameter
|
||||||
|
:param stoploss_order: If true, uses fetch_stoploss_order, otherwise fetch_order.
|
||||||
|
"""
|
||||||
|
if stoploss_order:
|
||||||
|
return self.fetch_stoploss_order(order_id, pair)
|
||||||
|
return self.fetch_order(order_id, pair)
|
||||||
|
|
||||||
@retrier
|
@retrier
|
||||||
def fetch_l2_order_book(self, pair: str, limit: int = 100) -> dict:
|
def fetch_l2_order_book(self, pair: str, limit: int = 100) -> dict:
|
||||||
"""
|
"""
|
||||||
|
@ -1936,6 +1936,31 @@ def test_fetch_stoploss_order(default_conf, mocker, exchange_name):
|
|||||||
order_id='_', pair='TKN/BTC')
|
order_id='_', pair='TKN/BTC')
|
||||||
|
|
||||||
|
|
||||||
|
def test_fetch_order_or_stoploss_order(default_conf, mocker):
|
||||||
|
exchange = get_patched_exchange(mocker, default_conf, id='binance')
|
||||||
|
fetch_order_mock = MagicMock()
|
||||||
|
fetch_stoploss_order_mock = MagicMock()
|
||||||
|
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
||||||
|
fetch_order=fetch_order_mock,
|
||||||
|
fetch_stoploss_order=fetch_stoploss_order_mock,
|
||||||
|
)
|
||||||
|
|
||||||
|
exchange.fetch_order_or_stoploss_order('1234', 'ETH/BTC', False)
|
||||||
|
assert fetch_order_mock.call_count == 1
|
||||||
|
assert fetch_order_mock.call_args_list[0][0][0] == '1234'
|
||||||
|
assert fetch_order_mock.call_args_list[0][0][1] == 'ETH/BTC'
|
||||||
|
assert fetch_stoploss_order_mock.call_count == 0
|
||||||
|
|
||||||
|
fetch_order_mock.reset_mock()
|
||||||
|
fetch_stoploss_order_mock.reset_mock()
|
||||||
|
|
||||||
|
exchange.fetch_order_or_stoploss_order('1234', 'ETH/BTC', True)
|
||||||
|
assert fetch_order_mock.call_count == 0
|
||||||
|
assert fetch_stoploss_order_mock.call_count == 1
|
||||||
|
assert fetch_stoploss_order_mock.call_args_list[0][0][0] == '1234'
|
||||||
|
assert fetch_stoploss_order_mock.call_args_list[0][0][1] == 'ETH/BTC'
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("exchange_name", EXCHANGES)
|
@pytest.mark.parametrize("exchange_name", EXCHANGES)
|
||||||
def test_name(default_conf, mocker, exchange_name):
|
def test_name(default_conf, mocker, exchange_name):
|
||||||
exchange = get_patched_exchange(mocker, default_conf, id=exchange_name)
|
exchange = get_patched_exchange(mocker, default_conf, id=exchange_name)
|
||||||
|
Loading…
Reference in New Issue
Block a user