import {z} from 'zod' export type GetApiV1CombosRfqsArgs = {pageSize?: number | undefined, pageToken?: string | undefined, rfqId?: string | undefined, rfqCreatorUserId?: string | undefined, symbol?: string | undefined, clientRequestId?: string | undefined, status?: ('QUOTE_STATUS_PENDING' | 'QUOTE_STATUS_ACCEPTED' | 'QUOTE_STATUS_DELETED' | 'QUOTE_STATUS_EXPIRED' | 'QUOTE_STATUS_PASSED' | 'QUOTE_STATUS_DONE_AWAY' | 'QUOTE_STATUS_PENDING_RISK' | 'QUOTE_STATUS_REJECTED' | 'QUOTE_STATUS_PENDING_END_TRADE') | undefined}; export type GetApiV1CombosRfqsOptions = {baseUrl?: string | undefined, XPMAccessKey?: string | undefined, XPMTimestamp?: string | undefined, XPMSignature?: string | undefined, fetch?: typeof fetch | undefined}; export const v1Side = z.enum(["SIDE_BUY", "SIDE_SELL"]); export const v1ComboInstrumentLeg = z.object({instrumentId: z.string().optional(), side: v1Side.optional()}); export const v1ComboInstrument = z.object({id: z.string().optional(), description: z.string().optional(), eventId: z.string().optional(), eventDisplayName: z.string().optional(), question: z.string().optional(), legs: z.array(v1ComboInstrumentLeg).optional(), expirationTime: z.string().optional(), tickSize: z.number().optional()}); export const v1RFQ = z.object({id: z.string().optional(), qtyDecimal: z.string().nullable().optional(), cashOrderQty: z.string().nullable().optional(), side: v1Side.optional(), instrument: v1ComboInstrument.optional(), rfqCreatorUserId: z.string().optional(), clientRequestId: z.string().optional(), expirationTime: z.string().optional(), createdTime: z.string().optional()}); export const v1GetRFQsResponse = z.object({rfqs: z.array(v1RFQ).optional(), nextPageToken: z.string().optional(), eof: z.boolean().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 RFQs * * GET /v1/combos/rfqs */ export const getApiV1CombosRfqs = async (args: GetApiV1CombosRfqsArgs, options?: GetApiV1CombosRfqsOptions) => { const {baseUrl = "https://api.polymarket.us", fetch: fetchFn = fetch, XPMAccessKey, XPMTimestamp, XPMSignature} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.pageToken != null) query.append("pageToken", String(args.pageToken)) if (args.rfqId != null) query.append("rfqId", String(args.rfqId)) if (args.rfqCreatorUserId != null) query.append("rfqCreatorUserId", String(args.rfqCreatorUserId)) if (args.symbol != null) query.append("symbol", String(args.symbol)) if (args.clientRequestId != null) query.append("clientRequestId", String(args.clientRequestId)) if (args.status != null) query.append("status", String(args.status)) if (XPMAccessKey !== undefined) headers.set("X-PM-Access-Key", XPMAccessKey) if (XPMTimestamp !== undefined) headers.set("X-PM-Timestamp", XPMTimestamp) if (XPMSignature !== undefined) headers.set("X-PM-Signature", XPMSignature) const url = `${baseUrl.replace(/\/+$/, '')}/v1/combos/rfqs${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(v1GetRFQsResponse, await res.json()) };