1566b84379
Applies the backtest-validated trailing stop to live paper trading, and surfaces it transparently. Exit (A): - New paper-trade exit policy (paper_exit_mode=trailing, paper_trailing_pct=12), tunable in Admin → Paper-Trade Exit. resolve_open_trades runs a trailing stop (initial stop as floor, ratchets up from the peak; target ignored — the validated rule) and records close_reason (trailing|stop|target|manual; +migration 013). - list_trades enriches open trades with the live trailing-stop level + distance %. Open Trades panel shows the active tactic and a Trail Stop column. Alerts (B): - Daily digest now lists open trades with unrealized gain, trailing stop, and how far away it is. - New "trade closed" alert: one summary per auto-close (trailing/target/stop, not manual) — direction, reason, days held, P&L abs+%/R — covering wins AND stop-loss losses. Deduped by trade id; toggle in Admin alerts. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
30 lines
765 B
Python
30 lines
765 B
Python
"""add close_reason to paper_trades
|
|
|
|
Records how an open paper trade was closed (trailing | stop | target | manual) so
|
|
the close alert can summarise it and the UI can show why a position exited.
|
|
|
|
Revision ID: 013
|
|
Revises: 012
|
|
Create Date: 2026-06-30 00:00:00.000000
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = "013"
|
|
down_revision: Union[str, None] = "012"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.add_column("paper_trades", sa.Column("close_reason", sa.String(length=10), nullable=True))
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_column("paper_trades", "close_reason")
|