33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { getClients } from '@/lib/clients';
|
|
import axios from '@/lib/http-client';
|
|
|
|
export async function GET(
|
|
req: NextRequest,
|
|
{ params }: { params: Promise<{ id: string }> }
|
|
) {
|
|
try {
|
|
const { id: firmId } = await params;
|
|
const clients = getClients();
|
|
const client = clients.get(firmId) as any;
|
|
if (!client) return NextResponse.json({ error: 'Client not found' }, { status: 404 });
|
|
|
|
const symbol = req.nextUrl.searchParams.get('symbol') ?? 'NQ';
|
|
const accessToken = client.accessInfo?.accessToken;
|
|
if (!accessToken) return NextResponse.json({ error: 'Not authenticated' }, { status: 401 });
|
|
|
|
const res = await axios.get(
|
|
`https://demo.tradovateapi.com/v1/contract/suggest?t=${encodeURIComponent(symbol)}&l=20`,
|
|
{ headers: { Authorization: `Bearer ${accessToken}` } }
|
|
);
|
|
|
|
return NextResponse.json({
|
|
symbol,
|
|
contracts: res.data,
|
|
recentEntityEvents: client.recentEntityEvents ?? [],
|
|
});
|
|
} catch (err: any) {
|
|
return NextResponse.json({ error: err?.message }, { status: 500 });
|
|
}
|
|
}
|