Bug Fixes
fixed #1 - added null argument to get_current_median_history_price call
fixed #2 - unhide cursor on ticker exit
fixed duplicate method entry
Discovered these issues while running the scripts and playing with the functions in functions.sh.
New Features
Moved ticker style functionality to its own function and put it into functions.sh ee3dfc15a3ffc8ff0e0f337c84ae787fdf4ecde2.
Created balances.sh f12da076103377308e38b953983f55443ccb3d30 to replace all of the ticker scripts and provide new functionality:
added argument parsing for tenable output
User can choose
display full account value
display balances (sbd, steem, savings) [default]
display SP
display pending payouts [new] added here and then here
made ticker format optional (can do one-shot and exit)
added ability to display other output currencies (try LTC, for example) [new]
This is used for:
full account value option
pending payout option
added ability to specify the service endpoint (future proofing) [new]
minimized external service calls (speedup)
How did you implement it/them?
The pending payout calculation is the full pending payout, before subtracting any curation. Little more to do here, but good start. It was implemented using the rpc_get_discussions_by_author_before_date, giving it the provided author and today's date as a starting point and going back to the last N posts (10 originally, updated to be configurable).
This is how the get_payout function was implemented:
##
# get_payout <AUTHOR> <LIMIT> [ENDPOINT]
# Gets the specified author's pending payouts as a sum of SBD.
get_payout(){
local AUTHOR=${1}
local WHEN=$(date -Iseconds)
local LIMIT=${2:-}
local PAYOUTS=$(rpc_get_discussions_by_author_before_date "${AUTHOR}" '' "${WHEN}" "${LIMIT}" "${ENDPOINT}" | grep -Po '"pending_payout_value":.*?[^\\]",' | cut -f2 -d: | cut -f2 -d'"' | cut -f1 -d' ' | xargs)
VALUE=$(math "$(sed 's/ /+/g' <<< "${PAYOUTS}")" 2)
echo "${VALUE}"
}
The get_discussions_by_author_before_date rpc call is used because it looked like the only one that clearly filtered based on author. The tag field is simply left empty to get all posts before the current moment.
The original project author mentioned possibly moving away from jq, so I used grep as an example of how to extract json values. The actual pending payout values are of the form "000.000 SBD" so the value needed to be cut on the space to discard the SBD but otherwise extracting the value is pretty clear. Then The list of payout values it added together using the original author's math function. The values are built up with a sed expression. Finally, the value is returned in SBD.
Back in the balances.sh script, the value is also displayed in whatever currency the user passes in. This is accomplished by propagating the CURRENCY value through the CURRENCY global to the get_prices function so that the SBD value can just be multiplied by that result.
Added some functions to fetch just SP, STEEM, and SBD f381a3df70661a2c6d6ca8424718d644fae1c689. Originally these were in a new example script, but I made this script obsolete when I moved balances_ticker.sh to just balances.sh and added all of the new options f12da076103377308e38b953983f55443ccb3d30. It was too slow to fetch the various fields one at a time, so the method fetches the account information and then calculates the rest. At the same time, I added a CURRENCY option to balances.sh so that it could be used in calculating other dollar values of account assets.
The ability to choose which elements are displayed is new. Calculating pending payouts is new. Displaying in other currencies was supported by aspects of the architecture, but it wasn't being passed through nor being used in calculating values, so while the functions for fetching currency values already existed, making use of them and doing the extra calculations is new.
The output of the new balances.sh is much clearer than the previous ticker.
ticker screenshot
I don't know how to make animated gifs, but I updated the README to include text examples of the new output and features.
Updated content for the readme:
There are some example scripts, they all take a minimum, one or more account names.
worth.sh - original one-shot example for fetching account value
balances.sh - an uber example ticker or one-shot script
The worth.sh script is a very basic example that only supports a user name.
Example:
$ worth.sh not-a-bird
1577.120
The balances.sh supports more options and multiple user names.
Usage:
balances.sh [-b] [-c CURRENCY] [-e RPC_ENDPOINT] [-s] [-t] [-w] [-p] [-h] <USER> [USER ...]"
Get and display balance information about the specified user.
- b show balances (sbd, steem, savings) [default when no options specified]
- c CURRENCY (default is USD)
- e specify service node endpoint
- h show help
- p include pending payouts in output
- s include SP in output
- t enable stock ticker output
- w include total account worth in output
Examples:
$ balances.sh -b not-a-bird
not-a-bird 1.899 STEEM 2.027 SBD 1.000 Savings
$ balances.sh -w not-a-bird
not-a-bird worth: 1,157.77 USD
$ balances.sh -c LTC -w not-a-bird
not-a-bird worth: 6.00 LTC
$ balances.sh -p not-a-bird
not-a-bird pending payout: 248.86 SBD (USD: 1072.587)
$ balances.sh -p -c BTC not-a-bird ned
not-a-bird pending payout: 248.87 SBD (BTC: 0.095)
ned pending payout: 0.00 SBD (BTC: 0.000)
$ balances.sh -bpw -c BTC not-a-bird ned
not-a-bird worth: 0.10 BTC 1.899 STEEM 2.027 SBD 1.000 Savings pending payout: 248.88 SBD (BTC: 0.094)
ned worth: 1,452.40 BTC 141871.305 STEEM 5743.288 SBD 0.000 Savings pending payout: 0.00 SBD (BTC: 0.000)
My Fork here and original project here.