export type AssetType = 'CASH' | 'THIRD_PARTY_INDEX' | 'EQUITY' | 'OPTION' | 'FUTURES' | 'MUTUAL_FUND' | 'MERQUBE_INDEX' | 'CUSTOM_SECAPI_INDEX' | 'OTHER'; export type PositionIdentifierType = 'RIC' | 'CURRENCY_CODE' | 'FSYM_ID' | 'TICKER' | 'BBG_TICKER' | 'CUSIP' | 'ISIN'; export type BasketPosition = {amount: number, asset_type: AssetType, identifier: string, identifier_type: PositionIdentifierType, position_id?: string | undefined, price?: number | undefined, price_currency?: string | undefined}; export type RealTimeTradeType = 'ELIGIBLE' | 'INELIGIBLE'; export type RicEquityPosition = {amount: number, asset_type: AssetType, identifier: string, identifier_type: PositionIdentifierType, position_id?: string | undefined, price?: number | undefined, price_currency?: string | undefined, real_time_trade_types?: Array | undefined, use_primary_listing?: boolean | undefined}; export type CountryCode = string; export type FsymEquityPosition = {amount: number, asset_type: AssetType, identifier: string, identifier_type: PositionIdentifierType, position_id?: string | undefined, price?: number | undefined, price_currency?: string | undefined, country_code: CountryCode}; export type IsoDate = string; export type OptionExpirationType = 'AM' | 'PM'; export type IsoTS = string; export type OptionStyle = 'AMERICAN' | 'EUROPEAN'; export type OptionType = 'PUT' | 'CALL'; export type OptionPosition = {amount: number, currency: string, delta_hedge_flag?: boolean | undefined, expiration_date: IsoDate, expiration_type?: OptionExpirationType | undefined, identifier: string, identifier_type: PositionIdentifierType, lag?: IsoTS | undefined, leg_multiple?: number | undefined, mic?: string | undefined, strike: number, strike_type?: ('PCT_SPOT' | 'DELTA' | 'SPCT_SPOT') | undefined, structure_id?: number | undefined, style?: OptionStyle | undefined, type: OptionType, underlying: string, vol_multiplier?: number | undefined, asset_type: AssetType, position_id?: string | undefined, price?: number | undefined, price_currency?: string | undefined}; export type FuturesPosition = {amount: number, currency: string, expiration_date: IsoDate, identifier: string, identifier_type: PositionIdentifierType, lag?: IsoTS | undefined, underlying: string, asset_type: AssetType, position_id?: string | undefined, price?: number | undefined, price_currency?: string | undefined}; export type SecapiBasketPosition = {amount: number, asset_type: AssetType, identifier: string, identifier_type: PositionIdentifierType, position_id?: string | undefined, price?: number | undefined, price_currency?: string | undefined, custom_metric?: string | undefined}; export type MerqubeIndexPosition = {amount: number, asset_type: AssetType, identifier: string, identifier_type: PositionIdentifierType, position_id?: string | undefined, price?: number | undefined, price_currency?: string | undefined, metric_name?: string | undefined}; export type IsinMicEquityPosition = {amount: number, asset_type: AssetType, identifier: string, identifier_type: PositionIdentifierType, position_id?: string | undefined, price?: number | undefined, price_currency?: string | undefined, mic: string}; export type MutualFundPosition = {amount: number, asset_type: AssetType, identifier: string, identifier_type: PositionIdentifierType, position_id?: string | undefined, price?: number | undefined, price_currency?: string | undefined}; export type ValidEquityBasketPosition = BasketPosition | RicEquityPosition | FsymEquityPosition | OptionPosition | FuturesPosition | SecapiBasketPosition | MerqubeIndexPosition | IsinMicEquityPosition | MutualFundPosition; export type PortfolioUom = 'SHARES' | 'WEIGHT'; export type BasketPortfolioPutIn = {divisor?: number | undefined, external_id?: string | undefined, positions: Array, share_selection_date?: IsoTS | undefined, target_portfolio_type?: ('EOD' | 'INTRADAY') | undefined, timestamp: IsoTS, unit_of_measure: PortfolioUom}; export type UpdateApiIndexUuidTargetPortfolioArgs = {uuid: string, body: BasketPortfolioPutIn}; export type UpdateApiIndexUuidTargetPortfolioOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * replace the portfolio for this index. Will eventually but not immediately affect /index/uuid/portfolio. * * PUT /index/{uuid}/target_portfolio */ export const updateApiIndexUuidTargetPortfolio = async (args: UpdateApiIndexUuidTargetPortfolioArgs, options?: UpdateApiIndexUuidTargetPortfolioOptions) => { const {baseUrl = "https://api.merqube.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/index/${encodeURIComponent(String(args.uuid))}/target_portfolio${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };