import {z} from 'zod' export type GetApiRestApiV1ProjectsProjectIdEconomicCalendarExposureArgs = {projectId: string, accountId: string, days?: number | undefined, impact?: string | undefined}; export type GetApiRestApiV1ProjectsProjectIdEconomicCalendarExposureOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const calendarExposureEventDTO = z.object({currencyCode: z.string().optional(), eventId: z.string().optional(), eventTimeUtc: z.string().optional(), floatingProfit: z.number().optional(), impact: z.enum(["HOLIDAY", "LOW", "MEDIUM", "HIGH"]).optional(), margin: z.number().optional(), positions: z.number().int().optional(), symbols: z.array(z.string()).optional(), title: z.string().optional(), volume: z.number().optional()}); export const calendarExposureDTO = z.object({asOfUtc: z.string().optional(), events: z.array(calendarExposureEventDTO).optional(), fromUtc: z.string().optional(), openPositions: z.number().int().optional(), toUtc: z.string().optional(), unresolvedSymbols: z.array(z.string()).optional()}); 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 }; /** * Which upcoming releases hit the open positions * * GET /rest/api/v1/projects/{projectId}/economicCalendar/exposure */ export const getApiRestApiV1ProjectsProjectIdEconomicCalendarExposure = async (args: GetApiRestApiV1ProjectsProjectIdEconomicCalendarExposureArgs, options?: GetApiRestApiV1ProjectsProjectIdEconomicCalendarExposureOptions) => { const {baseUrl = "https://api.metacopier.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.accountId != null) query.append("accountId", String(args.accountId)) if (args.days != null) query.append("days", String(args.days)) if (args.impact != null) query.append("impact", String(args.impact)) if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/rest/api/v1/projects/${encodeURIComponent(String(args.projectId))}/economicCalendar/exposure${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(calendarExposureDTO, await res.json()) };