a69557f5d8
New paper_trades table (migration 007) + service/router. "Mark as taken" on each setup card (shares prefilled from position sizing, entry from current price, both editable) records a simulated trade. Overview gains an Open Trades table that marks each position to the latest close — P&L in $, %, and R-multiples — with a total unrealized P&L footer and a Sell button to close at the current price. Closed trades are retained for future realized-P&L reporting. Deploy: alembic upgrade (new paper_trades table). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
"""add paper_trades table
|
|
|
|
Revision ID: 007
|
|
Revises: 006
|
|
Create Date: 2026-06-16 00:00:00.000000
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = "007"
|
|
down_revision: Union[str, None] = "006"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"paper_trades",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("user_id", sa.Integer(), nullable=False),
|
|
sa.Column("ticker_id", sa.Integer(), nullable=False),
|
|
sa.Column("direction", sa.String(length=10), nullable=False),
|
|
sa.Column("entry_price", sa.Float(), nullable=False),
|
|
sa.Column("shares", sa.Float(), nullable=False),
|
|
sa.Column("stop_loss", sa.Float(), nullable=False),
|
|
sa.Column("target", sa.Float(), nullable=False),
|
|
sa.Column("status", sa.String(length=10), nullable=False),
|
|
sa.Column("opened_at", sa.DateTime(timezone=True), nullable=False),
|
|
sa.Column("close_price", sa.Float(), nullable=True),
|
|
sa.Column("closed_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
|
|
sa.ForeignKeyConstraint(["ticker_id"], ["tickers.id"], ondelete="CASCADE"),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index("ix_paper_trades_user_status", "paper_trades", ["user_id", "status"])
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index("ix_paper_trades_user_status", table_name="paper_trades")
|
|
op.drop_table("paper_trades")
|