Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only return clm historic prices from updated api #26

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions src/api/data/clmRanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@ import { CLM_API } from '../../common/config.js';
import { logger } from '../logger.js';
import { getBucketParams, TimeBucket } from './timeBuckets.js';

type ClmApiHistoricPricesResponse = {
t: number;
min: string;
v: string;
max: string;
}[];
type ClmApiHistoricPrice = {
type: 'clm';
timestamp: number;
rangeMin: string;
currentPrice: string;
rangeMax: string;
};

type ClmApiHistoricPricesResponse = Array<ClmApiHistoricPrice>;

function isClmApiHistoricPrice(data: any): data is ClmApiHistoricPricesResponse {
function isClmApiHistoricPrice(data: any): data is ClmApiHistoricPrice {
return (
data &&
typeof data.t === 'number' &&
typeof data.min === 'string' &&
typeof data.v === 'string' &&
typeof data.max === 'string'
typeof data.timestamp === 'number' &&
typeof data.rangeMin === 'string' &&
typeof data.currentPrice === 'string' &&
typeof data.rangeMax === 'string' &&
typeof data.type === 'string' &&
data.type === 'clm'
);
}

Expand Down Expand Up @@ -53,7 +58,12 @@ export async function getClmHistoricPrices(
throw new Error('Invalid response for historic prices from upstream api');
}

return data;
return data.map(item => ({
t: item.timestamp,
min: item.rangeMin,
v: item.currentPrice,
max: item.rangeMax,
}));
}

type ClmHistoricPricesRangeResponse = Range;
Expand Down