import {z} from 'zod' export type ConnectProtocolVersion = number; export type ConnectTimeoutHeader = number; export type GoogleProtobufEmpty = Record; export type CreateApiMarketServiceV1MarketServiceGetMarketsArgs = {'Connect-Protocol-Version': ConnectProtocolVersion, 'Connect-Timeout-Ms'?: ConnectTimeoutHeader | undefined, body: GoogleProtobufEmpty}; export type CreateApiMarketServiceV1MarketServiceGetMarketsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const baseObjectsV1FeeConfig = z.object({marketId: z.string().optional(), tradeFeePct: z.number().optional(), maxEntitlement: z.number().optional(), insuranceFundEntitlementPct: z.number().optional(), maxImbalance: z.number().optional()}); export const baseObjectsV1ADLConfig = z.object({maintenanceMarginRatio: z.number().optional(), seizureThreshold: z.number().optional(), adlThreshold: z.number().optional(), shockFactor: z.number().optional(), maxIfFractionAllowed: z.number().optional()}); export const baseObjectsV1MarketConfig = z.object({marketId: z.string().optional(), marketName: z.string().optional(), minLeverage: z.number().optional(), maxLeverage: z.number().optional(), minTradeSize: z.number().optional(), maxTradeSize: z.number().optional(), tickDecimals: z.number().int().optional(), lotSize: z.number().optional(), sizeDecimals: z.number().int().optional(), creator: z.string().optional(), feeConfig: baseObjectsV1FeeConfig.optional(), adlConfig: baseObjectsV1ADLConfig.optional(), maintenanceMarginRate: z.string().optional(), tradeFeePct: z.number().int().nullable().optional(), longRevenue: z.number().nullable().optional(), shortRevenue: z.number().nullable().optional()}); export const marketServiceV1GetMarketsResponse = z.object({markets: z.array(baseObjectsV1MarketConfig).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 }; /** * GetMarkets * * POST /market_service.v1.MarketService/GetMarkets */ export const createApiMarketServiceV1MarketServiceGetMarkets = async (args: CreateApiMarketServiceV1MarketServiceGetMarketsArgs, options?: CreateApiMarketServiceV1MarketServiceGetMarketsOptions) => { const {baseUrl = "https://api.fairground.fi", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Connect-Protocol-Version'] != null) headers.set("Connect-Protocol-Version", String(args['Connect-Protocol-Version'])) if (args['Connect-Timeout-Ms'] != null) headers.set("Connect-Timeout-Ms", String(args['Connect-Timeout-Ms'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/market_service.v1.MarketService/GetMarkets${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(marketServiceV1GetMarketsResponse, await res.json()) };