Skip to content

Commit

Permalink
fix: oddly wrong fee_cost calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
xmatthias committed Aug 12, 2024
1 parent 6cf92c2 commit 7972a02
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion freqtrade/persistence/trade_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ def recalc_trade_from_orders(self, *, is_closing: bool = False):
self.open_rate = float(current_stake / current_amount)
self.amount = current_amount_tr
self.stake_amount = float(current_stake) / (self.leverage or 1.0)
self.fee_open_cost = self.fee_open * float(current_stake)
self.fee_open_cost = self.fee_open * float(self.max_stake_amount)
self.recalc_open_trade_value()
if self.stop_loss_pct is not None and self.open_rate is not None:
self.adjust_stop_loss(self.open_rate, self.stop_loss_pct)
Expand Down
6 changes: 3 additions & 3 deletions tests/persistence/test_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -2571,7 +2571,7 @@ def test_recalc_trade_from_orders_ignores_bad_orders(fee, is_short):
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.fee_open_cost == trade.nr_of_successful_entries * o1_fee_cost
assert trade.open_trade_value == 2 * o1_trade_val
assert trade.nr_of_successful_entries == 2

Expand All @@ -2598,7 +2598,7 @@ def test_recalc_trade_from_orders_ignores_bad_orders(fee, is_short):
assert trade.amount == o1_amount
assert trade.stake_amount == o1_amount
assert trade.open_rate == o1_rate
assert trade.fee_open_cost == o1_fee_cost
assert trade.fee_open_cost == trade.nr_of_successful_entries * o1_fee_cost
assert trade.open_trade_value == o1_trade_val
assert trade.nr_of_successful_entries == 2

Expand Down Expand Up @@ -2626,7 +2626,7 @@ def test_recalc_trade_from_orders_ignores_bad_orders(fee, is_short):
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.fee_open_cost == trade.nr_of_successful_entries * o1_fee_cost
assert trade.open_trade_value == 2 * o1_trade_val
assert trade.nr_of_successful_entries == 3

Expand Down

0 comments on commit 7972a02

Please sign in to comment.