import {z} from 'zod' export type GetApiV1CombosQuotesArgs = {pageSize?: number | undefined, pageToken?: string | undefined, quoteId?: string | undefined, rfqId?: string | undefined, creatorRfqUserId?: string | undefined, symbol?: 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, clientRequestId?: string | undefined}; export type GetApiV1CombosQuotesOptions = {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 v1QuoteStatus = z.enum(["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"]); export const v1Quote = z.object({id: z.string().optional(), rfqId: z.string().optional(), creatorRfqUserId: z.string().optional(), symbol: z.string().optional(), qtyDecimal: z.string().optional(), side: v1Side.optional(), price: z.string().optional(), status: v1QuoteStatus.optional(), createdTime: z.string().optional(), expirationTime: z.string().optional(), clientRequestId: z.string().optional()}); export const v1GetQuotesResponse = z.object({quotes: z.array(v1Quote).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 quotes * * GET /v1/combos/quotes */ export const getApiV1CombosQuotes = async (args: GetApiV1CombosQuotesArgs, options?: GetApiV1CombosQuotesOptions) => { 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.quoteId != null) query.append("quoteId", String(args.quoteId)) if (args.rfqId != null) query.append("rfqId", String(args.rfqId)) if (args.creatorRfqUserId != null) query.append("creatorRfqUserId", String(args.creatorRfqUserId)) if (args.symbol != null) query.append("symbol", String(args.symbol)) if (args.status != null) query.append("status", String(args.status)) if (args.clientRequestId != null) query.append("clientRequestId", String(args.clientRequestId)) 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/quotes${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(v1GetQuotesResponse, await res.json()) };