Tutorial: Get the value of your steemit earnings, Part #2 - Calculate Steem Power

in #steemdev7 years ago

In the second post of this series I added the conversation of the VESTS rewards to Steem Power.

The Mission

The requirements for the first part of this series:

  1. Get the steemit earnings (STEEM, SBD, VESTS) for an account
  2. Create a HTML and CSV report
    You can find the first part here:
    https://steemit.com/steemdev/@schererf/tutorial-get-the-value-of-your-steemit-earnings-part-1

The requirements for this second part:

  1. Calculate the Steem Power (SP) for the VESTS reward

System Requirements

nodeJS

As the runtime system for the program I used "nodeJS" (LTS version).
You can download nodeJS here: https://nodejs.org

Implementation

git repository

You can download the complete sources of this tutorial from my GitHub repository:
https://github.com/SchererF/steemit-earnings

calculation of Steem Power

The Steem Power is calculated using the following formula:

total_vesting_fund_steem * (user's vesting_shares / total_vesting_shares)



Thanks to @lantto:
https://steemit.com/steem/@lantto/how-to-calculate-steem-power-using-the-api

using steemd data

To calculate the Steem Power of VESTS reward, we need historical data for total_vesting_fund_steem and total_vesting_shares. The only way I found to get this historical data is provided by @jesta. He creates snapshots of steemd data on a regular base.

Thanks to @jesta:
https://steemit.com/witness-category/@jesta/jesta-witness-update-2016-09-02

The data are provided under this URL:
https://steemdb.com/api/props

        var url='https://steemdb.com/api/props';
        console.log( 'loading data from "' + url + '"');
        return fetch(url
            ).then((response) => response.json()
            ).then((data) => steemdApiPropsData = data);



Get the timestamp of an single item

var date = new Date(parseInt(steemdApiPropsDataItem.time.$date.$numberLong));


Calculate the steem_per_mvests value

steem_per_mvests = steemdApiPropsDataItem.total_vesting_fund_steem * 1000000 / steemdApiPropsDataItem.total_vesting_shares;

Example

time.$date.$numberLong 1515871554000 (GMT: Saturday, January 13, 2018 7:25:54 PM)
total_vesting_fund_steem 199304254.488
total_vesting_shares 408153245669.0034
steem_per_vests 0.000488307 = 199304254.488 / 408153245669.0034

small deviations

Unfortunately, there are small deviations in the comma range for the calculated Steem Power values compared to those in the wallet. Personally, I can live with this small deviations, but if you know a solution to this problem, I would appreciate a hint.

Let's do it

Please have a look at the first post of this series if you want to know how to download, install and run this program.
https://steemit.com/steemdev/@schererf/tutorial-get-the-value-of-your-steemit-earnings-part-1

Take a look at the output HTML

The created HTML now includes the values for steem_per_mvests and SP values.

Tutorial Preview

In the next parts of this little series add the STEEM and SBD earnings as EUR/USD based on the historical exchange rate of the reward claim date.

Note

This tool can simply be used for your personal interests or of course to create a template for reporting your steemit earnings for a financial office (as we need it in Germany for the tax office).

The created report is of course not an official document. It is just an idea on how to report your earnings!

Please give me feedback if this tutorial was helpful for you.

Thanks for reading and watching,
@schererf

Sort:  

Thanks @schererf, pretty useful post ! Is there any possibility to pin your post on my steemit till next year:) Is it working for OSX ?

Just use browser bookmarks ;-)
Yes it should work. You can download nodeJS for OSX here: https://nodejs.org/en/download/

Thx !

Coins mentioned in post:

CoinPrice (USD)📉 24h📈 7d
HTMLHTMLCOIN0.002$5.35%6.12%
SBDSteem Dollars5.427$-4.35%17.43%
STEEMSteem4.358$-5.19%6.99%

Good post!👍

I'm glad you like it...

Oh wow this can be done too interesting :D

Thanks for sharing a post on it how to do it :)

You're welcome. Writing technical posts is not that easy as it seems ;-)

Another awesome tutorial thanks for sharing it once again :)

Thanks for reading it again :)

i am gonna try this one out thanks bro for sharing it

Yes, please try it and give me some feedback about it!

Hi @schererf, 2017 my first year on taxing crypto income, so I'm following your tutorials closely! :)
The steem_per_mvest can also be queried from the blockchain. The fill_vesting_withdraw operations contain the numbers of [X] VESTs withdrawn into [Y] SP. However, this requires a query script, there's no ready to use API that I know of.

Thanks a lot, that sounds very interesting. Can you share an example for this query script?

Sure, I did it for another application a day ago in python for the time span from Jan 1st 2018 to yesterday:

from steemdata import SteemData
import datetime as dt

s = SteemData()
timerange = {"$gt": dt.datetime(2018, 1, 1, 0, 0, 0)}
ops = list(s.Operations.find({'type':'fill_vesting_withdraw',
                                'timestamp': timerange}))
rates = []
dates = []
for r in ops:
    deposited = float(r['deposited']['amount'])  # Steem
    withdrawn = float(r['withdrawn']['amount'])  # Vests
    rate = deposited / withdrawn * 1e6
    date = r['timestamp']
    # [few filters hidden for simplicity here]
    rates.append(rate)
    dates.append(date)

steem_per_mvest.png

The outliers are cases where withdraw vesting routes with less than 100% were used, so some of the Vests from one account went as STEEM or SP into another account. I think the upper limit of these values per day/hour/... should give a reasonably precise value.

Cool, thank you.
But if I understand it right, SteemData is a MongoDB server and therefore the data not comes directly from the blockchain.
https://steemit.com/steemdata/@furion/getting-started-with-steemdata

Yes, that's a MongoDB server. It contains the same information as on the blockchain, but it's magnitudes faster than streaming the blocks directly from the blockchain. If you want to get it directly from the blockchain, one could think about streaming a couple of full blocks around each reward claim to catch a fill_vesting_withdraw operation close by. But your steemdb API approach is in that case probably simpler...

Excellent lesson with step by step approach you explained it very simply

THX, glad you like it!

This post received a upvote from @resteemme and it's trail. Thanks to @resteemme!

Coin Marketplace

STEEM 0.19
TRX 0.16
JST 0.034
BTC 63935.74
ETH 2749.19
USDT 1.00
SBD 2.65