Image source: Wikipedia
Yup, we got just another witness feed publishing tool!
There are other scripts but not much Lua stuff for STEEM out there, so I had to do something about it :P
How STEEM and SBD market prices are calculated
The script uses several sources, the fastest one so far is Coinmarketcap, which has an specific STEEM-USD and SBD-USD pairs already available from its public API. Nothing to calculate, just fetch and use straight!
Yet, what happens if for some reason Coinmarketcap is not available? We should use other APIs. Poloniex, Blockchain and Coindesk provide BTC-USD pairs. Then we need the BTC-STEEM and BTC-SBD pairs, which are provided by Poloniex and Bittrex (currently the main exchanges supporting STEEM).
On each run the script fetches ALL pairs, resulting into the following Lua table (array-object mix):
{
sbd_usd = {
["coinmarketcap"] = 0.970959
}
btc_steem = {
["bittrex"] = 0.00018021
["poloniex"] = 0.00018
}
btc_usd = {
["poloniex"] = 5619.99999935
["coindesk"] = 5612.7788
["blockchain"] = 5610.62
}
steem_usd = {
["coinmarketcap"] = 1.01587
}
btc_sbd = {
["bittrex"] = 0.00017258
["poloniex"] = 0.00017225
}
}
Guess what is next? Calculate averages! Since we have some pairs with two or more alternatives. YET if for some reason one of the public APIs is not available, it will then be missing from that table, hopefully we have several APIs available. Don't worry dude ;)
This is the Lua table for prices averages:
{
sbd_usd = 0.970959
btc_steem = 0.000180105
btc_usd = 5614.46626645
steem_usd = 1.01587
btc_sbd = 0.000172415
}
Sweet huh?
The script then validates what is available into the averages table, if BTC-STEEM and BTC-USD pairs are available, then it will calculate a second STEEM-USD pair.
If the first STEEM-USD pair is not available, then the second pair will be used. If both are available the script will calculate an average of both.
Exactly the same logic as above is applied for BTC-SBD and STEEM-SBD pairs.
Install the script and publish the feed
You need Luarocks installed in your box, along with the UUID dev headers (uuid-dev
package in ubuntu). Then install seawolf:
$ apt install uuid-dev
$ luarocks install seawolf
That stuff above will install all required dependencies.
Now just clone the lazy-steem repo:
$ git clone https://github.com/develCuy/lazy-steem
$ cd lazy-steem
You are all set!
Running the script is pretty easy! Pass it your witness username, the remote address, protocol and port of your cli_wallet instance when running the script, like this:
$ ./publish_feed.lua dropahead http://localhost:8093
Yeah! https is supported :D
The script connects to cli_wallet once that all calculations are done by the script and it has the desired STEEM-USD and SBD-USD pairs. Otherwise it will just finish silently.
Running the script automagically every X minutes
This is something obvious for sysadmins but you might ignore it so... Use the power of cron! Example of cron setup (you are really so lazy folks!):
# m h dom mon dow command
15 * * * * cd /path/to/lazy-steem/; ./publish_feed.lua dropahead http://localhost:8093 > /dev/null
You'll find 10+ years of docs about cron in google, so doy your homework lame slacker! :P
Done?
Of course not! If you liked this stuff then vote @dropahead for witness!
Talk is cheap, code is gold! You had better start a pull request if you want to say something about my precious code. Here: https://github.com/develCuy/lazy-steem
Happy hacking and keep steeming hard!