Another Price Feed Publishing Tool for Witnesses

in #utopian-io7 years ago (edited)

price_feed.JPG

As most witnesses know the popular SteemFeed JS tool created by @someguy123 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 @drakos'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

Sort:  

Thank you for the contribution. It has been approved.

Great job on price feeder, and nice touch with the nodejs instructions. It used to always gives me trouble on Ubuntu.

You can contact us on Discord.
[utopian-moderator]

Hey @helo, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!

Loading...

Awesome, I have had my price feed not update a few times so may try this out. I like how it has fallback if a node isn't available.

FIXED!

@yabapmatt in one feel swoop earneds my witness vote

Thank you! Glad it has helped you!

A coding master and a kind and helpful witness. Thanks for providing another tool for steemit. Im learning Javascript to match you guys one day! Youre the best :)

@yabapmatt Brother please talk to me i have been removed from your bot list due to a person make false blame you can ask any question i am trustworthy i will answer you

@lays please contact me on Discord or Steemit.Chat and we can discuss further.

@lays made good on his votes
I have offrerd my help communicating with vote guyers for him if in the future he ever gets buried again with request like happened this time.

Beat me to it! I've been needing this since the other script has been really unreliable recently. Thanks for creating it.

I have just sign up for utopian.io
But i don't know how to get started

Thanks for providing another important tool for steemit . Really this is helpful.have a nice day.

The best master post

you are doing a great work in this platform @yabapmatt

@yabapmatt sorry to bother you on your post but please looking into the voting bot @boomerang. it is taking bids but not upvoting. myself and many others have lost our money and there's no response. please help us

if you look at boomerang's latest post and in the comment section you will see all the complaint, including mine. thanks

Thanks matt! Really appreciate that - pricefeed was fairly inconsistent the last few days.

Hey @yabapmatt I am @utopian-io. I have just upvoted you!

Achievements

  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

@yabapmatt excellent for making these tools unique to the community.

@yabapmatt excelente por realizar estas herramientas unicas para la comunidad

amazing news and post,,,thanks for sharing

You got a 100.00% upvote from @mitsuko courtesy of @yabapmatt!

Thanks for being on top of this! You never lost my vote. In my opinion, we need more witnesses to have a bias percent as high as yours!

This post has been just added as new item to timeline of Witness Price Feed on Steem Projects.

If you want to be notified about new updates from this project, register on Steem Projects and add Witness Price Feed to your favorite projects.