simplify dry-run taker/maker selection
This commit is contained in:
parent
8b2535a8da
commit
4172f92bfc
@ -811,26 +811,6 @@ class Exchange:
|
||||
|
||||
# Dry-run methods
|
||||
|
||||
def taker_or_maker(
|
||||
self,
|
||||
order_reason: Literal['entry', 'exit', 'stoploss'], # TODO: stoploss
|
||||
):
|
||||
order_type = self._config['order_types'][order_reason]
|
||||
if order_type == 'market' or order_reason == 'stoploss':
|
||||
return 'taker'
|
||||
else:
|
||||
return (
|
||||
'maker' if (
|
||||
(
|
||||
order_reason == 'entry' and
|
||||
self._config['entry_pricing']['price_side'] == 'same'
|
||||
) or (
|
||||
order_reason == 'exit' and
|
||||
self._config['exit_pricing']['price_side'] == 'same'
|
||||
)
|
||||
) else 'taker'
|
||||
)
|
||||
|
||||
def create_dry_run_order(self, pair: str, ordertype: str, side: str, amount: float,
|
||||
rate: float, leverage: float, params: Dict = {},
|
||||
stop_loss: bool = False) -> Dict[str, Any]:
|
||||
@ -873,7 +853,7 @@ class Exchange:
|
||||
# market orders will always incurr taker fees
|
||||
dry_order = self.add_dry_order_fee(pair, dry_order, 'taker')
|
||||
|
||||
dry_order = self.check_dry_limit_order_filled(dry_order)
|
||||
dry_order = self.check_dry_limit_order_filled(dry_order, immediate=True)
|
||||
|
||||
self._dry_run_open_orders[dry_order["id"]] = dry_order
|
||||
# Copy order and close it - so the returned order is open unless it's a market order
|
||||
@ -955,7 +935,8 @@ class Exchange:
|
||||
pass
|
||||
return False
|
||||
|
||||
def check_dry_limit_order_filled(self, order: Dict[str, Any]) -> Dict[str, Any]:
|
||||
def check_dry_limit_order_filled(
|
||||
self, order: Dict[str, Any], immediate: bool = False) -> Dict[str, Any]:
|
||||
"""
|
||||
Check dry-run limit order fill and update fee (if it filled).
|
||||
"""
|
||||
@ -969,15 +950,11 @@ class Exchange:
|
||||
'filled': order['amount'],
|
||||
'remaining': 0,
|
||||
})
|
||||
enter_long = not order['is_short'] and order['side'] == 'buy'
|
||||
enter_short = order['is_short'] and order['side'] == 'sell'
|
||||
entry_or_exit: EntryExit = (
|
||||
'entry' if (enter_short or enter_long) else 'exit'
|
||||
)
|
||||
|
||||
self.add_dry_order_fee(
|
||||
pair,
|
||||
order,
|
||||
self.taker_or_maker(entry_or_exit)
|
||||
'taker' if immediate else 'maker',
|
||||
)
|
||||
|
||||
return order
|
||||
|
@ -1160,23 +1160,33 @@ def test_create_dry_run_order_fees(
|
||||
price_side,
|
||||
fee,
|
||||
):
|
||||
default_conf[f"{order_reason}_pricing"]["price_side"] = "same"
|
||||
default_conf["order_types"][order_reason] = order_type
|
||||
mocker.patch(
|
||||
'freqtrade.exchange.Exchange.get_fee',
|
||||
lambda symbol, taker_or_maker: 2.0 if taker_or_maker == 'taker' else 1.0
|
||||
side_effect=lambda symbol, taker_or_maker: 2.0 if taker_or_maker == 'taker' else 1.0
|
||||
)
|
||||
mocker.patch('freqtrade.exchange.Exchange._is_dry_limit_order_filled',
|
||||
return_value=price_side == 'other')
|
||||
exchange = get_patched_exchange(mocker, default_conf)
|
||||
|
||||
order = exchange.create_dry_run_order(
|
||||
pair='ADA/USDT',
|
||||
pair='LTC/USDT',
|
||||
ordertype=order_type,
|
||||
side=side,
|
||||
amount=10,
|
||||
rate=2.0,
|
||||
leverage=1.0
|
||||
)
|
||||
if price_side == 'other' or order_type == 'market':
|
||||
assert order['fee']['rate'] == fee
|
||||
return
|
||||
else:
|
||||
assert order['fee'] is None
|
||||
|
||||
assert order['ft_fee_base'] == fee
|
||||
mocker.patch('freqtrade.exchange.Exchange._is_dry_limit_order_filled',
|
||||
return_value=price_side != 'other')
|
||||
|
||||
order1 = exchange.fetch_dry_run_order(order['id'])
|
||||
assert order1['fee']['rate'] == fee
|
||||
|
||||
|
||||
@pytest.mark.parametrize("side,startprice,endprice", [
|
||||
@ -5101,26 +5111,3 @@ def test_stoploss_contract_size(mocker, default_conf, contract_size, order_amoun
|
||||
assert order['cost'] == 100
|
||||
assert order['filled'] == 100
|
||||
assert order['remaining'] == 100
|
||||
|
||||
|
||||
@pytest.mark.parametrize('order_reason,price_side,order_type,taker_or_maker', [
|
||||
("entry", "same", "limit", "maker"),
|
||||
("exit", "same", "limit", "maker"),
|
||||
("entry", "other", "limit", "taker"),
|
||||
("exit", "other", "limit", "taker"),
|
||||
("stoploss", "same", "limit", "taker"),
|
||||
("stoploss", "other", "limit", "taker"),
|
||||
("entry", "same", "market", "taker"),
|
||||
("exit", "same", "market", "taker"),
|
||||
("entry", "other", "market", "taker"),
|
||||
("exit", "other", "market", "taker"),
|
||||
("stoploss", "same", "market", "taker"),
|
||||
("stoploss", "other", "market", "taker"),
|
||||
])
|
||||
def test_taker_or_maker(mocker, default_conf, order_reason, price_side, order_type, taker_or_maker):
|
||||
if order_reason != 'stoploss':
|
||||
default_conf[f"{order_reason}_pricing"]["price_side"] = price_side
|
||||
default_conf["order_types"] = {}
|
||||
default_conf["order_types"][order_reason] = order_type
|
||||
exchange = get_patched_exchange(mocker, default_conf)
|
||||
assert exchange.taker_or_maker(order_reason) == taker_or_maker
|
||||
|
Loading…
Reference in New Issue
Block a user