Automating Hive with Karaka Tutorial #7: Hive Token Price Tickers (an oracle)

image.png

Karaka is an Automation (clerk) for Hive and Hive Engine blockchains. Get Karaka from https://github.com/Stormrose/karaka

Karaka is a Maori word meaning variously: an English loanword for 'clerk' or 'clock' and a significant coastal plant 'Corynocarpus laevigatus'.

Karaka's Oracles

An oracle allows Karaka to assert facts based on information outside the blockchain, such as pricing information. This tutorial introduces the Hive Engine Token Price Ticker oracle. For more information about using Karaka's oracles, start here:

There are more tutorials linked at the end of this post.

Using Hive Engine Token Ticker oracle

The oracle section is an [array] of {oracle objects} that lives in the top level of the config.json file. The Hive Engine Token Ticker oracle has the type of hiveengineorderbook. Specify the array of token symbol names inside params. Exercise restraint with the token list because token names generate sequential synchronous API calls and may slow down the fact-gathering process.
In the following example, the oracle retrieves tickers for the DEC, BEE and WORKERBEE tokens.

"oracles": [
    { "type": "hiveengineorderbook", "params": { "tokens": [ "DEC", "BEE", "WORKERBEE" ]}}
]

The fact names generated are:

prefixTOKENNAME_type

Where prefix is the oracle's prefix (default: hem), and the _type is one of price, ask or bid. The example config above generates the following facts:
hemDEC_price, hemDEC_bid, hemDEC_ask,
hemBEE_price, hemBEE_bid, hemDEC_ask,
hemWORKERBEE_price, hemWORKERBEE_bid, hemWORKERBEE_ask

The pricing is generally in SWAP.HIVE. The _bid and _ask tickers are probably more helpful than _price when a market is thinly traded or widely spread. Use the _bid price when reasoning about selling and the _ask price for reasoning about buying.

Example Rule

Karaka uses oracle-generated facts like any other facts. For example, this rule will only sell the BEE token when the account @eturnerx has at least 1 BEE, and the bid price is 1 SWAP.HIVE or higher.

{ "if": "eturnerx.BEE_balance > 1 and hemBEE_bid >=  1",
  "then": "sell (eturnerx.BEE_balance) BEE for SWAP.HIVE from @eturnerx at market" }

What if I want to price in USD?

The tickers provided by hive-engine's API are typically in SWAP.HIVE - which is pegged to HIVE but has a small fee for transfers to and from HIVE. You can approximate the USD price of a token by combing SWAP.HIVE ticker with the HIVE to USD price from the Coingecko oracle, specifically using the fact named cgHIVEUSD.
In the following example rule, the account eturnerx will sell DEC when it has more than 10 DEC and the bid price for the DEC token is at or above the par value of a tenth of a US cent.

{ "if": "eturnerx.DEC_balance > 10 and (hemDEC_bid * cgHIVEUSD) >=  0.001",
  "then": "sell (eturnerx.DEC_balance) DEC for SWAP.HIVE from @eturnerx at market" }

Advanced config

The default prefix for fact names is hem, but you can specify your own.

{ "type": "hiveengineorderbook",
  "prefix": "myprefix",
  "params": { "tokens": [ "DEC", "BEE", "WORKERBEE" ]}
}

The token name can be specified as a bare string without the array brackets if you have just one token in the list. Karaka tries to keep its config files human-readable.

{ "type": "hiveengineorderbook", "params": { "tokens": "WORKERBEE" }}

Summary

Good decisions require good information. By adding the Hive Engine Token Ticker oracle, Karaka enhances your ability to automate your experience and thus save you time. More oracles can be added based on demand, so please ask for what you need.

Until next time.

Previous tutorials

  1. Karaka Tutorial #1: A Basic Tutorial config.json example
  2. Karaka Tutorial #2: Hive-Engine Tokens
  3. Karaka Tutorial #3: Constants
  4. Karaka Tutorial #4: Import facts between chains
  5. Karaka Tutorial #5: Oracles
  6. Karaka Tutorial #6: foreach saving you time and space


0
0
0.000

8 comments

👷‍♂️😎🤙 Cool stuff! good info is key.

0
0
0.000

Making life easier by the day. Good tool and a great innovation

0
0
0.000

This post has been manually curated by @steemflow from Indiaunited community. Join us on our Discord Server.

Do you know that you can earn a passive income by delegating to @indiaunited. We share more than 100 % of the curation rewards with the delegators in the form of IUC tokens. HP delegators and IUC token holders also get upto 20% additional vote weight.

Here are some handy links for delegations: 100HP, 250HP, 500HP, 1000HP.

image.png

Please contribute to the community by upvoting this comment and posts made by @indiaunited.

0
0
0.000