Oracles#
- class defichain.node.Oracles(node)#
- appointoracle(address: str, pricefeeds: [{}], weightage: float, inputs: [{}] = None) str #
Creates (and submits to local node and network) a appoint oracle transaction, and saves oracle to database.
The last optional argument (may be empty array) is an array of specific UTXOs to spend. Requires wallet passphrase to be set with walletpassphrase call.
- Parameters:
address (str) – (required) oracle address
pricefeeds (json array) – (required) list of allowed token-currency pairs
weightage (float) – (required) oracle weightage
inputs (json array) – (optional) Inputs
- Returns:
“hash” (string) – The hex-encoded hash of broadcasted transaction
- Example:
>>> node.oracles.appointoracle("mwSDMvn1Hoc8DsoB7AkLv7nxdrf5Ja4jsF", [{"currency": "USD", "token": "BTC"}, {"currency": "EUR", "token":"ETH"}], 20)
- getdusdswapblock() int #
Get the next block that DFI to DUSD swap will execute on.
- Returns:
n (int) – DFI to DUSD swap execution block. Zero if not set.
- Example:
>>> node.oracles.getdusdswapblock()
- getfixedintervalprice(fixedIntervalPriceId: str) {} #
Get fixed interval price for a given pair.
- Parameters:
fixedIntervalPriceId (str) – (required) token/currency pair to use for price of token
- Returns:
{…} (json) – returns fixed interval price of token
{ 'fixedIntervalPriceId': 'token/currency', 'activePrice': n.nnnnnnnn, 'nextPrice': n.nnnnnnnn, 'activePriceBlock': n, 'nextPriceBlock': n, 'timestamp': n, 'isLive': True|False }
- Example:
>>> node.oracles.getfixedintervalprice("TSLA/USD")
- getfutureswapblock() int #
Get the next block that futures will execute and update on
- Returns:
n (numeric) – Futures execution block. Zero if not set
- Example:
>>> node.oracles.getfutureswapblock()
- getoracledata(oracleid: str) {} #
Returns oracle data in json form
- Parameters:
oracleid (str) – (required) oracle hex id
- Returns:
{…} (string) – oracle data in json form
- Example:
>>> node.noracles.getoracledata()
- getprice(token: str, currency: str) float #
The only argument is a json-form request containing token and currency names
- Parameters:
token (str) – (required) token name
currency (str) – (required) currency name
- Returns:
float – returns price of token in given currency
- Example:
>>> node.oracles.getprice("TSLA", "USD")
- listfixedintervalprices(start: int | None = None, limit: int = 100) {} #
Get all fixed interval prices
- Parameters:
start (int) – (optional) Optional first key to iterate from, in lexicographical order.Typically it’s set to last ID from previous request
limit (int) – (optional) Maximum number of fixed interval prices to return
- Returns:
{…} (json) – returns fixed interval prices
{ 'priceFeedId': 'token/currency', 'activePrice': n.nnnnnnnn, 'nextPrice': n.nnnnnnnn, 'timestamp': n, 'isLive': True|False }
- Example:
>>> node.oracles.listfixedintervalprices()
- listlatestrawprices(token: str, currency: str, start: str | None = None, including_start: bool | None = None, limit: int = 100) {} #
Returns latest raw price updates through all the oracles for specified token and currency
- Parameters:
token (str) – (required) currency name
currency (str) – (required) token name
start (str) – (optional) Optional first key to iterate from, in lexicographical order. Typically it’s set to last ID from previous request
including_start (bool) – (optional) If true, then iterate including starting position
limit (int) – (optional) Maximum number of orders to return
- Returns:
{…} (json) – Array of json objects containing full information about token prices
- Example:
>>> node.oracles.listlatestrawprices("TSLA", "USD")
- listoracles(start: str | None = None, including_start: bool | None = None, limit: int = 100) [] #
Returns list of oracle ids
- Parameters:
start (str) – (optional) Optional first key to iterate from, in lexicographical order. Typically it’s set to last ID from previous request
including_start (bool) – (optional) If true, then iterate including starting position
limit (int) – (optional) Maximum number of orders to return
- Returns:
[…] (array) – list of known oracle ids
- Example:
>>> node.oracles.listoracles()
- listprices(start: int | None = None, including_start: bool | None = None, limit: int = 100) {} #
Calculates aggregated prices for all supported pairs (token, currency)
- Parameters:
start (int) – (optional) Optional first key to iterate from, in lexicographical order.Typically it’s set to last ID from previous request
including_start (bool) – (optional) If true, then iterate including starting position
limit (int) – (optional) Maximum number of orders to return
- Returns:
[{…}] (json array) – array containing json-objects with information
{ 'token': string, 'currency': string, 'price': n.nnnnnnn, 'ok': True|False }
- Example:
>>> node.oracles.listprices()
- removeoracle(oracleid: str, inputs: [{}] = None) str #
Removes oracle, The only argument is oracleid hex value.
- Parameters:
oracleid (str) – (required) oracle id
inputs (json array) – (optional) Inputs
- Returns:
“hash” (string) – The hex-encoded hash of broadcasted transaction
- Example:
>>> node.oracles.removeoracle("0xabcd1234ac1243578697085986498694")
- setoracledata(oracleid: str, timestamp: int, prices: [{}], inputs: [{}] = None) str #
Creates (and submits to local node and network) a set oracle data transaction.
The last optional argument (may be empty array) is an array of specific UTXOs to spend. Requires wallet passphrase to be set with walletpassphrase call.
- Parameters:
oracleid (str) – (required) oracle hex id
timestamp (int) – (required) balances timestamp
prices (json array) –
(required) tokens raw prices:the array of price and token strings in price@token format
[ { (json object) "currency": "str", (string, required) Currency name "tokenAmount": "str", (string, required) Amount@token }, ... ]
inputs (json array) – (optional) Inputs
- Returns:
“hash” (string) – The hex-encoded hash of broadcasted transaction
- Example:
>>> node.oracles.setoracledata("5474b2e9bfa96446e5ef3c9594634e1aa22d3a0722cb79084d61253acbdf87bf", 1612237937, [{"currency":"USD", "tokenAmount":"38293.12@BTC"}, {"currency":"EUR", "tokenAmount":"1328.32@ETH"}])
- updateoracle(oracleid: str, address: str, pricefeeds: [{}], weightage: int, inputs: [{}] = None) str #
Creates (and submits to local node and network) a update oracle transaction, and saves oracle updates to database.
The last optional argument (may be empty array) is an array of specific UTXOs to spend. Requires wallet passphrase to be set with walletpassphrase call.
- Parameters:
oracleid (str) – (required) oracle id
address (str) – (required) oracle address
pricefeeds (json array) –
(required) list of allowed token-currency pairs
[ { (json object) "currency": "str", (string, required) Currency name "token": "str", (string, required) Token name }, ... ]
weightage (int) – (required) oracle weightage
inputs (json array) – (optional) Inputs
- Returns:
“hash” (string) – The hex-encoded hash of broadcasted transaction
- Example:
>>> node.oracles.setoracledata("5474b2e9bfa96446e5ef3c9594634e1aa22d3a0722cb79084d61253acbdf87bf", "mwSDMvn1Hoc8DsoB7AkLv7nxdrf5Ja4jsF", [{"currency":"USD", "tokenAmount":"38293.12@BTC"}, {"currency":"EUR", "tokenAmount":"1328.32@ETH"}], 20)