import { getPlatformAccessToken } from './authSession'; import { tradingRuntime } from './runtime'; export interface StrategyPresetPayload { id: string; name: string; description: string; risk_style_id: string; recommended_assets: string[]; typical_trades_per_day: string; performance_tag: string; is_popular: boolean; created_by?: string; original_profile_id?: string; strategy_config: Record; } async function apiRequest(path: string, init?: RequestInit): Promise { const response = await fetch(`${tradingRuntime.tradingApiUrl}${path}`, { ...init, headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${getPlatformAccessToken()}`, ...(init?.headers || {}), }, }); const body = await response.json().catch(() => ({} as any)); if (!response.ok) { throw new Error(body?.error || `Request failed (${response.status})`); } return body as T; } export async function fetchMarketplacePresets(): Promise { const response = await apiRequest<{ presets: any[] }>('/api/marketplace-presets'); return Array.isArray(response.presets) ? response.presets : []; } export async function publishMarketplacePreset(payload: StrategyPresetPayload): Promise { await apiRequest<{ success: boolean }>('/api/marketplace-presets', { method: 'POST', body: JSON.stringify(payload), }); }