Add Properties for canceled orders to trade_model

This commit is contained in:
Matthias 2024-05-25 20:05:29 +02:00
parent dc92787f1d
commit ec0f6cb246
2 changed files with 41 additions and 1 deletions

View File

@ -957,7 +957,24 @@ class LocalTrade:
def update_order(self, order: Dict) -> None:
Order.update_orders(self.orders, order)
def get_canceled_exit_order_count(self) -> int:
@property
def fully_canceled_entry_order_count(self) -> int:
"""
Get amount of failed exiting orders
assumes full exits.
"""
return len(
[
o
for o in self.orders
if o.ft_order_side == self.entry_side
and o.status in CANCELED_EXCHANGE_STATES
and o.filled == 0
]
)
@property
def canceled_exit_order_count(self) -> int:
"""
Get amount of failed exiting orders
assumes full exits.
@ -970,6 +987,13 @@ class LocalTrade:
]
)
def get_canceled_exit_order_count(self) -> int:
"""
Get amount of failed exiting orders
assumes full exits.
"""
return self.canceled_exit_order_count
def _calc_open_trade_value(self, amount: float, open_rate: float) -> float:
"""
Calculate the open_rate including open_fee.

View File

@ -1961,9 +1961,25 @@ def test_get_canceled_exit_order_count(fee, is_short):
trade = Trade.get_trades([Trade.pair == "ETC/BTC"]).first()
# No canceled order.
assert trade.get_canceled_exit_order_count() == 0
# Property returns the same result
assert trade.canceled_exit_order_count == 0
trade.orders[-1].status = "canceled"
assert trade.get_canceled_exit_order_count() == 1
assert trade.canceled_exit_order_count == 1
@pytest.mark.usefixtures("init_persistence")
@pytest.mark.parametrize("is_short", [True, False])
def test_fully_canceled_entry_order_count(fee, is_short):
create_mock_trades(fee, is_short=is_short)
trade = Trade.get_trades([Trade.pair == "ETC/BTC"]).first()
# No canceled order.
assert trade.fully_canceled_entry_order_count == 0
trade.orders[0].status = "canceled"
trade.orders[0].filled = 0
assert trade.fully_canceled_entry_order_count == 1
@pytest.mark.usefixtures("init_persistence")