Remove leftover comments and debug statements

This commit is contained in:
Mark Veidemanis 2023-01-11 19:59:27 +00:00
parent 23faeb6f71
commit 9a69120695
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
3 changed files with 7 additions and 29 deletions

View File

@ -39,12 +39,9 @@ class OANDAExchange(BaseExchange):
def get_balance(self, return_usd=False): def get_balance(self, return_usd=False):
r = accounts.AccountSummary(self.account_id) r = accounts.AccountSummary(self.account_id)
response = self.call(r) response = self.call(r)
print("RESPONSE", response)
balance = float(response["balance"]) balance = float(response["balance"])
currency = response["currency"] currency = response["currency"]
balance_usd = common.to_currency("sell", self.account, balance, currency, "USD") balance_usd = common.to_currency("sell", self.account, balance, currency, "USD")
print("BALANCE", balance)
print("BALANCE USD", balance_usd)
common.get_balance_hook( common.get_balance_hook(
self.account.user.id, self.account.user.id,

View File

@ -61,11 +61,7 @@ def convert_trades_to_usd(account, trades):
side = trade["side"] side = trade["side"]
direction = side_to_direction(side) direction = side_to_direction(side)
base, quote = get_base_quote(account.exchange, symbol) base, quote = get_base_quote(account.exchange, symbol)
print("BASE", base)
print("QUOTE", quote)
print("AMOUNT", amount)
amount_usd = common.to_currency(direction, account, amount, base, "USD") amount_usd = common.to_currency(direction, account, amount, base, "USD")
print("TRADE AMOUNT USD", amount_usd)
trade["trade_amount_usd"] = amount_usd trade["trade_amount_usd"] = amount_usd
if "stop_loss_percent" in trade: if "stop_loss_percent" in trade:
trade["stop_loss_usd"] = (trade["stop_loss_percent"] / 100) * amount_usd trade["stop_loss_usd"] = (trade["stop_loss_percent"] / 100) * amount_usd
@ -303,6 +299,12 @@ def get_precision(account, symbol):
return (None, None) return (None, None)
# TODO: create_trade helper
# account, strategy, symbol, direction
# pull all data to create the trade from the strategy
# complete all crossfilter and risk management checks, etc.
def execute_strategy(callback, strategy, func): def execute_strategy(callback, strategy, func):
""" """
Execute a strategy. Execute a strategy.

View File

@ -9,18 +9,9 @@ def check_max_loss(risk_model, initial_balance, account_balance):
""" """
Check that the account balance is within the max loss limit. Check that the account balance is within the max loss limit.
""" """
# print("Max loss percent", risk_model.max_loss_percent)
# print("Initial balance", initial_balance)
# print("Account balance", account_balance)
# max_loss_percent = risk_model.max_loss_percent
# print("Max loss ratio", (max_loss_percent / 100))
# max_loss = initial_balance * (max_loss_percent / 100)
# print("Max loss", max_loss)
# return account_balance > max_loss
max_loss_percent = risk_model.max_loss_percent max_loss_percent = risk_model.max_loss_percent
# calculate the inverse of the max loss percent as a ratio # Calculate the inverse of the max loss percent as a ratio
inverse_loss_multiplier = 1 - max_loss_percent / 100 inverse_loss_multiplier = 1 - max_loss_percent / 100
minimum_balance = initial_balance * inverse_loss_multiplier minimum_balance = initial_balance * inverse_loss_multiplier
@ -32,10 +23,8 @@ def check_max_risk(risk_model, account_balance_usd, account_trades):
Check that all of the trades in the account are within the max risk limit. Check that all of the trades in the account are within the max risk limit.
""" """
max_risk_percent = D(risk_model.max_risk_percent) max_risk_percent = D(risk_model.max_risk_percent)
print("Max risk percent", max_risk_percent)
# Calculate the max risk of the account in USD # Calculate the max risk of the account in USD
max_risk_usd = account_balance_usd * (max_risk_percent / D(100)) max_risk_usd = account_balance_usd * (max_risk_percent / D(100))
print("Max risk USD", max_risk_usd)
total_risk = 0 total_risk = 0
for trade in account_trades: for trade in account_trades:
max_tmp = [] max_tmp = []
@ -47,12 +36,9 @@ def check_max_risk(risk_model, account_balance_usd, account_trades):
if "trailing_stop_loss_usd" in trade: if "trailing_stop_loss_usd" in trade:
max_tmp.append(trade["trailing_stop_loss_usd"]) max_tmp.append(trade["trailing_stop_loss_usd"])
if max_tmp: if max_tmp:
print("MAX TMP", max_tmp)
total_risk += max(max_tmp) total_risk += max(max_tmp)
print("total risk", total_risk)
allowed = total_risk < max_risk_usd allowed = total_risk < max_risk_usd
print("check amx risk allowed", allowed)
return allowed return allowed
@ -60,7 +46,6 @@ def check_max_open_trades(risk_model, account_trades):
""" """
Check that the number of trades in the account is within the max open trades limit. Check that the number of trades in the account is within the max open trades limit.
""" """
print("LEN ACCOUNT TRADES", len(account_trades))
return len(account_trades) < risk_model.max_open_trades return len(account_trades) < risk_model.max_open_trades
@ -75,7 +60,6 @@ def check_max_open_trades_per_symbol(risk_model, account_trades):
symbol_map[symbol] = 0 symbol_map[symbol] = 0
symbol_map[symbol] += 1 symbol_map[symbol] += 1
print("SUMBOL MAP", symbol_map)
for symbol, count in symbol_map.items(): for symbol, count in symbol_map.items():
if count >= risk_model.max_open_trades_per_symbol: if count >= risk_model.max_open_trades_per_symbol:
return False return False
@ -90,7 +74,6 @@ def check_risk(risk_model, account, proposed_trade):
max_loss_check = check_max_loss( max_loss_check = check_max_loss(
risk_model, account.initial_balance, account.client.get_balance() risk_model, account.initial_balance, account.client.get_balance()
) )
print("Max loss check", max_loss_check)
if not max_loss_check: if not max_loss_check:
return {"allowed": False, "reason": "Maximum loss exceeded."} return {"allowed": False, "reason": "Maximum loss exceeded."}
@ -104,7 +87,6 @@ def check_risk(risk_model, account, proposed_trade):
account_trades = market.convert_trades_to_usd(account, account_trades) account_trades = market.convert_trades_to_usd(account, account_trades)
max_open_trades_check = check_max_open_trades(risk_model, account_trades) max_open_trades_check = check_max_open_trades(risk_model, account_trades)
print("Max open trades check: ", max_open_trades_check)
if not max_open_trades_check: if not max_open_trades_check:
return {"allowed": False, "reason": "Maximum open trades exceeded."} return {"allowed": False, "reason": "Maximum open trades exceeded."}
@ -112,15 +94,12 @@ def check_risk(risk_model, account, proposed_trade):
max_open_trades_per_symbol_check = check_max_open_trades_per_symbol( max_open_trades_per_symbol_check = check_max_open_trades_per_symbol(
risk_model, account_trades risk_model, account_trades
) )
print("Max open trades per symbol check: ", max_open_trades_per_symbol_check)
if not max_open_trades_per_symbol_check: if not max_open_trades_per_symbol_check:
return {"allowed": False, "reason": "Maximum open trades per symbol exceeded."} return {"allowed": False, "reason": "Maximum open trades per symbol exceeded."}
# Check that the max risk is not exceeded # Check that the max risk is not exceeded
account_balance_usd = account.client.get_balance(return_usd=True) account_balance_usd = account.client.get_balance(return_usd=True)
print("Account balance USD (not)", account_balance_usd)
max_risk_check = check_max_risk(risk_model, account_balance_usd, account_trades) max_risk_check = check_max_risk(risk_model, account_balance_usd, account_trades)
print("Max risk check: ", max_risk_check)
if not max_risk_check: if not max_risk_check:
return {"allowed": False, "reason": "Maximum risk exceeded."} return {"allowed": False, "reason": "Maximum risk exceeded."}