add paper trading: mark a setup as taken, track open P&L, sell
Deploy / lint (push) Successful in 5s
Deploy / test (push) Successful in 35s
Deploy / deploy (push) Successful in 24s

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>
This commit is contained in:
2026-06-16 06:33:56 +02:00
parent 050abc6f71
commit a69557f5d8
16 changed files with 736 additions and 1 deletions
+35
View File
@@ -0,0 +1,35 @@
"""Schemas for paper trades."""
from __future__ import annotations
from datetime import datetime
from pydantic import BaseModel, Field
class PaperTradeCreate(BaseModel):
symbol: str = Field(..., min_length=1, max_length=10)
direction: str = Field(..., pattern=r"^(long|short)$")
entry_price: float = Field(..., gt=0)
shares: float = Field(..., gt=0)
stop_loss: float = Field(..., gt=0)
target: float = Field(..., gt=0)
class PaperTradeClose(BaseModel):
close_price: float | None = Field(default=None, gt=0)
class PaperTradeResponse(BaseModel):
id: int
symbol: str
direction: str
entry_price: float
shares: float
stop_loss: float
target: float
status: str
opened_at: datetime
close_price: float | None = None
closed_at: datetime | None = None
current_price: float | None = None