Check the max risk relative to the account balance

This commit is contained in:
2023-01-06 07:20:55 +00:00
parent ae42d9b223
commit 93be9e6ffe
4 changed files with 136 additions and 44 deletions

View File

@@ -1,7 +1,6 @@
from decimal import Decimal as D
from core.lib.elastic import store_msg
from core.trading.market import to_currency
def get_balance_hook(user_id, user_name, account_id, account_name, balance):
@@ -89,9 +88,6 @@ def sl_price_to_percent(sl_price, side, current_price, current_units, unrealised
else:
profit = False
print("CHANGE PERCENT: ", change_percent)
print("PROFIT", profit)
if profit:
change_percent = 0 - abs(change_percent)
else:
@@ -120,6 +116,15 @@ def convert_open_trades(open_trades):
"pl": unrealised_pl,
}
# Add some extra fields, sometimes we have already looked up the
# prices and don't need to call convert_trades_to_usd
if "take_profit_usd" in trade:
cast["take_profit_usd"] = trade["take_profit_usd"]
if "stop_loss_usd" in trade:
cast["stop_loss_usd"] = trade["stop_loss_usd"]
if "trailing_stop_loss_usd" in trade:
cast["trailing_stop_loss_usd"] = trade["trailing_stop_loss_usd"]
if "takeProfitOrder" in trade:
if trade["takeProfitOrder"]:
take_profit = trade["takeProfitOrder"]["price"]
@@ -156,9 +161,3 @@ def convert_open_trades(open_trades):
trades.append(cast)
return trades
def convert_trades_to_usd(account, trades):
"""
Convert a list of trades to USD.
"""