Fix profit/loss calculation

This commit is contained in:
2023-01-06 08:52:15 +00:00
parent 1bab2a729b
commit ae42d9b223
4 changed files with 39 additions and 19 deletions

View File

@@ -163,7 +163,7 @@ class CommonTestCase(TestCase):
"""
Test that the SL price to percent conversion works for long trades.
"""
sl_price = 1.1 # 10%
sl_price = 0.9 # 10%
current_price = 1.0
current_units = 1
unrealised_pl = 0
@@ -176,7 +176,7 @@ class CommonTestCase(TestCase):
"""
Test that the SL price to percent conversion works for short trades.
"""
sl_price = 0.9 # 10%
sl_price = 1.1 # 10%
current_price = 1.0
current_units = 1
unrealised_pl = 0
@@ -219,7 +219,7 @@ class CommonTestCase(TestCase):
Test that the SL price to percent conversion works for long trades
with multiple units.
"""
sl_price = 1.1 # -10%
sl_price = 0.9 # -10%
current_price = 1.0
current_units = 10
unrealised_pl = 0
@@ -233,14 +233,14 @@ class CommonTestCase(TestCase):
Test that the SL price to percent conversion works for short trades
with multiple units.
"""
sl_price = 0.9 # -10%
sl_price = 1.2 # -20%
current_price = 1.0
current_units = 10
unrealised_pl = 0
percent = sl_price_to_percent(
sl_price, "short", current_price, current_units, unrealised_pl
)
self.assertEqual(percent, 10)
self.assertEqual(percent, 20)
def test_sl_price_to_percent_change_long_multi_profit(self):
"""