Getting Started with Triple Price Feeds Incorporating Triple Oracles' price feeds into your project is a straightforward process. Triple Oracles currently provides support for numerous EVM-based networks. The value of the price feed published by Triple is referred to as 'Triple-Value.' In the following sections, we will illustrate how to access and retrieve Triple-Value from Triple.
Step 1: Create The Triple-Value Interface
In the first step you need to build data structures to receive the data feeds and functions to fetch data into configured data structures.
You may add the following code to the solidity smart contract that you wish to retrieve Triple-Value.
pragmasolidity 0.8.19;// depending on the requirement, you may build one or more // data structures given below. interface ITripleValueFeed {// Data structure to hold the pair datastructdataWithoutHcc {uint256 round;uint256 decimals;uint256 time;uint256 price;}// Data structure to hold the pair data with History Consistency CheckstructdataWithHcc {uint256 round;uint256 decimals;uint256 time;uint256 price;uint256 historyConsistent;}// Data structure to hold the derived pair data structderivedData{int256 roundDifference;int256 timeDifference;uint256 derivedPrice;uint256 decimals;}// Below functions enable you to retrieve different flavours of S-Value// Function to fetch the data for a single data pairfunctiongetTriplevalues(uint256_pairIndex)externalviewreturns (dataWithoutHcc memory);//Function to fetch the data for a multiple data pairsfunctiongetTriplevalues(uint256[] memory_pairIndexes)externalviewreturns (dataWithoutHcc[] memory);// Function to Fetch the Data for a single data pair with HCCfunctiongetTriplevaluesWithHCC(uint256_pairIndex)externalviewreturns (dataWithHcc memory);// Function to Fetch the Data for a multiple data pairs with HCCfunctiongetTriplevaluesWithHCC(uint256[] memory_pairIndexes)externalviewreturns (dataWithHcc[] memory);// Function to fetch the data for a derived data pair.functiongetDerivedTriplevalues(uint256_derivedPairId)externalviewreturns (derivedData memory);// Function to fetch the timestamp(Last or Latest) of the data pair// If you need to check the staleness of the data prior to requesting S-values// use this function to check the last updated time stamp of the data pair.functiongetTimestamp(uint256_tradingPair) externalviewreturns (uint256);
Above creates the interface that you will later apply in order to fetch a price from Triple Oracles.
Step 2: Configure The Triple-Value Feed Address
In order to retrieve the Triple-Value, then configure Triple-Value feed using the Triple Smart Contract address as demonstrated below.
Now you can access the Triple-Value for any of the trading pairs Triple publishes. Below sample code retrieves Triple-Value for single as well as multiple data pairs for demonstration purpose. You may use it as appropriate.
// requesting Triple-Value for a single pair
function getPrice(uint256 _priceIndex)
external
view
returns (ITripleValueFeed.dataWithoutHcc memory) {
return TripleValueFeed.getTriplevalue(_priceIndex);
}
// requesting Triple-values for multiple pairs
function getPriceForMultiplePair(uint256[] memory _pairIndexes)
external
view
returns (ITripleValueFeed.dataWithoutHcc[] memory) {
return TripleValueFeed.getTriplevalues(_pairIndexes);
}
// Requesting Triple-value for a single data pair with HCC check.
function getPriceWithHccCheck (uint256 _priceIndex)
external
view
returns (ITripleValueFeed.dataWithHcc memory) {
return TripleFeed.getTriplevalueWithHCC(_priceIndex);
}
// Requesting Triple-values for multiple pairs with HCC check.
function getPriceWithHccCheckForMultiplePair(uint256[] memory _pairIndexes)
external
view
returns (ITripleValueFeed.dataWithHcc[] memory) {
return TripleValueFeed.getTriplevaluesWithHCC(_pairIndexes);
}
// Requesting value of a derived data pair
function getDerivedValueOfPairId(uint256 _derivedPairId)
external
view returns(ITripleValueFeed.derivedData memory){
return TripleFeed.getDerivedTriplevalue(_derivedPairId);
}