Automating Hive with Karaka Tutorial #7: Hive Token Price Tickers (an oracle)
engine·@eturnerx·
0.000 HBDAutomating Hive with Karaka Tutorial #7: Hive Token Price Tickers (an oracle)
 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: + [Karaka Tutorial #5: Oracles](https://hive.blog/engine/@eturnerx/karaka-tutorial-5-oracles) 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](https://hive.blog/engine/@eturnerx/karaka-tutorial-5-oracles), 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](https://help.splinterlands.com/dec/faq-dec) 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](https://peakd.com/engine/@eturnerx/karaka-tutorial-1-a-basic-tutorial-configjson-example) 1. [Karaka Tutorial #2: Hive-Engine Tokens](https://peakd.com/engine/@eturnerx/d-buzz-not-working-on-5e8a5c9a21c53) 1. [Karaka Tutorial #3: Constants](https://peakd.com/engine/@eturnerx/karaka-tutorial-3-constants) 1. [Karaka Tutorial #4: Import facts between chains](https://peakd.com/engine/@eturnerx/karaka-tutorial-4-import-facts) 1. [Karaka Tutorial #5: Oracles](https://hive.blog/engine/@eturnerx/karaka-tutorial-5-oracles) 1. [Karaka Tutorial #6: foreach saving you time and space](https://hive.blog/engine/@eturnerx/karaka-tutorial-6-foreach-saving)
👍 a-alice, brazilians, dudutaulois, mynotsofitlife, truthtrader, leodelara, wlffreitas, brofund, brofi, roleerob, upfundme, penderis, ma1neevent, steembasicincome, smokingfit, anikys3reasure, piestrikesback, buildingpies, sbi-tokens, qwertm, sbi2, jerrybanfield, ninnu, sbi3, sbi4, gamer00, sbi5, sbi6, sbi7, sbi8, ambyr00, kiemis, oadissin, yestermorrow, hyborian-strain, msp-shanehug, iamthegray, msp-music, hivewatchers, schoolforsdg4, azizbd, darth-azrael, darth-cryptic, retrodroid, sovstar, cryptopi314, preparedwombat, stea90, tattoodjay, davidbright, abbak7, leoball, slobberchops, liz.writes, andrastia, discohedge, dhedge, dhedge-drips, steemflow, indiaunited, codingdefined, spydo, jatinhota, apokruphos, deimage, khan.dayyanz, lifecruiser, bobinson, shonyishere, bala41288, dynamicrypto, kamaleshwar, chandra.shekar, kannannv, frames, godfather.ftw, punkblogs, olaexcel, kanibot, sayee, cryptictruth, leninbracho50, maujmasti, esportleague, chinito, jedigeiss, balaz, resonator, ura-soul, informationwar, leprechaun, ausbitbank, ironshield, truthforce, risemultiversity, dmwh, empress-eremmy, deepdives, riskneutral, n0m0refak3n3ws, shanhenry, delver, investinfreedom, stevescoins, v4vapid, wakeupnd, atma.love, commonlaw, clownworld, jimbobbill, maxsieg, sansey, louisthomas, iktisat, denizcakmak, ledinis, fherdz, tookta, fatman, rynow, artgrafiken, appreciator, xappreciator, x30, roadstories, myfreshes, discoveringarni, lucianav, adedayoolumide, cielitorojo, trouvaille, aprasad2325, blackdaisyft, detlev, bluemist, lenasveganliving, sunsea, anikekirsten, outlinez, kgakakillerg, elmundodexao, marblely, daysiselena, zeesh, actioncats, noalys, elgatoshawua, hexagono6, power-kappe, fotomaglys, fairyberry, mcookies, femcy-willcy, gardenofcarmen, kirito-freud, honeymoon-1611, jvphotography, damian-z, roadstories.trib, quycmf8, noelyss, inciter, marblesz, coolsurfer, kattycrochet, vancouverdining, iptrucs, beerlover, assan, freebornsociety, phusionphil, steemvpn, timhorton, cerberus-dji, hivecannabis, hive-vpn, zelegations, josemalavem, theguruasia, marcusantoniu26, prydefoltz, newsflash, barski, fredkese, bosveld1, datsir, tangmo, gidlark, santigs, hairyfairy, macchiata, fourfourfun, bcarolan639, not-sure,