Python code to retrieve a user's vested share of Steem

in #utopian-io6 years ago (edited)

View this post on Hive: Python code to retrieve a user's vested share of Steem


In March 2020, many Steem users, including @dhimmel, migrated to the Hive blockchain in response to the hostile takeover of Steem. Please use the Hive link when sharing this post and comment on the Hive version to get in touch.


Have you ever been curious what share of Steem ecosystem you own? Well one way to answer that question is to calculate your share of the total VESTS. And how does one obtain VESTS? Powered up STEEM actually becomes VESTS. STEEM Power is just an illusion, it doesn't actually exist, as @yabapmatt elegantly explains.

Below is Python code, which uses the steem-js REST API, to calculate any user's share of total VESTS. Technically, this share metric just divides two blockchain values: vesting_shares / total_vesting_shares . This Python code was written in Python 3 (but should also work in 2). The only dependency is the requests package. Here's the source code (released under a CC0 public domain dedication):

import math
import requests

def get_user_vesting_shares(user):
    url = 'https://steemit.com/@{}.json'.format(user)
    response = requests.get(url)
    result = response.json()
    vests = result['user']['vesting_shares']
    vests, unit = vests.split(' ')
    return result, float(vests)

def get_total_vesting_shares():
    url = 'https://api.steemjs.com/get_dynamic_global_properties'
    response = requests.get(url)
    result = response.json()
    vests = result['total_vesting_shares']
    vests, unit = vests.split(' ')
    return result, float(vests)

def print_perecentage_share(user, significant_digits=2):
    """
    Print information on a user's ownership of Steem,
    based on their VESTS versus the total.
    """
    user_result, vests = get_user_vesting_shares(user)
    global_result, total = get_total_vesting_shares()
    proportion = vests / total
    digits = -math.floor(math.log10(proportion)) - 3 + significant_digits
    percent = '{{:.{}f}}%'.format(digits).format(100 * proportion)
    template = '@{username} owns {percent} of Steem VESTS as of {time} (block {head_block_number:,})'
    print(template.format(percent=percent, username=user, **global_result))

# Substitute your username below
print_perecentage_share('dhimmel')

With a for-loop you can print the share for multiple users:

for username in 'dhimmel', 'yabapmatt', 'greenescientist', 'knircky', 'ned', 'beeyou', 'simoxenham':
    print_perecentage_share(username)

I've copied the output to a bulleted list below:

  • @dhimmel owns 0.0036% of Steem VESTS as of 2018-03-30T16:19:06 (block 21,132,367)
  • @yabapmatt owns 0.0093% of Steem VESTS as of 2018-03-30T16:19:09 (block 21,132,368)
  • @greenescientist owns 0.000000053% of Steem VESTS as of 2018-03-30T16:19:09 (block 21,132,368)
  • @knircky owns 0.029% of Steem VESTS as of 2018-03-30T16:19:12 (block 21,132,369)
  • @ned owns 1.9% of Steem VESTS as of 2018-03-30T16:19:15 (block 21,132,370)
  • @beeyou owns 0.00017% of Steem VESTS as of 2018-03-30T16:19:18 (block 21,132,371)
  • @simoxenham owns 0.000020% of Steem VESTS as of 2018-03-30T16:19:18 (block 21,132,371)

These metrics can be useful for putting a user's ownership and investment in perspective. Certain users may want to target a level of ownership in the ecosystem and could find this metric useful.

This is my first time working with any APIs related to Steem, so please suggest any improvements. The next step is to calculate a user's percent share over time. Eventually, I'd like to analyze the share of all users over time to see how vests are distributed and whether the ecosystem is becoming more of less distributed in terms of wealth.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Your contribution cannot be approved because it is not as informative as other contributions. See the Utopian Rules. Contributions need to be informative and descriptive in order to help readers and developers understand them.

Please check other contributions in the analysis category. These are usully full blown posts about a specific area of an open source project and not just scripts to extract data.

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

Okay hopefully someday I'll get a post approved on Utopian. As someone who creates open source research as a profession, these rejections are a bit discouraging. Especially, since Utopian is still a 25% post beneficiary, so posting via Utopian and then getting rejected can be costly.

However, I appreciate the thoughtful moderation and will try at least one more time to post via Utopian. I wonder though if such strict moderation harms new user onboarding.

Hello @dhimmel, thanks for understanding. Since you know how to code, why not try creating a contribution under the development category?

Sounds good. I will make a development post next time. So to be clear, I should make the development post after a peer-reviewed pull request of mine has been merged into an open source repository? And the development post should describe the enhancement / bug fix?

Yes, that's the basic rule that we have. If it's not your project, and it's a new feature or it's a bug fix for an existing feature, then there's a high probability of it to be approved.

Again, I suggest to go through the rules of course.

To my surprise, Gina bot notified me that BeeYOU was mentioned on your post. Hey Dan, it's Mello. Thanks for calculating BeeYOU's % of Steem VESTS. It's a sad tiny number, which I hope to grow over the next few months. I would love to see who has the highest VESTS %.

Interesting post. There is something to think about. Thanks for sharing.

thanks for sharing such an informative post regarding coding of python i actually didnt about coding and phython but my brother discuss these thing with me but soon i will learn but your post must be useful for the retrieve a user!

Great,very informative post.I tell youa bit of my sense,Steemit is a social news service which runs a blogging and social networking website on top of a blockchain database.Steem has also changed the entire scenario of the same market by incentivizing community contribution to social media networks.


Exclusive 30 days free upvotes to your every new post. No need to send any kinds of steem or sbd its full free service. we have paid service too so please check them too. Active the free upvote service and learn more about it here : https://t.co/GOqKWndWZz

Coin Marketplace

STEEM 0.31
TRX 0.11
JST 0.033
BTC 64275.02
ETH 3139.81
USDT 1.00
SBD 4.14