Files
autofirmer-expanded/app/api/trade/route.ts
T
SenofyandClaude Sonnet 4.6 a13096ea86 Add Random direction option — picks Buy or Sell once per batch
All accounts in the same batch trade the same resolved direction.
Each new batch (after positions are flat) picks a fresh random direction.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-10 03:35:50 -05:00

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' | 'Random'; 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 });
}
}