Skip to content

Commit

Permalink
fix(fiat-services): fix fetching fiat rates for timestamps range
Browse files Browse the repository at this point in the history
  • Loading branch information
vytick committed Feb 2, 2025
1 parent a8cd2f4 commit ec9fb40
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions suite-common/fiat-services/src/coingecko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { RateLimiter } from './limiter';
// a proxy for https://api.coingecko.com/api/v3
const COINGECKO_API_BASE_URL = 'https://cdn.trezor.io/dynamic/coingecko/api/v3';

const ONE_DAY_IN_MS = 24 * 60 * 60 * 1000;
const ONE_DAY_IN_S = 24 * 60 * 60;

interface HistoricalResponse extends HistoricRates {
symbol: string;
Expand Down Expand Up @@ -133,11 +133,12 @@ export const getFiatRatesForTimestamps = async (
if (!coinUrls || coinUrls.length === 0) return null;

// sort timestamps chronologically to get the minimum and maximum values
const sortedTimestamps = [...timestamps].sort((ts1, ts2) => ts1 - ts2);
const sortedTimestampsInSeconds = [...timestamps].sort((ts1, ts2) => ts1 - ts2);

// adjust from and to timestamps to get better range of data
const fromTimestamp = sortedTimestamps[0] - ONE_DAY_IN_MS;
const toTimestamp = sortedTimestamps[sortedTimestamps.length - 1] + ONE_DAY_IN_MS;
const fromTimestamp = sortedTimestampsInSeconds[0] - ONE_DAY_IN_S;
const toTimestamp =
sortedTimestampsInSeconds[sortedTimestampsInSeconds.length - 1] + ONE_DAY_IN_S;

const params = `?vs_currency=${fiatCurrencyCode}&from=${fromTimestamp}&to=${toTimestamp}`;

Expand Down

0 comments on commit ec9fb40

Please sign in to comment.