Worth.sh - A script to fetch and display account value, STEEM/SBD value
I wrote a Bash script that will display the total value of your steem holdings, the current value of steem, the current value of SBD, and the ratio of the values of STEEM to SBD.
Why
I make it a point to not visit Steemit.com while I'm working. But I'm always curious how the price of STEEM and SBD are doing. I found myself googling things like STEEM in USD and STEEM SBD in USD and afterwords I'd clumsily do some ballpark math in my head to figure out roughly what my account was worth. Well, that got tiring, so I wrote a script for it.
How
I fetch the current price of SBD and STEEM in USD, then I multiply these numbers by how much I have and then display it. The prices are fetched from Crypto Compare which has a really simple JS API, so I just use wget
to fetch that. Except then I have to throw away all that pesky JSON syntax so I can get the raw numbers. Then I use the bc
command to do the math. If I were to just use Bash it wouldn't do floating point.
Then I echo the result and have the script sleep for a while. I leave this running at home and at work and then I can see, at a glance, what everything is worth.
I left quite a few of the values in the script in their own variables in case anyone else would like to display any of the other numbers used in the calculation.
What
Anyway, here's the script. It's dirt simple and doesn't do any error checking or accept any arguments because it was all about convenience.
#!/bin/bash
MY_SBD=2.3
MY_STEEM=244.0
DELAY=600
while true ; do
read STEEM < <(wget 'https://min-api.cryptocompare.com/data/price?fsym=STEEM&tsyms=USD' -O- 2>/dev/null)
read SBD < <(wget 'https://min-api.cryptocompare.com/data/price?fsym=SBD&tsyms=USD' -O - 2>/dev/null)
STEEM=$(echo ${STEEM} | cut -f2 -d:| cut -f1 -d})
SBD=$(echo ${SBD} | cut -f2 -d:| cut -f1 -d})
SV=$(echo "${STEEM} * ${MY_STEEM}" | bc)
SBDV=$(echo "${SBD} * ${MY_SBD}" | bc)
HOLDINGS=$(echo "${SV}+${SBDV}" | bc)
echo "${HOLDINGS} (${STEEM}) (${SBD}) ratio s/sbd: $(echo "scale=2; ${STEEM}/${SBD}" | bc -l)"
sleep $DELAY
done
Using it
Edit the MY_SBD variable to say how much SBD your account has.
Edit the MY_STEEM variable to say how much STEEM your account has.
That's it, run it!
Here's what the output looks like:
Limitations
It doesn't fetch the counts for holdings. That data is gzipped json and kind of ugly. If anyone wants a script that does that, leave a comment and I could look at writing one for another post.
References
Image source is Pixabay
If you liked this, you might be interested in some of my previous Bash-related posts:
- Bash/Linux Tip: dircolors
- Bash Script Examples (Directory Navigation)
- Bash Script Examples - Processing Lists of Files
- Bash Script Examples (continued, still very very basic)
- Bash Script Examples (very very basic)
- Linux Tips - DRYing up the Bash (incremental search)
Ooh fun. Now it just needs some spinners and you're golden. I think I'll run this for fun too.
Be sure to edit MY_SBD and MY_STEEM so it actually displays your account values.
A spinner to do what?
The fancier bash graphical things. I think you could even make a scrolling ticker too. I'm not sure how they work though.
I know what you meant by a spinner, and I know how to make them work, but I wasn't sure what it should be used it indicate in the context of this script.
Good question. I don't really know either. An idling spinner for no reason was what I had in mind.