|
|
|
@ -61,22 +61,28 @@ def sl_price_to_percent(sl_price, side, current_price, current_units, unrealised
|
|
|
|
|
change_percent = ((initial_price - D(sl_price)) / initial_price) * 100
|
|
|
|
|
|
|
|
|
|
# If the trade is long, the SL price will be higher than the initial price.
|
|
|
|
|
if side == "long":
|
|
|
|
|
change_percent *= -1
|
|
|
|
|
# if side == "long":
|
|
|
|
|
# change_percent *= -1
|
|
|
|
|
|
|
|
|
|
if side == "long":
|
|
|
|
|
if current_price > initial_price:
|
|
|
|
|
if D(current_price) > initial_price:
|
|
|
|
|
profit = True
|
|
|
|
|
else:
|
|
|
|
|
profit = False
|
|
|
|
|
else:
|
|
|
|
|
if current_price < initial_price:
|
|
|
|
|
if D(current_price) < initial_price:
|
|
|
|
|
profit = True
|
|
|
|
|
else:
|
|
|
|
|
profit = False
|
|
|
|
|
|
|
|
|
|
if profit:
|
|
|
|
|
change_percent *= -1
|
|
|
|
|
# if we are in profit on the short side, we want to show a negative loss
|
|
|
|
|
if profit and side == "short":
|
|
|
|
|
# change_percent *= -1
|
|
|
|
|
change_percent = 0 - abs(change_percent)
|
|
|
|
|
# if we are in loss on the long side, we want to show a positive loss
|
|
|
|
|
if not profit and side == "long":
|
|
|
|
|
# change_percent *= -1
|
|
|
|
|
change_percent = abs(change_percent)
|
|
|
|
|
|
|
|
|
|
return round(change_percent, 5)
|
|
|
|
|
|
|
|
|
|