create account

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

View this thread on: hive.blogpeakd.comecency.com
· @eturnerx ·
$24.64
Automating Hive with Karaka Tutorial #7: Hive Token Price Tickers (an oracle)
![image.png](https://images.ecency.com/DQmUcqK2BoE1TFDnW7dU2YeFzvX2CubUqzuWPYqFDxCPKYM/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:
+ [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)
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 128 others
👎  ,
properties (23)
authoreturnerx
permlinkautomating-hive-with-karaka-tutorial-7-hive-token-price-tickers-an-oracle
categoryengine
json_metadata"{"app":"peakd/2022.12.1","format":"markdown","description":"Use Karaka to automate actions based on hive engine prices. Introducing the Hive Engine Token Price Ticker oracle.","tags":["engine","palnet","karaka","automation","tutorial","typescript","script","dev","nodejs"],"users":["eturnerx"],"image":["https://images.ecency.com/DQmUcqK2BoE1TFDnW7dU2YeFzvX2CubUqzuWPYqFDxCPKYM/image.png"]}"
created2023-01-03 19:44:30
last_update2023-01-03 19:44:30
depth0
children8
last_payout2023-01-10 19:44:30
cashout_time1969-12-31 23:59:59
total_payout_value12.332 HBD
curator_payout_value12.306 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length4,726
author_reputation103,695,946,143,660
root_title"Automating Hive with Karaka Tutorial #7: Hive Token Price Tickers (an oracle)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id119,590,526
net_rshares62,968,734,913,710
author_curate_reward""
vote details (194)
@chinito ·
$0.04
👷‍♂️😎🤙 Cool stuff! good info is key.
👍  
properties (23)
authorchinito
permlinkre-eturnerx-rnxs3o
categoryengine
json_metadata{"tags":["engine"],"app":"peakd/2022.12.1"}
created2023-01-04 00:59:48
last_update2023-01-04 00:59:48
depth1
children0
last_payout2023-01-11 00:59:48
cashout_time1969-12-31 23:59:59
total_payout_value0.018 HBD
curator_payout_value0.018 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length36
author_reputation185,372,573,588,972
root_title"Automating Hive with Karaka Tutorial #7: Hive Token Price Tickers (an oracle)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id119,596,766
net_rshares92,875,167,159
author_curate_reward""
vote details (1)
@fredkese ·
$0.03
Making life easier by the day. Good tool and a great innovation 
👍  
properties (23)
authorfredkese
permlinkre-eturnerx-ro17ma
categoryengine
json_metadata{"tags":["engine"],"app":"peakd/2022.12.1"}
created2023-01-05 21:27:48
last_update2023-01-05 21:27:48
depth1
children0
last_payout2023-01-12 21:27:48
cashout_time1969-12-31 23:59:59
total_payout_value0.014 HBD
curator_payout_value0.015 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length64
author_reputation171,886,943,758,195
root_title"Automating Hive with Karaka Tutorial #7: Hive Token Price Tickers (an oracle)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id119,644,641
net_rshares73,967,724,903
author_curate_reward""
vote details (1)
@indiaunited ·
Indiaunited Curation 1672789057652
This post has been manually curated by @steemflow from Indiaunited community. Join us on our [Discord Server](https://discord.gg/bGmS2tE). 

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](https://hivesigner.com/sign/delegateVestingShares?delegator=&delegatee=indiaunited&vesting_shares=179645.9083407081%20VESTS), [250HP](https://hivesigner.com/sign/delegateVestingShares?delegator=&delegatee=indiaunited&vesting_shares=449114.77085177024%20VESTS), [500HP](https://hivesigner.com/sign/delegateVestingShares?delegator=&delegatee=indiaunited&vesting_shares=898229.5417035405%20VESTS), [1000HP](https://hivesigner.com/sign/delegateVestingShares?delegator=&delegatee=indiaunited&vesting_shares=1796459.083407081%20VESTS). 

[![image.png](https://files.peakd.com/file/peakd-hive/bala41288/46eaz12N-image.png)](https://discord.gg/bGmS2tE) 

<sub>**Please contribute to the community by upvoting this comment and posts made by @indiaunited.**</sub>
properties (22)
authorindiaunited
permlinkindiaunited-1672789057652
categoryengine
json_metadata{"app":"hiveblog/0.1","tags":["engine","palnet","karaka","automation","tutorial","typescript","script","dev","nodejs"]}
created2023-01-03 23:37:45
last_update2023-01-03 23:37:45
depth1
children0
last_payout2023-01-10 23:37:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,199
author_reputation95,041,759,723,078
root_title"Automating Hive with Karaka Tutorial #7: Hive Token Price Tickers (an oracle)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id119,595,341
net_rshares0
@malos10 ·
!luv
properties (22)
authormalos10
permlinkre-eturnerx-2023117t19326943z
categoryengine
json_metadata{"tags":["engine","palnet","karaka","automation","tutorial","typescript","script","dev","nodejs"],"app":"ecency/3.0.30-vision","format":"markdown+html"}
created2023-01-17 23:03:27
last_update2023-01-17 23:03:27
depth1
children1
last_payout2023-01-24 23:03:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length4
author_reputation647,665,892,545,600
root_title"Automating Hive with Karaka Tutorial #7: Hive Token Price Tickers (an oracle)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id119,966,894
net_rshares0
@luvshares ·
@eturnerx, @malos10<sub>(1/1)</sub> sent you LUV. | <a
    href="https://crrdlx.websavvy.work/" style="text-decoration:none">tools</a> | <a 
    href="https://discord.gg/K5GvNhcPqR" style="text-decoration:none">discord</a> | <a href="https://peakd.com/c/hive-159259">community | <a 
    href="https://crrdlx.websavvy.work/wiki/doku.php?id=start" style="text-decoration:none">HiveWiki</a> | <a href="https://peakd.com/nftforpeace/@hivebuzz/nft-for-peace" target="_blank"><img src="https://files.peakd.com/file/peakd-hive/crrdlx/Epvkqd2sQEjZxu93x3A2J2fztKDarTY17qgMbpqWRV14NrfNBA6fu1jxtTkZztjXZKo.gif" target="_blank"></a> <a href="https://peakd.com/nftforpeace/@hivebuzz/nft-for-peace" target="_blank">NFT</a> | <a href="https://ichthys.netlify.app" style="text-decoration:none"><>< daily</a>
<center>Made with <a href="https://peakd.com/@luvshares" target="_blank"><img src="https://files.peakd.com/file/peakd-hive/crrdlx/AKKSsM8HYHY5o4R1UPRdUADTz5QpsKAxSH5uyxsK4k1AJz5wsBqm7TfvA8aSCjE.png"></a> by <a href="https://hive.blog/@crrdlx" target="_blank">crrdlx</a></center>
properties (22)
authorluvshares
permlinkre-re-eturnerx-2023117t19326943z-20230117t230353z
categoryengine
json_metadata"{"app": "beem/0.24.26"}"
created2023-01-17 23:03:54
last_update2023-01-17 23:03:54
depth2
children0
last_payout2023-01-24 23:03:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,070
author_reputation5,651,102,754,153
root_title"Automating Hive with Karaka Tutorial #7: Hive Token Price Tickers (an oracle)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id119,966,902
net_rshares0
@poshtoken ·
https://twitter.com/1497016371355750401/status/1610363283923701761
<sub> The rewards earned on this comment will go directly to the people( @eturnerx ) sharing the post on Twitter as long as they are registered with @poshtoken. Sign up at https://hiveposh.com.</sub>
properties (22)
authorposhtoken
permlinkre-eturnerx-automating-hive-with-karaka-tutorial-7-hive-token--1406
categoryengine
json_metadata"{"app":"Poshtoken 0.0.1","payoutToUser":["eturnerx"]}"
created2023-01-03 19:52:39
last_update2023-01-03 19:52:39
depth1
children0
last_payout2023-01-10 19:52:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length267
author_reputation5,148,213,386,933,320
root_title"Automating Hive with Karaka Tutorial #7: Hive Token Price Tickers (an oracle)"
beneficiaries
0.
accountreward.app
weight10,000
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id119,590,698
net_rshares0
@theguruasia ·
$WINE
properties (22)
authortheguruasia
permlinkre-eturnerx-rnzuja
categoryengine
json_metadata{"tags":["engine"],"app":"peakd/2022.12.1"}
created2023-01-05 03:47:36
last_update2023-01-05 03:47:36
depth1
children1
last_payout2023-01-12 03:47:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5
author_reputation72,541,003,040,813
root_title"Automating Hive with Karaka Tutorial #7: Hive Token Price Tickers (an oracle)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id119,625,647
net_rshares0
@wine.bot ·
<center>
<sup>Congratulations, @theguruasia You Successfully Shared <b>0.800</b> <b>WINEX</b> With @eturnerx.</sup>
<sup>You Earned <b>0.800</b> <b>WINEX</b> As Curation Reward.</sup>
<sup>You Utilized <b>4/4</b> Successful Calls.</sup>

<img src="https://images.hive.blog/DQmSWfbie9MTC172sENiA16bsMaz1ofT6AAyTo1ishasrcX/winexcomment.png" alt="wine_logo">

---
<sup>Contact Us : [WINEX Token Discord Channel](https://discord.gg/rS3KzjJDCx)</sup>
<sup>[WINEX Current Market Price](https://hive-engine.com/?p=market&t=WINEX) : <b>0.153</b></sup>
---
<sup>Swap Your <b>Hive <=> Swap.Hive</b> With Industry <b>Lowest Fee (0.1%)</b> : [Click This Link](https://swaphive.github.io/swap/)</sup>
<sup>[Read Latest Updates](https://peakd.com/@hiveupme/posts) Or [Contact Us](https://discord.gg/rS3KzjJDCx)</sup>
</center>
properties (22)
authorwine.bot
permlink20230105t034903221z
categoryengine
json_metadata{"tags":["wine","token","winebot"],"app":"wine-bot/4.0","format":"markdown"}
created2023-01-05 03:49:03
last_update2023-01-05 03:49:03
depth2
children0
last_payout2023-01-12 03:49:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length827
author_reputation8,092,913,767,308
root_title"Automating Hive with Karaka Tutorial #7: Hive Token Price Tickers (an oracle)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id119,625,677
net_rshares0