import {z} from 'zod' export type GetApiSapiV1SubAccountSubTransferHistoryArgs = {fromEmail?: string | undefined, toEmail?: string | undefined, startTime?: number | undefined, endTime?: number | undefined, page?: number | undefined, limit?: number | undefined, recvWindow?: number | undefined, timestamp: number, signature: string}; export type GetApiSapiV1SubAccountSubTransferHistoryOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiSapiV1SubAccountSubTransferHistoryResponse = z.array(z.object({from: z.string(), to: z.string(), asset: z.string(), qty: z.string(), status: z.string(), tranId: z.number().int(), time: z.number().int()})); 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 }; /** * Sub-account Spot Asset Transfer History (For Master Account) * * GET /sapi/v1/sub-account/sub/transfer/history */ export const getApiSapiV1SubAccountSubTransferHistory = async (args: GetApiSapiV1SubAccountSubTransferHistoryArgs, options?: GetApiSapiV1SubAccountSubTransferHistoryOptions) => { const {baseUrl = "https://api.binance.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.fromEmail != null) query.append("fromEmail", String(args.fromEmail)) if (args.toEmail != null) query.append("toEmail", String(args.toEmail)) if (args.startTime != null) query.append("startTime", String(args.startTime)) if (args.endTime != null) query.append("endTime", String(args.endTime)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.recvWindow != null) query.append("recvWindow", String(args.recvWindow)) if (args.timestamp != null) query.append("timestamp", String(args.timestamp)) if (args.signature != null) query.append("signature", String(args.signature)) if (ApiKeyAuth !== undefined) headers.set("X-MBX-APIKEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/sapi/v1/sub-account/sub/transfer/history${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(getApiSapiV1SubAccountSubTransferHistoryResponse, await res.json()) };