add paper trading: mark a setup as taken, track open P&L, sell
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:
@@ -0,0 +1,29 @@
|
||||
import apiClient from './client';
|
||||
import type { PaperTrade } from '../lib/types';
|
||||
|
||||
export function listPaperTrades(status?: 'open' | 'closed') {
|
||||
return apiClient
|
||||
.get<PaperTrade[]>('paper-trades', { params: status ? { status } : {} })
|
||||
.then((r) => r.data);
|
||||
}
|
||||
|
||||
export interface CreatePaperTradeBody {
|
||||
symbol: string;
|
||||
direction: 'long' | 'short';
|
||||
entry_price: number;
|
||||
shares: number;
|
||||
stop_loss: number;
|
||||
target: number;
|
||||
}
|
||||
|
||||
export function createPaperTrade(body: CreatePaperTradeBody) {
|
||||
return apiClient.post<PaperTrade>('paper-trades', body).then((r) => r.data);
|
||||
}
|
||||
|
||||
export function closePaperTrade(id: number, closePrice?: number) {
|
||||
return apiClient
|
||||
.post<{ id: number; status: string }>(`paper-trades/${id}/close`, {
|
||||
close_price: closePrice ?? null,
|
||||
})
|
||||
.then((r) => r.data);
|
||||
}
|
||||
Reference in New Issue
Block a user