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

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

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center