mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 02:12:01 +00:00
Add Properties for canceled orders to trade_model
This commit is contained in:
parent
dc92787f1d
commit
ec0f6cb246
|
@ -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.
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue
Block a user