- lib/instrument-specs.ts (pure, tested): the CME specs — point value, tick size, one-tick spread, Yahoo ticker — replacing POINT_VALUES; the draw's maths; the 12-hour hold cap; the micro for drain and extra-day legs; reading a firm's list (the master's, or the old rules against an older master: this machine's enabled set less bans, the symbol map). - lib/instruments.ts: the one module the trading paths ask. Measures every future's daily move from Yahoo's hourly candles once per trade date, and shows entry cost (a tick of spread plus Tradovate's fee parameters or TopstepX's last measured fill) without ever choosing by it. - Futures Auto draws one root per batch from the batch firm's list: movement per dollar of spread early in the session with a 10% floor each, sliding to the fastest movers by the last entry; nothing expected to hold 12h or more; micros only if nothing else is listed. Every draw logs its odds. - The batch is chosen before its instrument, and a group that can't trade anything yields to the next. Copy trade matches the held contract against the listed roots and won't copy an instrument it can't identify. Manual legs, manual orders and drain/extra-day legs follow the lists. - DXtrade firms rank their own list whatever root was drawn. - Capabilities, the dashboard's trade bar and contract resolves follow the lists; the trade bar and scheduler default to Auto. The master link reconnects when master_dashboard_url changes, and the catalog drops ?since after a switch so two masters' versions can't collide. - Reports carry each futures firm's instrumentStats for the master's Firms page; GET /api/instruments shows them (?simulate=N runs the draw, no orders); the Settings page shows the lists read-only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
61 lines
2.5 KiB
TypeScript
61 lines
2.5 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
import { firmInstruments, instrumentsSource } from '@/lib/instruments';
|
|
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,
|
|
instruments: firmInstruments(firm),
|
|
instrumentsSource: instrumentsSource(firm),
|
|
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 });
|
|
}
|
|
}
|