Fix trade log equity_after to chain from initial capital by close time.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1241,7 +1241,7 @@ def close_position(pid):
|
||||
result = classify_close_result(direction, close_price, sl, tp)
|
||||
minutes = holding_to_minutes(open_time, close_time)
|
||||
margin_pct = metrics.get("position_pct")
|
||||
from trade_log_lib import calc_equity_after
|
||||
from trade_log_lib import calc_equity_after, refresh_trade_log_equity_chain
|
||||
equity_after = calc_equity_after(capital, pnl_net)
|
||||
conn.execute(
|
||||
"""INSERT INTO trade_logs
|
||||
@@ -1258,6 +1258,10 @@ def close_position(pid):
|
||||
),
|
||||
)
|
||||
conn.execute("DELETE FROM position_monitors WHERE id=?", (pid,))
|
||||
try:
|
||||
refresh_trade_log_equity_chain(conn, capital if capital > 0 else None)
|
||||
except Exception as exc:
|
||||
app.logger.debug("equity chain refresh after close: %s", exc)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
touch_stats_cache()
|
||||
@@ -1301,6 +1305,11 @@ def update_trade(tid):
|
||||
tid,
|
||||
),
|
||||
)
|
||||
try:
|
||||
cap = float(get_setting("live_capital", "0") or 0)
|
||||
refresh_trade_log_equity_chain(conn, cap if cap > 0 else None)
|
||||
except Exception as exc:
|
||||
app.logger.debug("equity chain refresh after trade edit: %s", exc)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
touch_stats_cache()
|
||||
|
||||
Reference in New Issue
Block a user