export type LedgerEntryType = 'DEPOSIT' | 'WITHDRAWAL' | 'ORDER_EXECUTION' | 'CORRECTION' | 'RESOLUTION' | 'MANUAL_ADJUSTMENT' | 'ACCOUNT_PROPERTY_ADJUSTMENT' | 'COMMISSION' | 'WITHDRAWAL_REJECTION' | 'MANUAL_TRANSFER' | 'PENDING_WITHDRAWAL_CREATION'; export type GetApiV1FundingBalanceLedgerDownloadArgs = {account: string, currency?: string | undefined, start_time?: string | undefined, end_time?: string | undefined, entry_types?: Array | undefined, symbol?: string | undefined, description?: string | undefined, newest_first?: boolean | undefined, page_size?: number | undefined, page_token?: string | undefined}; export type GetApiV1FundingBalanceLedgerDownloadOptions = {baseUrl?: string | undefined, XPMAccessKey?: string | undefined, XPMTimestamp?: string | undefined, XPMSignature?: string | undefined, fetch?: typeof fetch | undefined}; /** * Download account balance ledger as CSV * * GET /v1/funding/balance-ledger/download */ export const getApiV1FundingBalanceLedgerDownload = async (args: GetApiV1FundingBalanceLedgerDownloadArgs, options?: GetApiV1FundingBalanceLedgerDownloadOptions) => { const {baseUrl = "https://api.polymarket.us", fetch: fetchFn = fetch, XPMAccessKey, XPMTimestamp, XPMSignature} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/csv") if (args.account != null) query.append("account", String(args.account)) if (args.currency != null) query.append("currency", String(args.currency)) if (args.start_time != null) query.append("start_time", String(args.start_time)) if (args.end_time != null) query.append("end_time", String(args.end_time)) for (const item of args.entry_types ?? []) query.append("entry_types", String(item)) if (args.symbol != null) query.append("symbol", String(args.symbol)) if (args.description != null) query.append("description", String(args.description)) if (args.newest_first != null) query.append("newest_first", String(args.newest_first)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.page_token != null) query.append("page_token", String(args.page_token)) 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/funding/balance-ledger/download${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 res.text() };