import {z} from 'zod' export type GetApiBalanceSheetConsolidatedArgs = {symbol?: string | undefined, figi?: string | undefined, isin?: string | undefined, cusip?: string | undefined, exchange?: string | undefined, mic_code?: string | undefined, country?: string | undefined, period?: ('annual' | 'quarterly') | undefined, start_date?: string | undefined, end_date?: string | undefined, outputsize?: number | undefined}; export type GetApiBalanceSheetConsolidatedOptions = {baseUrl?: string | undefined, authorizationHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const equityInfo = z.object({total_equity_gross_minority_interest: z.number().optional(), stockholders_equity: z.number().optional(), common_stock_equity: z.number().optional(), preferred_stock_equity: z.number().optional(), other_equity_interest: z.number().optional(), minority_interest: z.number().optional(), total_capitalization: z.number().optional(), net_tangible_assets: z.number().optional(), tangible_book_value: z.number().optional(), invested_capital: z.number().optional(), working_capital: z.number().optional(), capital_stock: z.object({common_stock: z.number().optional(), preferred_stock: z.number().optional(), total_partnership_capital: z.number().optional(), general_partnership_capital: z.number().optional(), limited_partnership_capital: z.number().optional(), capital_stock: z.number().optional(), other_capital_stock: z.number().optional(), additional_paid_in_capital: z.number().optional(), retained_earnings: z.number().optional(), treasury_stock: z.number().optional(), treasury_shares_number: z.number().optional(), ordinary_shares_number: z.number().optional(), preferred_shares_number: z.number().optional(), share_issued: z.number().optional()}).optional(), equity_adjustments: z.object({gains_losses_not_affecting_retained_earnings: z.number().optional(), other_equity_adjustments: z.number().optional(), fixed_assets_revaluation_reserve: z.number().optional(), foreign_currency_translation_adjustments: z.number().optional(), minimum_pension_liabilities: z.number().optional(), unrealized_gain_loss: z.number().optional()}).optional(), net_debt: z.number().optional(), total_debt: z.number().optional()}); export const assetsInfo = z.object({total_assets: z.number().optional(), current_assets: z.object({total_current_assets: z.number().optional(), cash_cash_equivalents_and_short_term_investments: z.number().optional(), cash_and_cash_equivalents: z.number().optional(), cash_equivalents: z.number().optional(), cash_financial: z.number().optional(), other_short_term_investments: z.number().optional(), restricted_cash: z.number().optional(), receivables: z.object({total_receivables: z.number().optional(), accounts_receivable: z.number().optional(), gross_accounts_receivable: z.number().optional(), allowance_for_doubtful_accounts_receivable: z.number().optional(), receivables_adjustments_allowances: z.number().optional(), other_receivables: z.number().optional(), due_from_related_parties_current: z.number().optional(), taxes_receivable: z.number().optional(), accrued_interest_receivable: z.number().optional(), notes_receivable: z.number().optional(), loans_receivable: z.number().optional()}).optional(), inventory: z.object({total_inventory: z.number().optional(), inventories_adjustments_allowances: z.number().optional(), other_inventories: z.number().optional(), finished_goods: z.number().optional(), work_in_process: z.number().optional(), raw_materials: z.number().optional()}).optional(), prepaid_assets: z.number().optional(), current_deferred_assets: z.number().optional(), current_deferred_taxes_assets: z.number().optional(), assets_held_for_sale_current: z.number().optional(), hedging_assets_current: z.number().optional(), other_current_assets: z.number().optional()}).optional(), non_current_assets: z.object({total_non_current_assets: z.number().optional(), financial_assets: z.number().optional(), investments_and_advances: z.number().optional(), other_investments: z.number().optional(), investment_in_financial_assets: z.number().optional(), held_to_maturity_securities: z.number().optional(), available_for_sale_securities: z.number().optional(), financial_assets_designated_as_fair_value_through_profit_or_loss_total: z.number().optional(), trading_securities: z.number().optional(), long_term_equity_investment: z.number().optional(), investments_in_joint_ventures_at_cost: z.number().optional(), investments_in_other_ventures_under_equity_method: z.number().optional(), investments_in_associates_at_cost: z.number().optional(), investments_in_subsidiaries_at_cost: z.number().optional(), investment_properties: z.number().optional(), goodwill_and_other_intangible_assets: z.object({goodwill: z.number().optional(), other_intangible_assets: z.number().optional(), total_goodwill_and_intangible_assets: z.number().optional()}).optional(), net_ppe: z.number().optional(), gross_ppe: z.number().optional(), accumulated_depreciation: z.number().optional(), leases: z.number().optional(), construction_in_progress: z.number().optional(), other_properties: z.number().optional(), machinery_furniture_equipment: z.number().optional(), buildings_and_improvements: z.number().optional(), land_and_improvements: z.number().optional(), properties: z.number().optional(), non_current_accounts_receivable: z.number().optional(), non_current_note_receivables: z.number().optional(), due_from_related_parties_non_current: z.number().optional(), non_current_prepaid_assets: z.number().optional(), non_current_deferred_assets: z.number().optional(), non_current_deferred_taxes_assets: z.number().optional(), defined_pension_benefit: z.number().optional(), other_non_current_assets: z.number().optional()}).optional(), liabilities: z.object({total_liabilities_net_minority_interest: z.number().optional(), current_liabilities: z.object({total_current_liabilities: z.number().optional(), current_debt_and_capital_lease_obligation: z.number().optional(), current_debt: z.number().optional(), current_capital_lease_obligation: z.number().optional(), other_current_borrowings: z.number().optional(), line_of_credit: z.number().optional(), commercial_paper: z.number().optional(), current_notes_payable: z.number().optional(), current_provisions: z.number().optional(), payables_and_accrued_expenses: z.object({total_payables_and_accrued_expenses: z.number().optional(), accounts_payable: z.number().optional(), current_accrued_expenses: z.number().optional(), interest_payable: z.number().optional(), payables: z.number().optional(), other_payable: z.number().optional(), due_to_related_parties_current: z.number().optional(), dividends_payable: z.number().optional(), total_tax_payable: z.number().optional(), income_tax_payable: z.number().optional()}).optional(), pension_and_other_post_retirement_benefit_plans_current: z.number().optional(), employee_benefits: z.number().optional(), current_deferred_liabilities: z.number().optional(), current_deferred_revenue: z.number().optional(), current_deferred_taxes_liabilities: z.number().optional(), other_current_liabilities: z.number().optional(), liabilities_held_for_sale_non_current: z.number().optional()}).optional(), non_current_liabilities: z.object({total_non_current_liabilities_net_minority_interest: z.number().optional(), long_term_debt_and_capital_lease_obligation: z.object({total_long_term_debt_and_capital_lease_obligation: z.number().optional(), long_term_debt: z.number().optional(), long_term_capital_lease_obligation: z.number().optional()}).optional(), long_term_provisions: z.number().optional(), non_current_pension_and_other_postretirement_benefit_plans: z.number().optional(), non_current_accrued_expenses: z.number().optional(), due_to_related_parties_non_current: z.number().optional(), trade_and_other_payables_non_current: z.number().optional(), non_current_deferred_liabilities: z.number().optional(), non_current_deferred_revenue: z.number().optional(), non_current_deferred_taxes_liabilities: z.number().optional(), other_non_current_liabilities: z.number().optional(), preferred_securities_outside_stock_equity: z.number().optional(), derivative_product_liabilities: z.number().optional(), capital_lease_obligations: z.number().optional(), restricted_common_stock: z.number().optional()}).optional(), equity: equityInfo.optional()}).optional()}); export const balanceSheetConsolidatedItem = z.object({fiscal_date: z.string(), assets: assetsInfo.optional()}); export const getApiBalanceSheetConsolidatedResponse = z.object({balance_sheet: z.array(balanceSheetConsolidatedItem), status: z.string().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 }; /** * Balance sheet consolidated * * GET /balance_sheet/consolidated * * Also accepts auth: queryParameter */ export const getApiBalanceSheetConsolidated = async (args: GetApiBalanceSheetConsolidatedArgs, options?: GetApiBalanceSheetConsolidatedOptions) => { const {baseUrl = "https://api.twelvedata.com", fetch: fetchFn = fetch, authorizationHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.symbol != null) query.append("symbol", String(args.symbol)) if (args.figi != null) query.append("figi", String(args.figi)) if (args.isin != null) query.append("isin", String(args.isin)) if (args.cusip != null) query.append("cusip", String(args.cusip)) if (args.exchange != null) query.append("exchange", String(args.exchange)) if (args.mic_code != null) query.append("mic_code", String(args.mic_code)) if (args.country != null) query.append("country", String(args.country)) if (args.period != null) query.append("period", String(args.period)) if (args.start_date != null) query.append("start_date", String(args.start_date)) if (args.end_date != null) query.append("end_date", String(args.end_date)) if (args.outputsize != null) query.append("outputsize", String(args.outputsize)) if (authorizationHeader !== undefined) headers.set("Authorization", authorizationHeader) const url = `${baseUrl.replace(/\/+$/, '')}/balance_sheet/consolidated${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(getApiBalanceSheetConsolidatedResponse, await res.json()) };