Unify functions and make it easy to get a list of filled buy orders
This commit is contained in:
parent
08cae6f067
commit
320c9ccf90
@ -614,15 +614,25 @@ class LocalTrade():
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def select_filled_orders(self, order_side: str) -> List['Order']:
|
||||||
|
"""
|
||||||
|
Finds filled orders for this orderside.
|
||||||
|
:param order_side: Side of the order (either 'buy' or 'sell')
|
||||||
|
:return: array of Order objects
|
||||||
|
"""
|
||||||
|
return [o for o in self.orders if o.ft_order_side == order_side and
|
||||||
|
o.ft_is_open is False and
|
||||||
|
(o.filled or 0) > 0 and
|
||||||
|
o.status in NON_OPEN_EXCHANGE_STATES]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def nr_of_successful_buys(self) -> int:
|
def nr_of_successful_buys(self) -> int:
|
||||||
"""
|
"""
|
||||||
Helper function to count the number of buy orders that have been filled.
|
Helper function to count the number of buy orders that have been filled.
|
||||||
:return: int count of buy orders that have been filled for this trade.
|
:return: int count of buy orders that have been filled for this trade.
|
||||||
"""
|
"""
|
||||||
return len([o for o in self.orders if o.ft_order_side == 'buy' and
|
|
||||||
o.status in NON_OPEN_EXCHANGE_STATES and
|
return len(self.select_filled_orders('buy'))
|
||||||
(o.filled or 0) > 0])
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def nr_of_successful_sells(self) -> int:
|
def nr_of_successful_sells(self) -> int:
|
||||||
@ -630,9 +640,7 @@ class LocalTrade():
|
|||||||
Helper function to count the number of sell orders that have been filled.
|
Helper function to count the number of sell orders that have been filled.
|
||||||
:return: int count of sell orders that have been filled for this trade.
|
:return: int count of sell orders that have been filled for this trade.
|
||||||
"""
|
"""
|
||||||
return len([o for o in self.orders if o.ft_order_side == 'sell' and
|
return len(self.select_filled_orders('sell'))
|
||||||
o.status in NON_OPEN_EXCHANGE_STATES and
|
|
||||||
(o.filled or 0) > 0])
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_trades_proxy(*, pair: str = None, is_open: bool = None,
|
def get_trades_proxy(*, pair: str = None, is_open: bool = None,
|
||||||
|
@ -1663,3 +1663,49 @@ def test_recalc_trade_from_orders_ignores_bad_orders(fee):
|
|||||||
assert trade.fee_open_cost == 2 * o1_fee_cost
|
assert trade.fee_open_cost == 2 * o1_fee_cost
|
||||||
assert trade.open_trade_value == 2 * o1_trade_val
|
assert trade.open_trade_value == 2 * o1_trade_val
|
||||||
assert trade.nr_of_successful_buys == 2
|
assert trade.nr_of_successful_buys == 2
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("init_persistence")
|
||||||
|
def test_select_filled_orders(fee):
|
||||||
|
create_mock_trades(fee)
|
||||||
|
|
||||||
|
trades = Trade.get_trades().all()
|
||||||
|
|
||||||
|
# Closed buy order, no sell order
|
||||||
|
orders = trades[0].select_filled_orders('buy')
|
||||||
|
assert orders is not None
|
||||||
|
assert len(orders) == 1
|
||||||
|
order = orders[0]
|
||||||
|
assert order.amount > 0
|
||||||
|
assert order.filled > 0
|
||||||
|
assert order.side == 'buy'
|
||||||
|
assert order.ft_order_side == 'buy'
|
||||||
|
assert order.status == 'closed'
|
||||||
|
orders = trades[0].select_filled_orders('sell')
|
||||||
|
assert orders is not None
|
||||||
|
assert len(orders) == 0
|
||||||
|
|
||||||
|
# closed buy order, and closed sell order
|
||||||
|
orders = trades[1].select_filled_orders('buy')
|
||||||
|
assert orders is not None
|
||||||
|
assert len(orders) == 1
|
||||||
|
|
||||||
|
orders = trades[1].select_filled_orders('sell')
|
||||||
|
assert orders is not None
|
||||||
|
assert len(orders) == 1
|
||||||
|
|
||||||
|
# Has open buy order
|
||||||
|
orders = trades[3].select_filled_orders('buy')
|
||||||
|
assert orders is not None
|
||||||
|
assert len(orders) == 0
|
||||||
|
orders = trades[3].select_filled_orders('sell')
|
||||||
|
assert orders is not None
|
||||||
|
assert len(orders) == 0
|
||||||
|
|
||||||
|
# Open sell order
|
||||||
|
orders = trades[4].select_filled_orders('buy')
|
||||||
|
assert orders is not None
|
||||||
|
assert len(orders) == 1
|
||||||
|
orders = trades[4].select_filled_orders('sell')
|
||||||
|
assert orders is not None
|
||||||
|
assert len(orders) == 0
|
||||||
|
Loading…
Reference in New Issue
Block a user