Skip to main content

Query Portfolio History

A wallet's historical portfolio value can be found at specific date ranges and intervals.

Using the hook usePortfolioHistory(range: TimeFrame), you can query history for a specifc range of dates.

This hook will return an array of objects relating to a wallet's balance at a specific point in time.

Return Type

{
fetchDetails: FetchDetails,
history: {
total: number;
time: number;
}[]
}
FieldDetails
totalThe total portfolio value at that timestamp. This is given in the currently-selected default currency
timeUnix timestamp (seconds) of the portfolio snapshot

Inputs

The range for which to fetch balances is a required parameter, and corresponds to the number of days to retrieve data for. A period can be defined by the TimeFrame type from the Core SDK, which has the following construction:

type Time = "hour" | "day" | "week" | "month" | "year";
type TimeFrame = Time | `${number} ${Time}s` | "all";

This means time periods can be specified in number of hours, number of days, number of weeks, number of months, or number of years.

Additionally, the resolution can be supplied as an integer, where the following applies:

ValueResolutionDefault For
05 minutesTimeFrame <= 2 Hours
115 minutes2 Hours < Time Frame <= 1 Day
230 minutes1 Day < Time Frame <= 2 weeks
31 Hour2 Weeks < Time Frame <= 1 Month
41 Day1 Month < Time Frame

Five-minute resolution is only available in entirety for up to 1 week in the past.

This hook exposes QueryOptions and FetchDetails as explained in Data Retrieval Hooks``

The returned data will be priced according the wallet's default price currency.

Example

import { usePortfolioHistory } from '@node-fi/react-native-sdk';
import { DateRange } from '@node-fi/sdk-core';


function GraphComponent() {
const [dayRange, setDayRange] = useState<DateRange>(1);
const { history: portfolioHistory, fetchDetails } = usePortfolioHistory(`${dayRange} days`);

if (fetchDetails.isFetching) {
// If portfolioHistory === undefined, content is loading
return <LoadingComponent />;
}

return <Chart data={portolioHistory} x="time" y="total" />;
}