30effa89b7
Three usability fixes: 1. Global ticker search in the sidebar (TickerSearch) — typeahead over the tracked universe that opens a ticker's detail page without adding it to the watchlist. Also wired into the mobile nav. 2. Watchlist table shows the ticker's 12-1 momentum percentile (the top-pick selector) instead of the noisy full S/R-level list. Enriched from the setup already loaded in watchlist_service._enrich_entry — no extra query. 3. Alpha vs the S&P 500 on paper trades (open + closed). New benchmark_prices table + benchmark_service store SPY daily closes (a standalone series, not a Ticker, so it never enters the scanner / momentum ranking / rankings) via a new daily-pipeline step. paper_trade_service computes per-trade benchmark_return / alpha_pct / alpha_usd over each holding period; the open- trades table, dashboard, and closed-trades panel surface per-trade and total alpha. The list read path never makes a provider call. Deploy: alembic upgrade head, then run the benchmark/daily job once to populate SPY closes (alpha shows "—" until then). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
"""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
|
|
# Alpha vs the S&P 500 (SPY) over the trade's holding period. None when the
|
|
# benchmark series doesn't cover the trade's open date yet.
|
|
benchmark_return_pct: float | None = None
|
|
alpha_pct: float | None = None
|
|
alpha_usd: float | None = None
|