- Auto-trade scheduler fires every 60s; uses Promise.allSettled batch so no new trades fire while any position from the current batch is open
- Commission gross-up: read entryCommission from cash.realizedPnL after fill (fallback 2.5×contracts), grossTarget = target + 2×entryCommission
- Sync gate: TradovateClient.syncComplete flag; scheduler skips tick until every client finishes initial position/balance sync
- Contracts formula changed to Math.ceil so $1500 target = 2 contracts
- Removed all fee caching (perContractFees, recentFills, fillFee handler) from tradovate-class.ts
- Removed firm_fees table, getFirmFees, upsertFirmFee from db.ts
- Deleted instrument-configs API routes; removed Fees UI from firm settings page
- /api/instruments returns full {symbol, enabled}[] objects; dashboard filters to enabled-only for trade selector
- Added auto-trade, debug, orders, settings, and trade API routes
- Instrument selector on dashboard now driven by enabled instruments from DB
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { runTrade, startScheduler } from '@/lib/auto-trade';
|
|
import { POINT_VALUES } from '@/lib/trading-logic';
|
|
|
|
export async function POST(req: NextRequest) {
|
|
try {
|
|
const body = await req.json() as { action: 'Buy' | 'Sell'; symbol: string };
|
|
const { action, symbol } = body;
|
|
|
|
if (!action || !symbol) {
|
|
return NextResponse.json({ error: 'Missing required fields: action, symbol' }, { status: 400 });
|
|
}
|
|
|
|
if (!POINT_VALUES[symbol]) {
|
|
return NextResponse.json({ error: `Unknown symbol: ${symbol}` }, { status: 400 });
|
|
}
|
|
|
|
// Execute trade immediately for all eligible accounts
|
|
const results = await runTrade(action, symbol);
|
|
|
|
// (Re)start the 60-second scheduler with this action + symbol
|
|
startScheduler(action, symbol);
|
|
|
|
return NextResponse.json(results);
|
|
} catch (err: any) {
|
|
console.error('[POST /api/trade]', err);
|
|
return NextResponse.json({ error: err?.message ?? 'Trade failed' }, { status: 500 });
|
|
}
|
|
}
|