From ea98d8145ab8fe37057794ad30e5217fc6861ff8 Mon Sep 17 00:00:00 2001 From: bre1470 <40056287+bre1470@users.noreply.github.com> Date: Thu, 12 Sep 2024 13:06:50 +0200 Subject: [PATCH] Updated XRayConnector with shared code. --- src/XRay/XRayConnector.ts | 54 ++++++++++----------------------------- src/XRay/XRayOptions.ts | 37 +++------------------------ 2 files changed, 17 insertions(+), 74 deletions(-) diff --git a/src/XRay/XRayConnector.ts b/src/XRay/XRayConnector.ts index caba6b3..f269e10 100644 --- a/src/XRay/XRayConnector.ts +++ b/src/XRay/XRayConnector.ts @@ -25,13 +25,15 @@ import External from '../Shared/External'; import MorningstarAPI from '../Shared/MorningstarAPI'; import MorningstarConnector from '../Shared/MorningstarConnector'; +import { + isMorningstarHoldingAmountOptions, + isMorningstarHoldingWeightOptions, + MorningstarHoldingAmountOptions, + MorningstarHoldingWeightOptions +} from '../Shared/MorningstarOptions'; import MorningstarURL from '../Shared/MorningstarURL'; import XRayConverter from './XRayConverter'; -import { - XRayHoldingAmountOptions, - XRayHoldingWeightOptions, - XRayOptions -} from './XRayOptions'; +import XRayOptions from './XRayOptions'; /* * @@ -44,42 +46,11 @@ import { interface XRayPortfolioObject { benchmarkId?: string; currencyId?: string; - holdings?: (Array|Array); + holdings?: (Array|Array); type?: (2|3); } -/* * - * - * Functions - * - * */ - - -function isXRayHoldingAmountOptions ( - options?: unknown -): options is XRayHoldingAmountOptions { - return ( - !!options && - typeof options === 'object' && - typeof (options as XRayHoldingAmountOptions).amount === 'string' && - typeof (options as XRayHoldingWeightOptions).weight === 'undefined' - ); -} - - -function isXRayHoldingWeightOptions ( - options?: unknown -): options is XRayHoldingAmountOptions { - return ( - !!options && - typeof options === 'object' && - typeof (options as XRayHoldingAmountOptions).amount === 'undefined' && - typeof (options as XRayHoldingWeightOptions).weight === 'string' - ); -} - - /* * * * Class @@ -139,13 +110,14 @@ export class XRayConnector extends MorningstarConnector { return this; } - const amountHoldings: Array = []; - const weightHoldings: Array = []; + const amountHoldings: Array = []; + const weightHoldings: Array = []; for (const holding of holdings) { - if (isXRayHoldingAmountOptions(holding)) { + if (isMorningstarHoldingAmountOptions(holding)) { amountHoldings.push(holding); - } else if (isXRayHoldingWeightOptions(holding)) { + } + if (isMorningstarHoldingWeightOptions(holding)) { weightHoldings.push(holding); } } diff --git a/src/XRay/XRayOptions.ts b/src/XRay/XRayOptions.ts index e5cfaee..07ee344 100644 --- a/src/XRay/XRayOptions.ts +++ b/src/XRay/XRayOptions.ts @@ -24,8 +24,9 @@ import type { MorningstarConverterOptions, - MorningstarOptions, - MorningstarSecurityOptions + MorningstarHoldingAmountOptions, + MorningstarHoldingWeightOptions, + MorningstarOptions } from '../Shared/MorningstarOptions'; @@ -71,21 +72,6 @@ export type XRayDataPointOptions = ( ); -export interface XRayHoldingAmountOptions extends MorningstarSecurityOptions { - - /** - * Holding amount. - */ - amount: string; - - /** - * Name of holding. - */ - name?: string; - -} - - export interface XRayHoldingDataPointOptions { /** @@ -148,21 +134,6 @@ export type XRayHoldingDataPoints = ( ); -export interface XRayHoldingWeightOptions extends MorningstarSecurityOptions { - - /** - * Name of holding. - */ - name?: string; - - /** - * Holding weight. - */ - weight: string; - -} - - export interface XRayOptions extends MorningstarOptions { /** @@ -183,7 +154,7 @@ export interface XRayOptions extends MorningstarOptions { /** * Array of portfolio holdings. */ - holdings?: (Array|Array); + holdings?: (Array|Array); }