Write protection check tests
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
from decimal import Decimal as D
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from core.exchanges.convert import sl_price_to_percent, tp_price_to_percent
|
||||
from core.exchanges.convert import (
|
||||
sl_percent_to_price,
|
||||
sl_price_to_percent,
|
||||
tp_percent_to_price,
|
||||
tp_price_to_percent,
|
||||
)
|
||||
|
||||
|
||||
class CommonTestCase(TestCase):
|
||||
@@ -247,25 +254,39 @@ class CommonTestCase(TestCase):
|
||||
Test that the SL price to percent conversion works for long trades
|
||||
when the price has changed, with multiple units, and the SL is at a profit.
|
||||
"""
|
||||
sl_price = 1.2 # +20%
|
||||
sl_price = D(1.2) # +20%
|
||||
current_price = 1.1 # +10%
|
||||
current_units = 10
|
||||
unrealised_pl = 1 # +10%
|
||||
expected_percent = -20
|
||||
percent = sl_price_to_percent(
|
||||
sl_price, "long", current_price, current_units, unrealised_pl
|
||||
)
|
||||
self.assertEqual(percent, -20)
|
||||
self.assertEqual(percent, expected_percent)
|
||||
self.assertEqual(
|
||||
tp_percent_to_price(
|
||||
expected_percent, "long", current_price, current_units, unrealised_pl
|
||||
),
|
||||
sl_price,
|
||||
)
|
||||
|
||||
def test_sl_price_to_percent_change_short_multi_profit(self):
|
||||
"""
|
||||
Test that the SL price to percent conversion works for short trades
|
||||
when the price has changed, with multiple units, and the SL is at a profit.
|
||||
"""
|
||||
sl_price = 0.8 # -20%
|
||||
sl_price = D(0.8) # -20%
|
||||
current_price = 0.9 # +10%
|
||||
current_units = 10
|
||||
unrealised_pl = 1 # +10%
|
||||
expected_percent = -20
|
||||
percent = sl_price_to_percent(
|
||||
sl_price, "short", current_price, current_units, unrealised_pl
|
||||
)
|
||||
self.assertEqual(percent, -20)
|
||||
self.assertEqual(percent, expected_percent)
|
||||
self.assertEqual(
|
||||
tp_percent_to_price(
|
||||
expected_percent, "short", current_price, current_units, unrealised_pl
|
||||
),
|
||||
sl_price,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user