import {z} from 'zod' export type GetApiApiPropfirmsSuggestedStrategiesArgs = {productType?: string | undefined}; export type GetApiApiPropfirmsSuggestedStrategiesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiPropfirmsSuggestedStrategiesResponse = z.object({data: z.object({strategies: z.array(z.object({propfirmId: z.string(), propfirmName: z.string(), id: z.string(), startDate: z.string().nullable(), ticker: z.string(), timeframe: z.number().nullable(), netProfit: z.number().nullable(), closedTrades: z.number().nullable(), winrate: z.number().nullable(), profitFactor: z.number().nullable(), maxDrawdownPct: z.number().nullable(), avgTrade: z.number().nullable(), avgWinningTrade: z.number().nullable(), avgLosingTrade: z.number().nullable(), longConditions: z.array(z.string()), shortConditions: z.array(z.string()), currency: z.string(), historicalNetProfit: z.array(z.number()).nullable(), productType: z.enum(["Futures", "CFD"])}))}), errors: z.unknown()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Public: suggested backtesting strategies per propfirm, optionally filtered by product type * * GET /api/propfirms/suggested-strategies */ export const getApiApiPropfirmsSuggestedStrategies = async (args: GetApiApiPropfirmsSuggestedStrategiesArgs, options?: GetApiApiPropfirmsSuggestedStrategiesOptions) => { const {baseUrl = "https://app.luxalgo.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.productType != null) query.append("productType", String(args.productType)) const url = `${baseUrl.replace(/\/+$/, '')}/api/propfirms/suggested-strategies${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiApiPropfirmsSuggestedStrategiesResponse, await res.json()) };