import {z} from 'zod' export type GetApiSapiV1EthStakingEthHistoryStakingHistoryArgs = {startTime?: number | undefined, endTime?: number | undefined, current?: number | undefined, size?: number | undefined, recvWindow?: number | undefined, timestamp: number, signature: string}; export type GetApiSapiV1EthStakingEthHistoryStakingHistoryOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiSapiV1EthStakingEthHistoryStakingHistoryResponse = z.object({rows: z.array(z.object({time: z.number().int(), asset: z.string(), amount: z.string(), status: z.string(), distributeAmount: z.string(), conversionRatio: z.string()})), total: 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 }; /** * Get ETH staking history (USER_DATA) * * GET /sapi/v1/eth-staking/eth/history/stakingHistory */ export const getApiSapiV1EthStakingEthHistoryStakingHistory = async (args: GetApiSapiV1EthStakingEthHistoryStakingHistoryArgs, options?: GetApiSapiV1EthStakingEthHistoryStakingHistoryOptions) => { 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.startTime != null) query.append("startTime", String(args.startTime)) if (args.endTime != null) query.append("endTime", String(args.endTime)) if (args.current != null) query.append("current", String(args.current)) if (args.size != null) query.append("size", String(args.size)) 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/eth-staking/eth/history/stakingHistory${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(getApiSapiV1EthStakingEthHistoryStakingHistoryResponse, await res.json()) };