These could be properties.

This commit is contained in:
Reigo Reinmets 2022-01-13 20:31:03 +02:00
parent 13bc5c5d8f
commit ffe69535d8
4 changed files with 12 additions and 9 deletions

View File

@ -476,8 +476,9 @@ class FreqtradeBot(LoggingMixin):
current_rate = self.exchange.get_rate(trade.pair, refresh=True, side="buy") current_rate = self.exchange.get_rate(trade.pair, refresh=True, side="buy")
current_profit = trade.calc_profit_ratio(current_rate) current_profit = trade.calc_profit_ratio(current_rate)
# FIXME This is only here to lazyload orders. # TODO: Is there a better way to force lazy-load?
trade.nr_of_successful_buys() len(trade.orders)
min_stake_amount = self.exchange.get_min_pair_stake_amount(trade.pair, min_stake_amount = self.exchange.get_min_pair_stake_amount(trade.pair,
current_rate, current_rate,
self.strategy.stoploss) self.strategy.stoploss)

View File

@ -614,6 +614,7 @@ class LocalTrade():
else: else:
return None return None
@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.
@ -623,6 +624,7 @@ class LocalTrade():
o.status in NON_OPEN_EXCHANGE_STATES and o.status in NON_OPEN_EXCHANGE_STATES and
(o.filled or 0) > 0]) (o.filled or 0) > 0])
@property
def nr_of_successful_sells(self) -> int: def nr_of_successful_sells(self) -> int:
""" """
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.

View File

@ -259,7 +259,7 @@ def test_dca_buying(default_conf_usdt, ticker_usdt, fee, mocker) -> None:
assert trade.amount == trade.orders[0].amount + trade.orders[1].amount assert trade.amount == trade.orders[0].amount + trade.orders[1].amount
assert trade.nr_of_successful_buys() == 2 assert trade.nr_of_successful_buys == 2
# Sell # Sell
patch_get_signal(freqtrade, value=(False, True, None, None)) patch_get_signal(freqtrade, value=(False, True, None, None))
@ -273,4 +273,4 @@ def test_dca_buying(default_conf_usdt, ticker_usdt, fee, mocker) -> None:
assert trade.orders[-1].side == 'sell' assert trade.orders[-1].side == 'sell'
assert trade.orders[2].amount == trade.amount assert trade.orders[2].amount == trade.amount
assert trade.nr_of_successful_buys() == 2 assert trade.nr_of_successful_buys == 2

View File

@ -1553,7 +1553,7 @@ def test_recalc_trade_from_orders_ignores_bad_orders(fee):
assert trade.open_rate == o1_rate assert trade.open_rate == o1_rate
assert trade.fee_open_cost == o1_fee_cost assert trade.fee_open_cost == o1_fee_cost
assert trade.open_trade_value == o1_trade_val assert trade.open_trade_value == o1_trade_val
assert trade.nr_of_successful_buys() == 1 assert trade.nr_of_successful_buys == 1
order2 = Order( order2 = Order(
ft_order_side='buy', ft_order_side='buy',
@ -1580,7 +1580,7 @@ def test_recalc_trade_from_orders_ignores_bad_orders(fee):
assert trade.open_rate == o1_rate assert trade.open_rate == o1_rate
assert trade.fee_open_cost == o1_fee_cost assert trade.fee_open_cost == o1_fee_cost
assert trade.open_trade_value == o1_trade_val assert trade.open_trade_value == o1_trade_val
assert trade.nr_of_successful_buys() == 1 assert trade.nr_of_successful_buys == 1
# Let's try with some other orders # Let's try with some other orders
order3 = Order( order3 = Order(
@ -1608,7 +1608,7 @@ def test_recalc_trade_from_orders_ignores_bad_orders(fee):
assert trade.open_rate == o1_rate assert trade.open_rate == o1_rate
assert trade.fee_open_cost == o1_fee_cost assert trade.fee_open_cost == o1_fee_cost
assert trade.open_trade_value == o1_trade_val assert trade.open_trade_value == o1_trade_val
assert trade.nr_of_successful_buys() == 1 assert trade.nr_of_successful_buys == 1
order4 = Order( order4 = Order(
ft_order_side='buy', ft_order_side='buy',
@ -1635,7 +1635,7 @@ def test_recalc_trade_from_orders_ignores_bad_orders(fee):
assert trade.open_rate == o1_rate assert trade.open_rate == o1_rate
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
# Just to make sure sell orders are ignored, let's calculate one more time. # Just to make sure sell orders are ignored, let's calculate one more time.
sell1 = Order( sell1 = Order(
@ -1662,4 +1662,4 @@ def test_recalc_trade_from_orders_ignores_bad_orders(fee):
assert trade.open_rate == o1_rate assert trade.open_rate == o1_rate
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