Skip to content

Commit

Permalink
Updated XRayConnector with shared code.
Browse files Browse the repository at this point in the history
  • Loading branch information
bre1470 committed Sep 12, 2024
1 parent 9d1dead commit ea98d81
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 74 deletions.
54 changes: 13 additions & 41 deletions src/XRay/XRayConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';


/* *
Expand All @@ -44,42 +46,11 @@ import {
interface XRayPortfolioObject {
benchmarkId?: string;
currencyId?: string;
holdings?: (Array<XRayHoldingAmountOptions>|Array<XRayHoldingWeightOptions>);
holdings?: (Array<MorningstarHoldingAmountOptions>|Array<MorningstarHoldingWeightOptions>);
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
Expand Down Expand Up @@ -139,13 +110,14 @@ export class XRayConnector extends MorningstarConnector {
return this;
}

const amountHoldings: Array<XRayHoldingAmountOptions> = [];
const weightHoldings: Array<XRayHoldingWeightOptions> = [];
const amountHoldings: Array<MorningstarHoldingAmountOptions> = [];
const weightHoldings: Array<MorningstarHoldingWeightOptions> = [];

for (const holding of holdings) {
if (isXRayHoldingAmountOptions(holding)) {
if (isMorningstarHoldingAmountOptions(holding)) {
amountHoldings.push(holding);
} else if (isXRayHoldingWeightOptions(holding)) {
}
if (isMorningstarHoldingWeightOptions(holding)) {
weightHoldings.push(holding);
}
}
Expand Down
37 changes: 4 additions & 33 deletions src/XRay/XRayOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@

import type {
MorningstarConverterOptions,
MorningstarOptions,
MorningstarSecurityOptions
MorningstarHoldingAmountOptions,
MorningstarHoldingWeightOptions,
MorningstarOptions
} from '../Shared/MorningstarOptions';


Expand Down Expand Up @@ -71,21 +72,6 @@ export type XRayDataPointOptions = (
);


export interface XRayHoldingAmountOptions extends MorningstarSecurityOptions {

/**
* Holding amount.
*/
amount: string;

/**
* Name of holding.
*/
name?: string;

}


export interface XRayHoldingDataPointOptions {

/**
Expand Down Expand Up @@ -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 {

/**
Expand All @@ -183,7 +154,7 @@ export interface XRayOptions extends MorningstarOptions {
/**
* Array of portfolio holdings.
*/
holdings?: (Array<XRayHoldingAmountOptions>|Array<XRayHoldingWeightOptions>);
holdings?: (Array<MorningstarHoldingAmountOptions>|Array<MorningstarHoldingWeightOptions>);

}

Expand Down

0 comments on commit ea98d81

Please sign in to comment.