Skip to content

Commit

Permalink
Sorted TimeSeries types.
Browse files Browse the repository at this point in the history
  • Loading branch information
bre1470 committed Sep 3, 2024
1 parent 39930ce commit 0187c25
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 67 deletions.
8 changes: 4 additions & 4 deletions src/TimeSeries/Converters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import CumulativeReturnSeriesConverter from './CumulativeReturnSeriesConverter';
import DividendSeriesConverter from './DividendSeriesConverter';
import GrowthSeriesConverter from './GrowthSeriesConverter';
import OHLCVSeriesConverter from './OHLCVSeriesConverter';
import PriceSeriesConverter from './PriceSeriesConverter';
import RatingSeriesConverter from './RatingSeriesConverter';
import OHLCVSeriesConverter from './OHLCVSeriesConverter';


/* *
Expand All @@ -40,9 +40,9 @@ import OHLCVSeriesConverter from './OHLCVSeriesConverter';
export * from './CumulativeReturnSeriesConverter';
export * from './DividendSeriesConverter';
export * from './GrowthSeriesConverter';
export * from './OHLCVSeriesConverter';
export * from './PriceSeriesConverter';
export * from './RatingSeriesConverter';
export * from './OHLCVSeriesConverter';


/* *
Expand All @@ -56,7 +56,7 @@ export default {
CumulativeReturnSeriesConverter,
DividendSeriesConverter,
GrowthSeriesConverter,
OHLCVSeriesConverter,
PriceSeriesConverter,
RatingSeriesConverter,
OHLCVSeriesConverter
RatingSeriesConverter
};
25 changes: 9 additions & 16 deletions src/TimeSeries/TimeSeriesConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,13 @@
* */


import Converters from './Converters';
import External from '../Shared/External';
import GrowthSeriesConverter from './Converters/GrowthSeriesConverter';
import MorningstarAPI from '../Shared/MorningstarAPI';
import MorningstarConnector from '../Shared/MorningstarConnector';
import MorningstarURL from '../Shared/MorningstarURL';
import CumulativeReturnSeriesConverter from './Converters/CumulativeReturnSeriesConverter';
import DividendSeriesConverter from './Converters/DividendSeriesConverter';
import TimeSeriesOptions, { OHLCVSeriesOptions } from './TimeSeriesOptions';
import TimeSeriesRatingConverter from './Converters/RatingSeriesConverter';
import PriceSeriesConverter from './Converters/PriceSeriesConverter';
import TimeSeriesConverter from './TimeSeriesConverter';
import { OHLCVSeriesConverter } from './Converters';
import TimeSeriesOptions from './TimeSeriesOptions';


/* *
Expand Down Expand Up @@ -61,47 +56,45 @@ export class TimeSeriesConnector extends MorningstarConnector {
switch (options.series?.type) {

case 'CumulativeReturn':
this.converter = new CumulativeReturnSeriesConverter({
this.converter = new Converters.CumulativeReturnSeriesConverter({
...options.converter,
...options.series
});
break;

case 'Dividend':
this.converter = new DividendSeriesConverter({
this.converter = new Converters.DividendSeriesConverter({
...options.converter,
...options.series
});
break;

case 'Growth':
this.converter = new GrowthSeriesConverter({
this.converter = new Converters.GrowthSeriesConverter({
...options.converter,
...options.series
});
break;

case 'Rating':
this.converter = new TimeSeriesRatingConverter({
this.converter = new Converters.RatingSeriesConverter({
...options.converter,
...options.series
});
break;

case 'Price':
this.converter = new PriceSeriesConverter({
this.converter = new Converters.PriceSeriesConverter({
...options.converter,
...options.series
});
break;

case 'OHLCV':
this.converter = new OHLCVSeriesConverter({
this.converter = new Converters.OHLCVSeriesConverter({
...options.converter,
...options.series,
securities: options.securities,
replaceZeroWithCloseValue: (options as OHLCVSeriesOptions)
.replaceZeroWithCloseValue
securities: options.securities
});
break;

Expand Down
97 changes: 52 additions & 45 deletions src/TimeSeries/TimeSeriesJSON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ namespace TimeSeriesJSON {
* */


export type CompactHistoryDetail = (
| CompactHistoryOHLCV
);


export type CompactJSON = Array<CompactHistoryDetail>;


export type CompactHistoryOHLCV = [
date: number,
open: number,
high: number,
low: number,
close: number,
volume: number
];


export interface CurrencyHistory {
HistoryDetail: Array<CurrencyHistoryDetail>;
}
Expand Down Expand Up @@ -78,20 +96,6 @@ namespace TimeSeriesJSON {
Security: Array<Security>;
}

export type CompactJSON = Array<CompactHistoryDetail>;

export type CompactHistoryDetail =
| CompactHistoryOHLCV;

export type CompactHistoryOHLCV = [
date: number,
open: number,
high: number,
low: number,
close: number,
volume: number
];


/* *
*
Expand All @@ -100,6 +104,40 @@ namespace TimeSeriesJSON {
* */


export function isCompactJSONOHLCVResponse (
json?: unknown
): json is CompactJSON {
return (
isCompactJSONResponse(json) &&
(
json.length === 0 ||
isCompactHistoryOHLCV(json[0])
)
);
}


function isCompactJSONResponse (
json?: unknown
): json is CompactJSON {
return (
!!json &&
json instanceof Array
);
}


function isCompactHistoryOHLCV (
json?: unknown
): json is CompactHistoryOHLCV {
return (
!!json &&
Array.isArray(json) &&
json.length === 6
);
}


export function isHistory (
json?: unknown
): json is History {
Expand Down Expand Up @@ -182,37 +220,6 @@ namespace TimeSeriesJSON {
);
}

export function isCompactJSONOHLCVResponse (
json?: unknown
): json is CompactJSON {
return (
isCompactJSONResponse(json) &&
(
json.length === 0 ||
isCompactHistoryOHLCV(json[0])
)
);
}

function isCompactJSONResponse (
json?: unknown
): json is CompactJSON {
return (
!!json &&
Array.isArray(json)
);
}

function isCompactHistoryOHLCV (
json?: unknown
): json is CompactHistoryOHLCV {
return (
!!json &&
Array.isArray(json) &&
json.length === 6
);
}


}

Expand Down
2 changes: 1 addition & 1 deletion src/TimeSeries/TimeSeriesOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export interface TimeSeriesOptions extends MorningstarOptions {
localization?: LocalizationOptions;

/**
* Security to retrieve.
* Securities to retrieve.
*
* **NOTE: When series type is `OHLCV`, only one security is supported.**
*/
Expand Down
1 change: 0 additions & 1 deletion src/TimeSeries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export * from './TimeSeriesConnector';
export * from './TimeSeriesConverter';
export * as TimeSeriesConverters from './Converters/index';
export * from './TimeSeriesOptions';
export * from './TimeSeriesConverter';


/* *
Expand Down

0 comments on commit 0187c25

Please sign in to comment.