Files
autofirmer-expanded/app/api/firms/route.ts
T
Brandon LiandClaude Opus 5.5 a2cd3a94c9 Legs: cheapest symbol that reaches the target hold, last stands, a reserve that grows with size
- A batch sizes its leg on every mapped candidate, each at the leverage
  the broker states for it, and trades the cheapest (spread, commissions,
  expected swap) that reaches the target hold — else the quickest. The
  dashboard ranks the same way from a half-hourly candidate survey.
- Last stand: when a daily-loss stop-out would leave the account within
  15% of that loss above its max-drawdown floor (the account type's static
  max loss, or the broker's liquidation floor), the leg carries no
  daily-loss stop and is sized against the firm's own breach.
- The daily-loss reserve is 10% of the limit or 0.1% of the position,
  whichever is more, since a stop's slippage grows with the position.
- The account type's max notional is gone: the broker's margin rates cap
  each symbol. planLegSize holds the one sizing rule fireLeg, the pick and
  the dashboard share.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 18:26:12 -05:00

59 lines
2.4 KiB
TypeScript

import { NextResponse } from 'next/server';
import { getCachedCatalog, hasPlatformCredentials } from '@/lib/firm-catalog';
import { getCredentials } from '@/lib/db';
import type { FirmConfig } from '@/types';
/**
* The firms this machine knows about — the master's catalog, annotated with
* whether credentials for each are stored here.
*
* Firms are created and edited on the master dashboard; there is no POST. The
* only writable thing per firm is its credentials, at
* PUT /api/firms/[id]/credentials.
*
* The stored password is deliberately not returned. It used to be, and nothing
* ever read it.
*/
export async function GET() {
try {
const result: FirmConfig[] = getCachedCatalog().map((firm) => {
const creds = getCredentials(firm.id);
const hasCredentials = hasPlatformCredentials(firm.platform, creds);
return {
id: firm.id,
firm: firm.name,
platform: firm.platform,
username: creds?.username ?? '',
hasCredentials,
bannedSymbols: firm.bannedSymbols,
accounts: firm.accountTypes.map((a) => ({
id: a.id,
label: a.label,
prefix: a.prefix,
profitTarget: a.profitTarget,
consistency: a.consistency,
minDayPnL: a.minDayPnL,
minTradingDays: a.minTradingDays,
accountSize: a.accountSize,
maxLoss: a.maxLoss,
maxPositionSize: a.maxPositionSize,
targetSameEquity: a.targetSameEquity,
splitEnabled: a.splitEnabled,
minLegs: a.minLegs,
firstDayStop: a.firstDayStop,
minDayStop: a.minDayStop,
combineCmeHolidays: a.combineCmeHolidays,
withdrawalStages: a.withdrawalStages,
dailyLossLimit: a.dailyLossLimit ?? 0,
tradesEveryDay: a.tradesEveryDay === true,
})),
catalogUpdatedAt: firm.updatedAt,
};
});
return NextResponse.json(result);
} catch (err) {
console.error('[GET /api/firms]', err);
return NextResponse.json({ error: 'Failed to fetch firms' }, { status: 500 });
}
}