Readings
The Reading API lets you get readings data from the network. You can read data from any Asset object in the network using its readings
property.
Return value
Section titled “Return value”These values of type AssetReadings are automatically refreshed every few minutes and contain the readings for the current network time sampled with a 15 minute resolution.
readings: AssetReadings & { latest, forRange }
Examples
Section titled “Examples”const asset = sdk.network.getAsset('Nellybay')console.log(asset.readings)// {// level: {// date: Date;// value: number// }// }
Query methods
Section titled “Query methods”forPeriod()
Section titled “forPeriod()”Returns the cached readings in the current 24 hour period.
Method signature
Section titled “Method signature”forPeriod(): AssetReadingsCollection
Parameters
Section titled “Parameters”None.
Returns
Section titled “Returns”Return type is AssetReadingsCollection. An array with the readings cached in the 24 hour period, sampled with a 15 minute resolution.
latest()
Section titled “latest()”Retrieves the latest reading for an asset.
Method signature
Section titled “Method signature”latest(): Promise<AssetReadings>
Parameters
Section titled “Parameters”None.
Returns
Section titled “Returns”A promise that will resolve when the latest available readings are available in an AssetReadings object.
Examples
Section titled “Examples”const asset = sdk.network.getAsset('Nellybay')asset.readings.latest().then((reading) => { console.log(reading)})
forRange()
Section titled “forRange()”Retrieves readings for an asset between two dates.
Method signature
Section titled “Method signature”forRange(start: Date, end: Date): Promise<AssetReadings>
Parameters
Section titled “Parameters”- start: Start date
- end: End date
Returns
Section titled “Returns”A promise that will resolve when the readings are available in an AssetReadings object.
Examples
Section titled “Examples”Get readings for 24 hours for an asset.
const sdk = window.qatiumconst network = sdk.network
const asset = network.getAsset('Nellybay')asset.readings.forRange(new Date("2024-01-01"), new Date("2024-01-02")).then((readings) => { readings.level.forEach((reading) => { console.log(reading) })})