Added min_stake, max_stake. Removed pair as its included in trade.

This commit is contained in:
Reigo Reinmets
2022-01-08 17:20:02 +02:00
parent 813a2cd23b
commit 0bca07a32a
7 changed files with 69 additions and 29 deletions

View File

@@ -162,12 +162,12 @@ class StrategyTestV2(IStrategy):
'sell'] = 1
return dataframe
def adjust_trade_position(self, pair: str, trade: Trade, current_time: datetime,
current_rate: float, current_profit: float, **kwargs):
def adjust_trade_position(self, trade: Trade, current_time: datetime, current_rate: float,
current_profit: float, min_stake: float, max_stake: float, **kwargs):
if current_profit < -0.0075:
try:
return self.wallets.get_trade_stake_amount(pair, None)
return self.wallets.get_trade_stake_amount(trade.pair, None)
except DependencyException:
pass

View File

@@ -259,6 +259,8 @@ 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.nr_of_successful_buys() == 2
# Sell
patch_get_signal(freqtrade, value=(False, True, None, None))
freqtrade.process()
@@ -270,3 +272,5 @@ def test_dca_buying(default_conf_usdt, ticker_usdt, fee, mocker) -> None:
# Sold everything
assert trade.orders[-1].side == 'sell'
assert trade.orders[2].amount == trade.amount
assert trade.nr_of_successful_buys() == 2

View File

@@ -1553,20 +1553,21 @@ def test_recalc_trade_from_orders_ignores_bad_orders(fee):
assert trade.open_rate == o1_rate
assert trade.fee_open_cost == o1_fee_cost
assert trade.open_trade_value == o1_trade_val
assert trade.nr_of_successful_buys() == 1
order2 = Order(
ft_order_side='buy',
ft_pair=trade.pair,
ft_is_open=True,
status="closed",
status="open",
symbol=trade.pair,
order_type="market",
side="buy",
price=1,
average=2,
filled=0,
remaining=4,
cost=5,
price=o1_rate,
average=o1_rate,
filled=o1_amount,
remaining=0,
cost=o1_cost,
order_date=arrow.utcnow().shift(hours=-1).datetime,
order_filled_date=arrow.utcnow().shift(hours=-1).datetime,
)
@@ -1579,8 +1580,9 @@ def test_recalc_trade_from_orders_ignores_bad_orders(fee):
assert trade.open_rate == o1_rate
assert trade.fee_open_cost == o1_fee_cost
assert trade.open_trade_value == o1_trade_val
assert trade.nr_of_successful_buys() == 1
# Let's try with some other orders
# Let's try with some other orders
order3 = Order(
ft_order_side='buy',
ft_pair=trade.pair,
@@ -1606,6 +1608,34 @@ def test_recalc_trade_from_orders_ignores_bad_orders(fee):
assert trade.open_rate == o1_rate
assert trade.fee_open_cost == o1_fee_cost
assert trade.open_trade_value == o1_trade_val
assert trade.nr_of_successful_buys() == 1
order4 = Order(
ft_order_side='buy',
ft_pair=trade.pair,
ft_is_open=False,
status="closed",
symbol=trade.pair,
order_type="market",
side="buy",
price=o1_rate,
average=o1_rate,
filled=o1_amount,
remaining=0,
cost=o1_cost,
order_date=arrow.utcnow().shift(hours=-1).datetime,
order_filled_date=arrow.utcnow().shift(hours=-1).datetime,
)
trade.orders.append(order4)
trade.recalc_trade_from_orders()
# Validate that the trade values have been changed
assert trade.amount == 2 * o1_amount
assert trade.stake_amount == 2 * o1_amount
assert trade.open_rate == o1_rate
assert trade.fee_open_cost == 2 * o1_fee_cost
assert trade.open_trade_value == 2 * o1_trade_val
assert trade.nr_of_successful_buys() == 2
# Just to make sure sell orders are ignored, let's calculate one more time.
sell1 = Order(
@@ -1627,8 +1657,10 @@ def test_recalc_trade_from_orders_ignores_bad_orders(fee):
trade.orders.append(sell1)
trade.recalc_trade_from_orders()
assert trade.amount == o1_amount
assert trade.stake_amount == o1_amount
assert trade.amount == 2 * o1_amount
assert trade.stake_amount == 2 * o1_amount
assert trade.open_rate == o1_rate
assert trade.fee_open_cost == o1_fee_cost
assert trade.open_trade_value == o1_trade_val
assert trade.fee_open_cost == 2 * o1_fee_cost
assert trade.open_trade_value == 2 * o1_trade_val
assert trade.nr_of_successful_buys() == 2