Files
autofirmer-expanded/app/api/account-configs/[id]/route.ts
T
SenofyandClaude Sonnet 4.6 dd18f91584 Add full Next.js autotrader app with SQLite persistence and live Tradovate data
- 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>
2026-03-08 15:03:21 -05:00

82 lines
2.4 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import { updateAccountConfig, deleteAccountConfig } from '@/lib/db';
export async function PUT(
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 body = await req.json() as {
prefix?: string;
profitTarget?: number;
consistency?: number;
minDayPnL?: number;
minTradingDays?: number;
accountSize?: number;
maxLoss?: number;
};
const { prefix, profitTarget, consistency, minDayPnL, minTradingDays, accountSize, maxLoss } = body;
if (
typeof prefix !== 'string' || !prefix.trim() ||
typeof profitTarget !== 'number' ||
typeof consistency !== 'number' ||
typeof minDayPnL !== 'number' ||
typeof minTradingDays !== 'number' ||
typeof accountSize !== 'number'
) {
return NextResponse.json({ error: 'Invalid body' }, { status: 400 });
}
try {
const updated = updateAccountConfig(id, {
prefix: prefix.trim(),
profitTarget,
consistency,
minDayPnL,
minTradingDays,
accountSize,
maxLoss: maxLoss ?? 0,
});
if (!updated) {
return NextResponse.json({ error: 'Account config not found' }, { status: 404 });
}
return NextResponse.json({ success: true });
} catch (err) {
console.error('[PUT /api/account-configs/:id]', err);
return NextResponse.json({ error: 'Failed to update' }, { status: 500 });
}
}
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 = deleteAccountConfig(id);
if (!deleted) {
return NextResponse.json({ error: 'Account config not found' }, { status: 404 });
}
return NextResponse.json({ success: true });
} catch (err) {
console.error('[DELETE /api/account-configs/:id]', err);
return NextResponse.json({ error: 'Failed to delete' }, { status: 500 });
}
}