- DB migration: ALTER TABLE account_configs ADD COLUMN max_position_size INTEGER NOT NULL DEFAULT 0 - Added max_position_size to AccountConfigRow, createAccountConfig, updateAccountConfig in lib/db.ts - Added maxPositionSize to AccountConfig type in types.ts (0 = no limit) - GET /api/firms/[id] now returns maxPositionSize per account - POST /api/firms/[id]/accounts and PUT /api/account-configs/[id] accept maxPositionSize - Firm settings page: new Max Contracts column (blank = no limit) - auto-trade: contracts capped at maxPositionSize when > 0 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
63 lines
1.8 KiB
TypeScript
63 lines
1.8 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,
|
|
})),
|
|
});
|
|
}
|
|
|
|
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 });
|
|
}
|
|
}
|