SteemJS Tools - Witness Price Feed in NodeJS

in #witness-category6 years ago (edited)

For a long time I've been using the legendary Steemfeed-JS by @someguy123. However, it uses the outdated https://github.com/svk31/steemjs-lib which is buggy and causes script crashes every once in a while. Also, Steemfeed-JS is only working for Bittrex prices now that Poloniex has been utterly unreliable with its disabled STEEM/SBD wallet therefore having much lower traded volumes with a different (lower) price than the rest of the exchanges.

There are other price feed scripts out there, but I decided to write my own for several reasons.

  • Programming is fun.
  • Learn something new.
  • Customize the tool to my liking.
  • Address and fix the problems in Steemfeed-JS.
  • Average the price from the major exchanges: Binance, Bittrex, Huobi and UpBit.

STEEM Price Feed

A price feed application written in NodeJS for witnesses on the Steem network.

Features

  • Application resilience with NodeJS restart on crash/exit.
  • Automatic RPC switching.
  • Averaged price from up to 5 major cryptocurrency exchanges.

Pre-install (e.g. Ubuntu 16.04)

Requires NodeJS >7.6 (for the async functions).

sudo apt update
sudo apt install -y curl software-properties-common gnupg build-essential libssl-dev
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt install -y nodejs
sudo npm i npm@latest -g

Install

git clone https://github.com/Jolly-Pirate/pricefeed.git
cd pricefeed
cp app/config.json.example app/config.json
chmod 600 app/config.json

Edit the app/config.json then install and start the app

npm install
npm start

Screen session example

Start and enter a screen session: screen -S pricefeed

Start the script: npm start

Detach from the screen session with CTRL-a-d. This will leave it running in the background.

Reattach to the session with screen -x pricefeed to monitor its status.

If you want to terminate the script press CTRL-c, then type exit to close the session.


Docker install (recommended)

git clone https://github.com/Jolly-Pirate/pricefeed.git
cd pricefeed
chmod +x run.sh
./run.sh install_docker
./run.sh build

Edit the file app/config.json accordingly (see the section below), then start the container with

./run.sh start

Check that it's running fine with ./runs.sh logs

Type ./run.sh without arguments for a list of options.


Configuration

The configuration is located in the file app/config.json.

  • witness: witness account
  • privateActiveKey : private active key of the witness account
  • interval : delay between each feed publishing.
  • peg : set to true only if you want to adjust your price feed bias.
  • peg_multi : if the peg is enabled, then this will change the "quote" to 1 / peg_multi, e.g. a peg_multi of 2 it will show a 100% bias on the feed.
  • rpc: Steem RPC nodes

The different exchanges can be set to true or false. Poloniex is set to false by default because of their constant wallet problems.

The script is set to publish the price feed every 6 hours by default which is very acceptable. I included a docker setup for easy deployment.

example.png

Source code at https://github.com/Jolly-Pirate/pricefeed

I hope you like it. Please report any bugs or if you have any improvement suggestions.


Available & Reliable. I am your Witness. I want to represent You.

🗳 If you like what I do, consider voting for me 🗳

Vote

If you never voted before, I wrote a detailed guide about Voting for Witnesses.

Go to https://steemit.com/~witnesses. My name is listed in the Top 50. Click once.

Alternatively you can vote via SteemConnect

https://v2.steemconnect.com/sign/account-witness-vote?witness=drakos&approve=1

Sort:  

I really appreciate your work IMG_20180523_045454.jpg

Hi i am lija so sad but i am steemit account not a upvote please help me friend please only give me upvote me

Congracts for new post keep up the good work with steemit a resteem from my side best of luck Advance. Cheers...... @drakos

Great work on nodejs @drakos

I voted for you as a witness
Because you are a very successful and wonderful person
And help everyone dear
Thank you for the wonderful effort

Ah finally! I was going to start my own but now that you did it I’m got be lazy 😜

Thanks for sharing

It’s fun seeing you play with your code for all our benefit :) You’re one of my favorite witnesses.

Hi. Was going through my witness list, which was long overdue. I saw your name and somehow I could not recall you being on the witness list. I saw that you were close to the top 20, so I checked out your witness post (through Steemian.info, btw). Very impressive. So I checked out a few posts and saw the one about the spaghetti western comedy. Nice. So I went to your most recent post and gave you an upvote and voted for you as witness. Since they were playing cards, I also thought you might be a poker player. If you are a poker fan, stop by at https://discord.gg/tYSFja. We play poker at lucksacks.com with SBD as the unit of exchange. Love to have you stop by if you have time. Thanks for all you do for the Steem world.

Indeed I'm a poker fan, in fact I used to play at Lucksacks. Maybe I'll pop in again.

That would be great. I will tell @tuck-fheman to get you approved as soon as possible. When you pop in there, let me know and I will set that up for you.

Being independent is good. That's a nice effort. Thanks for the innovative post.

I do not get along with the programming, but I see that you do! Excellent work

Thank you for your work @drakos . You are my favorite Witness, because you support art ❤ But for the first time I hear that programming is fun. My husband is a programmer, and I often see the screen of his computer. In my opinion, this is too difficult 😊
I'll show my husband your post. Perhaps your advice will be useful to him.

@drakos, I don't understand the programming language, but I support you master. :)

That's a good one

Wow what a great job, programmers should consider themselves an artist, for my programming it is a work of art.

Feel relieved that you do not know me in person because if I do not spend the whole day asking you to teach me how to program hehehe 😍

Dammit. If i ever decide to run for witness in 25 years, seems id need to buy a programmer. Keep him/her locked away hammering at those blocks. haha..
Hmmm. @jesta seems capable... leaves to buy a net and some cake for bait.

One more thing. Im trying to help out OpenMic this week. Im donating all my SBD from a post i wrote on "Enlightened self interest".. (its a bit of a long read). I pinged you but you might have missed it.
OpenMic is running at a loss for weeks now since Pfunk dropped from Top 20, so im trying to help fill up their reward pool. The post is already at 74$ so theres the bonus of some delegation for you and you will be doing a good deed. :D

Hi @drakos!

Your post was just upvoted by @utopian-io. We invite you to join our developer community on the Steem blockchain to crowdsource your project development and promotion with Utopian.

Contributing on Utopian

Learn how to contribute on our website.

Want to chat? Join us on Discord https://discord.gg/h52nFrV

Master frankly your have match on steemit, i adorn your precious blog.
My regards to you boss.

thanks for the informative post
(Would be great if you could support my latest post;)

Hello!
Good post!

vote for vote

Muy Creativo. seguire tus publicaciones...

Awesome! I'll try your tool because I'm tired of mistakes like "SteemApi error:get_required_signatures"
steemfeed js error

Great post @drakos i don't know if you remember but you were the one who helped me get started on steemit and told me how i can buy my account as i was getting impatient from waiting hehe I just voted for you as a witness :) and as i grow even more here on this platform i will remember how lovely and helpful you were :) I hope you have an awesome day :D

Keep up the great work there @drakos I have toted for you too.

Thanks for sharing the price feed script. pm2 may be a better solution to keep the price feed process up instead of tmux, screen, etc.

I'm actually using forever with the script. It has the option to start a process as a service like pm2 does. Nevertheless, if you use the dockerized installation you don't need to worry about screen or tmux, it's all taken care of :)