OKTC price feeds#

Introduction to OKTC price feeds#

OKTC price feeds is the quickest way to connect your smart contracts to the real-world market prices of crypto assets.

For example, one use for data feeds is to enable smart contracts to retrieve the latest pricing data of a crypto asset in a single call.

1.Using OKTC price feeds#

Contract address#

OKTC mainnet:

OKTC Testnet:

Code example#

pragma solidity ^0.5.17;
pragma experimental ABIEncoderV2;

interface IExOraclePriceData
{
    function latestRoundData(string calldata priceType, address dataSource) external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
    function get(string calldata priceType, address source) external view returns (uint256 price, uint256 timestamp);
    function getOffchain(string calldata priceType, address source) external view returns (uint256 price, uint256 timestamp);
    function getCumulativePrice(string calldata priceType, address source) external view returns (uint256 cumulativePrice,uint32 timestamp);
    function lastResponseTime(address source) external view returns (uint256);
}

contract Demo {
    address public exOracleAddress;
    
     /**
     * Input an ExOracle contract address
     */
    constructor(address oracle) public {
        exOracleAddress = oracle;
    }
    
    /**
     * @notice Read a single key from an authenticated source. 
     * @param priceType The selector for the value to return
     * @param source The verifiable author of the data
     */
    function getLatestPrice(string memory priceType, address source) public view returns (uint256) 
    {
        IExOraclePriceData oracle = IExOraclePriceData(exOracleAddress);
        (uint256  value, uint256 timestamp) = oracle.get(priceType, source);
        return value;
    }
    
    /**
    * @notice A specific example to get BTC-USD price
    */
    function getBtcPrice() public view returns (uint256) 
    {
        address dataSource = 0x8B83D77C1584e9E1D81d3172608c045E6E5876e5;
        return getLatestPrice("BTC", dataSource);
    }
}

Price feeds API reference#

Import this interface to your contract and use it to run functions in the proxy contract. Create the interface object by pointing to the proxy address.

For example, on OKTC Mainnet you could create the interface object in the constructor of your contract using the following example:

/**
 * Network: OKTC Mainnet
 * Address: 0xF77596928f0823959c2caF4810834FD227244871
 */constructor() {
    priceFeed = ExOraclePriceDataInterface(0xF77596928f0823959c2caF4810834FD227244871);
    }

Functions#

NameDescription
latestRoundDataThe last round data (the most recent data for a given price type and data source)
getRead a single key from an authenticated source
getOffchainGet the price data on off-chain
getCumulativePriceRead a Cumulative Price from an authenticated source
lastResponseTimeTimestamp of last response

latestRoundData#

get the last round data (the most recent data for a given price type and data source)

function latestRoundData(string calldata priceType, address source) external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);

Parameters:

  • priceType: specifies which price to get, i.e. BTC.Please note that upper case letters must be used.
  • source: specifies which data source you want to get the price. i.e. the address of OKX

Return values:

  • roundId: roundId is set to 0
  • answer: answer is the actual value of the priceType
  • startedAt: startedAt is set to 0
  • updatedAt: the timestamp when this answer is submitted to the oracle
  • answeredInRound: answeredInRound is set to 0

get#

Read a single key from an authenticated source

function get(string calldata priceType, address source) external view returns (uint256 price, uint256 timestamp);

Parameters:

  • priceType: specifies which price to get, i.e. BTC.Please note that upper case letters must be used.

  • source: specifies which data source you want to get the price. i.e. the address of OKX

Return values:

  • price: The value of the priceType
  • timestamp: Timestamp of last updated

getOffchain#

Get the price data on off-chain

function getOffchain(string calldata priceType, address source) external view returns (uint256 price, uint256 timestamp);

Parameters:

  • priceType: specifies which price to get, i.e. BTC.Please note that upper case letters must be used.

  • source: specifies which data source you want to get the price. i.e. the address of OKX

Return values:

  • price: The value of the priceType
  • timestamp: Timestamp of last updated

getCumulativePrice#

Read a Cumulative Price from an authenticated source

function getCumulativePrice(string calldata priceType, address source) external view returns (uint256 cumulativePrice,uint32 timestamp);

Parameters:

  • priceType: specifies which price to get, i.e. BTC.Please note that upper case letters must be used.

  • source: specifies which data source you want to get the price. i.e. the address of OKX

Return values:

  • cumulativePrice: Cumulative Price from an authenticated source
  • timestamp: Timestamp of last updated

lastResponseTime#

The timestamp of the last data source response

function lastResponseTime(address source) external view returns (uint256);

Parameters:

  • source: specifies which data source you want to get the price. i.e. the address of OKX

Return values:

  • timestamp: Timestamp of last updated

2.Available Feeds & Refresh Frequency#

We collect data from trusted data source (OKX、Coinbase、Kraken、Coingecko、CoinMarketCap、CryptoCompare and so on) and publish it to our on-chain oracle smart contracts through a robust pipeline.

To ensure accurate data is fed to the smart contracts in a timely manner, OKTC Oracle will feed the price to the smart contracts in regard to two parameters:deviation threshold and heartbeat threshold.

NameDescription
Deviation ThresholdThe deviation of real-world data beyond a certain interval triggers all the nodes to update.
Heartbeat ThresholdIf the data values stay within the deviation parameters, it will only trigger an update every X minutes / seconds.

The list shown below represents the assets that OKTC Oracle currently supports.

PairAssets(priceType)DecimalsDeviation Threshold(%)Heartbeat Threshold(s)
BTC/USDBTC60.160
CHE/USDCHE60.5120
DAI/USDDAI60.1120
DOT/USDDOT60.2120
ETC/USDETC60.2120
ETH/USDETH60.160
FIL/USDFIL60.3120
LINK/USDLINK60.2120
LTC/USDLTC60.3120
OKB/USDOKB60.5120
OKT/USDOKT60.5120
ONT/USDONT60.5120
SUSHI/USDSUSHI60.5120
USDC/USDUSDC60.1120
USDK/USDUSDK60.1120
USDT/USDUSDT60.1120
UNI/USDUNI60.2120
WING/USDWING60.5120