- Add withdrawal stage system: each stage defines profit target, consistency, and min trading days for post-withdrawal challenge cycles - Target Same Equity mode accounts for withdrawn amounts when computing effective profit target (profitTarget - remainingProfit) - Store fund transaction timestamps for time-aware cycle filtering (withdrawals before 9 AM CT include that day in new cycle) - Expose full P&L history (fullDailyPnL) for calendar/equity curve display across all cycles, with DB fallback for pre-restart data - Show stage number (#1, #2, etc.) on calendar cells - Hide consistency reference line when consistency is 0% or 100% - Settings UI: "After First W/D" column with same-equity checkbox, expandable stage sub-rows with profit/consistency/days inputs - Default target_same_equity to 1 for new and existing account configs Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
65 lines
2.0 KiB
TypeScript
65 lines
2.0 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { getFirmById, deleteFirm } from '@/lib/db';
|
|
import { removeClient } from '@/lib/clients';
|
|
|
|
export async function GET(
|
|
_req: NextRequest,
|
|
{ params }: { params: Promise<{ id: string }> }
|
|
) {
|
|
const { id: idStr } = await params;
|
|
const id = parseInt(idStr, 10);
|
|
|
|
if (isNaN(id)) {
|
|
return NextResponse.json({ error: 'Invalid id' }, { status: 400 });
|
|
}
|
|
|
|
const firm = getFirmById(id);
|
|
if (!firm) {
|
|
return NextResponse.json({ error: 'Firm not found' }, { status: 404 });
|
|
}
|
|
|
|
return NextResponse.json({
|
|
id: firm.id,
|
|
firm: firm.name,
|
|
username: firm.username,
|
|
password: firm.password,
|
|
accounts: firm.accounts.map((a) => ({
|
|
id: a.id,
|
|
prefix: a.prefix,
|
|
profitTarget: a.profit_target,
|
|
consistency: a.consistency,
|
|
minDayPnL: a.min_day_pnl,
|
|
minTradingDays: a.min_trading_days,
|
|
accountSize: a.account_size,
|
|
maxLoss: a.max_loss,
|
|
maxPositionSize: a.max_position_size,
|
|
targetSameEquity: a.target_same_equity === 1,
|
|
withdrawalStages: (() => { try { return JSON.parse(a.withdrawal_stages ?? '[]') as { profit: number; consistency: number; minTradingDays: number }[]; } catch { return []; } })(),
|
|
})),
|
|
});
|
|
}
|
|
|
|
export async function DELETE(
|
|
_req: NextRequest,
|
|
{ params }: { params: Promise<{ id: string }> }
|
|
) {
|
|
const { id: idStr } = await params;
|
|
const id = parseInt(idStr, 10);
|
|
|
|
if (isNaN(id)) {
|
|
return NextResponse.json({ error: 'Invalid id' }, { status: 400 });
|
|
}
|
|
|
|
try {
|
|
const deleted = deleteFirm(id);
|
|
if (!deleted) {
|
|
return NextResponse.json({ error: 'Firm not found' }, { status: 404 });
|
|
}
|
|
removeClient(id);
|
|
return NextResponse.json({ success: true });
|
|
} catch (err) {
|
|
console.error('[DELETE /api/firms/:id]', err);
|
|
return NextResponse.json({ error: 'Failed to delete firm' }, { status: 500 });
|
|
}
|
|
}
|