- SQLite DB (better-sqlite3) with firms, account_configs, firm_fees, instruments tables - REST API routes: firms CRUD, account configs CRUD, state, accounts, instruments - Live Tradovate WebSocket client: login, sync, positions, auto-liq thresholds - Dashboard (app/page.tsx): per-firm account list with balance, day P&L, days traded, target progress, and Dead/Inactive/Flat status based on Tradovate auto-liq floors - Account detail page: objectives progress, daily P&L chart, consistency tracking - Per-firm settings page: account configs and instrument fee management - Dead detection uses trailingMaxDrawdownLimit - trailingMaxDrawdown from userAccountAutoLiqs; filters Tradovate sentinel value (999999999 = no limit) - FIFO P&L engine with commission accounting for daily P&L history - Removed manual maxLoss fallback in favour of live Tradovate auto-liq data Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
61 lines
1.7 KiB
TypeScript
61 lines
1.7 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,
|
|
})),
|
|
});
|
|
}
|
|
|
|
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 });
|
|
}
|
|
}
|