import {z} from 'zod' export type GetApiRestApiV1ProjectsProjectIdCustomEaArgs = {projectId: string}; export type GetApiRestApiV1ProjectsProjectIdCustomEaOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const expertAdvisorRuntimeStateDTO = z.object({accountId: z.string().optional(), cpuPercent: z.number().optional(), expertLoaded: z.boolean().optional(), featureId: z.string().optional(), journalTail: z.string().optional(), lastError: z.string().optional(), lastLifesignAt: z.number().int().optional(), nextRestartAt: z.number().int().optional(), restartCount: z.number().int().optional(), startedAt: z.number().int().optional(), state: z.enum(["STOPPED", "STARTING", "RUNNING", "ERROR"]).optional(), terminalConnected: z.boolean().optional(), warning: z.string().optional(), workingSetBytes: z.number().int().optional()}); export const expertAdvisorOverviewDTO = z.object({accountId: z.string().optional(), enabled: z.boolean().optional(), expertName: z.string().optional(), featureId: z.string().optional(), state: expertAdvisorRuntimeStateDTO.optional(), symbol: z.string().optional(), timeframe: z.enum(["M1", "M2", "M3", "M4", "M5", "M6", "M10", "M12", "M15", "M20", "M30", "H1", "H2", "H3", "H4", "H6", "H8", "H12", "D1", "W1", "MN1"]).optional()}); export const getApiRestApiV1ProjectsProjectIdCustomEaResponse = z.array(expertAdvisorOverviewDTO); 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 }; /** * Runtime state of every hosted expert advisor on the project's active accounts, with the expert name, symbol and timeframe * * GET /rest/api/v1/projects/{projectId}/customEa */ export const getApiRestApiV1ProjectsProjectIdCustomEa = async (args: GetApiRestApiV1ProjectsProjectIdCustomEaArgs, options?: GetApiRestApiV1ProjectsProjectIdCustomEaOptions) => { 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 (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/rest/api/v1/projects/${encodeURIComponent(String(args.projectId))}/customEa${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(getApiRestApiV1ProjectsProjectIdCustomEaResponse, await res.json()) };