import {z} from 'zod' export type ConnectProtocolVersion = number; export type ConnectTimeoutHeader = number; export type BaseObjectsV1MarketSymbol = {assetSymbol?: string | undefined, quoteSymbol?: string | undefined}; export type MarketServiceV1GetMarketconfigRequest = {market: {marketId: unknown} | {marketSymbol: BaseObjectsV1MarketSymbol}}; export type CreateApiMarketServiceV1MarketServiceGetMarketConfigsArgs = {'Connect-Protocol-Version': ConnectProtocolVersion, 'Connect-Timeout-Ms'?: ConnectTimeoutHeader | undefined, body: MarketServiceV1GetMarketconfigRequest}; export type CreateApiMarketServiceV1MarketServiceGetMarketConfigsOptions = {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 marketServiceV1GetMarketconfigResponse = z.object({marketConfig: 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 }; /** * GetMarketConfigs * * POST /market_service.v1.MarketService/GetMarketConfigs */ export const createApiMarketServiceV1MarketServiceGetMarketConfigs = async (args: CreateApiMarketServiceV1MarketServiceGetMarketConfigsArgs, options?: CreateApiMarketServiceV1MarketServiceGetMarketConfigsOptions) => { 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/GetMarketConfigs${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(marketServiceV1GetMarketconfigResponse, await res.json()) };