import {z} from 'zod' export type GetApiRfqsRfqIdBboArgs = {rfq_id: string}; export type GetApiRfqsRfqIdBboOptions = {baseUrl?: string | undefined, BearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const responsesRfqBboLegResult = z.object({best_ask_iv: z.string().optional(), best_ask_price: z.string().optional(), best_ask_quantity: z.string().optional(), best_bid_iv: z.string().optional(), best_bid_price: z.string().optional(), best_bid_quantity: z.string().optional(), mark_price: z.string().optional(), mark_price_iv: z.string().optional(), market: z.string().optional()}); export const responsesRfqBboResult = z.object({best_ask_price: z.string().optional(), best_ask_quantity: z.string().optional(), best_bid_price: z.string().optional(), best_bid_quantity: z.string().optional(), created_at: z.number().int().optional(), legs: z.array(responsesRfqBboLegResult).optional(), mark_price: z.string().optional(), max_price: z.string().optional(), min_price: z.string().optional(), rfq_id: 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 }; /** * Get RFQ market data * * GET /rfqs/{rfq_id}/bbo */ export const getApiRfqsRfqIdBbo = async (args: GetApiRfqsRfqIdBboArgs, options?: GetApiRfqsRfqIdBboOptions) => { const {baseUrl = "https://api.prod.paradex.trade/v1", fetch: fetchFn = fetch, BearerToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerToken !== undefined) headers.set("Authorization", BearerToken) const url = `${baseUrl.replace(/\/+$/, '')}/rfqs/${encodeURIComponent(String(args.rfq_id))}/bbo${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(responsesRfqBboResult, await res.json()) };