As most witnesses know the popular SteemFeed JS tool created by stops working fairly often. The workaround for this has been to set it to automatically restart every couple hours using a cron job. I've been having a lot of trouble with this lately when even the cron job restart wasn't working.
When I lost 's witness vote due to my price feed being stale (which is a good reason for him to remove his vote - so kudos to him for being on top of that!) I decided it's time to take matters into my own hands!
I'm sure there are other great feed publishing options that work quite well, but as a developer I usually prefer to create my own tools. Not only does it give me full control over how they work but also it's a great learning experience. You have to really understand how something works to build software that automates it.
So I created my own JavaScript/NodeJS price feed publishing software which you can find here: https://github.com/MattyIce/pricefeed
The configuration options are pretty standard:
{
"rpc_nodes": [ // List of RPC nodes to use
"https://api.steemit.com",
"https://rpc.buildteam.io",
"https://steemd.minnowsupportproject.org",
"https://steemd.privex.io",
"https://gtg.steem.house:8090"
],
"account": "witness_account_name", // Name of your Steem witness account
"active_key": "witness_account_private_active_key", // Private active key of your Steem witness account
"interval": 60, // Number of minutes between feed publishes
"peg_multi": 1 // Feed bias setting, quote will be set to 1 / peg_multi
}
As you can see it supports RPC node failover using code borrowed from the Post Promoter voting bot software. If a feed publish transaction fails it will retry once per minute 5 times. After that it will switch to the next RPC node on the list and try that. I'm hoping this will be pretty resilient to the various issues that can arise and keep plugging along publishing prices without much maintenance or upkeep.
It currently pulls the price from the coinmarketcap.com API which takes an average price from all of the different exchanges on which STEEM trades. It would be pretty simple to update the code to pull from any different source that provides a REST API though if needed.
The code is pretty simple, the entire program is only about 75 lines of code (many of which are logging statements), but here's the method to publish the actual feed transaction:
function publishFeed(price, retries) {
var peg_multi = config.peg_multi ? config.peg_multi : 1;
var exchange_rate = { base: price.toFixed(3) + ' SBD', quote: (1 / peg_multi).toFixed(3) + ' STEEM' };
log('Broadcasting feed_publish transaction: ' + JSON.stringify(exchange_rate));
steem.broadcast.feedPublish(config.active_key, config.account, exchange_rate, function (err, result) {
if (result && !err) {
log('Broadcast successful!');
} else {
log('Error broadcasting feed_publish transaction: ' + err);
if (retries == 5)
failover();
if (retries < 10)
setTimeout(function () { publishFeed(price, retries + 1); }, 60 * 1000);
}
});
}
The code first checks if there is a price feed bias set via the "peg_multi" property in the config.json file. Then it creates the "exchange_rate" JSON object which contains the "base" and "quote" prices. Finally it broadcasts the "feed_publish" transaction using the Steem JS Library steem.broadcast.feedPublish() function.
Then it checks the response of the broadcast and if there was an error it tries again every minute and fails over to the next RPC node on the list after 5 failed attempts.
Thanks for your support!
As always I want to thank everyone who has supported my work. It would not be possible without you! Hopefully this tool will help other Steem witnesses run a stable and reliable price feed that doesn't require much maintenance. Also I should note that GINAbot now reports stale price feeds so all witnesses should sign up for that service if they haven't already!
Please see the GitHub project for more details on setup and installation of the tool: https://github.com/MattyIce/pricefeed
Posted on Utopian.io - Rewarding Open Source Contributors