import {z} from 'zod' export type GetApiMeMxvAccountOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const fireAntApiModelsMXVInvestorAccount = z.object({investorCode: z.string().optional(), investorName: z.string().optional(), brokerCode: z.string().optional(), brokerName: z.string().optional(), collaboratorCode: z.string().optional(), collaboratorName: z.string().optional(), currency: z.string().optional(), sodBalance: z.number().optional(), sodBalanceUSD: z.number().optional(), changedAmount: z.number().optional(), changedAmountUSD: z.number().optional(), actualProfitVND: z.number().optional(), actualProfitUSD: z.number().optional(), initialRequiredMargin: z.number().optional(), initialRequiredMarginUSD: z.number().optional(), estimatedProfitVND: z.number().optional(), estimatedProfitUSD: z.number().optional(), netMargin: z.number().optional(), netMarginUSD: z.number().optional(), eodBalance: z.number().optional(), eodBalanceUSD: z.number().optional(), marginRatio: z.number().optional(), depositProcessMethod: z.string().optional(), transactionFee: z.number().optional(), pendingTransactionFee: z.number().optional(), interest: z.number().optional(), initialRequiredMarginProvisional: z.number().optional(), initialRequiredMarginProvisionalUSD: z.number().optional(), availableMargin: z.number().optional(), availableMarginProvisional: z.number().optional(), currentBalance: z.number().optional(), additionalMargin: z.number().optional(), maxInitialRequiredMarginProvisional: z.number().optional(), defaultPositionLimit: z.number().int().optional(), totalProfitVND: z.number().optional(), change: z.number().optional(), changePercentage: z.number().optional(), generalFee: z.number().optional(), marginRatioColor: 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 }; /** * Lấy thông tin tài khoản hàng hóa MXV * * GET /me/mxv/account */ export const getApiMeMxvAccount = async (options?: GetApiMeMxvAccountOptions) => { const {baseUrl = "https://api.fireant.vn", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/me/mxv/account${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(fireAntApiModelsMXVInvestorAccount, await res.json()) };