Hello,
This is the 8. post of "steem-python for dummies" series. If you didn't read the older ones take your time and have a look.
- steem-python for dummies #1 - Introduction and Basic Operations
- steem-python for dummies #2 - Playing with account data
- steem-python for dummies #3 - Coding an upvote bot
- steem-python for dummies #4 - Private Memos
- steem-python for dummies #5 - Bundling Blockchain Operations
- steem-python for dummies #6 - Delegating
- steem-python for dummies #7 - Creating Accounts
In this post, we will learn about the "rewards". How they're calculated and shared between authors, beneficiaries (co-authors) and curators.
Post Rewards
A post's payout is calculated by the votes given. Each vote on a post has something called rshares which does actually means "Reward Shares".
This stands for determining how much percentage of steem blockchain reward fund is will be paid to the author and curators at the end of the payout period. (7 days)
To convert rshares to payout values, we have that formula.
Fund Per RewardShare = Reward Fund / Recent Claims
Payout = Reward Shares * Fund Per RewardShare / BasePrice
When you multiply Fund Per RewardShare with the vote's rshares property, you know that how much this vote will increments post's payout.
Reward Fund
Steem-Python has a call that gives information about the reward fund and recent claims.
from steem.post import Post
s = Steem()
reward_fund = s.get_reward_fund()
print(reward_fund)
This currently returns with that information.
{
'id': 0,
'name': 'post',
'reward_balance': '721431.557 STEEM',
'recent_claims': '328380833602342900',
'last_update': '2017-12-10T18:31:00',
'content_constant': '2000000000000',
'percent_curation_rewards': 2500,
'percent_content_rewards': 10000,
'author_reward_curve': 'linear',
'curation_reward_curve': 'square_root'
}
There is still one value is missing in the formula. That is base price. And of course, there is a method for that in steem-python.
s.get_current_median_history_price()["base"]
Let's implement this formula and get one of my post's expected payout.
s = Steem()
reward_fund = s.get_reward_fund()
reward_balance, recent_claims = reward_fund["reward_balance"], \
reward_fund["recent_claims"]
base_price = s.get_current_median_history_price()["base"]
def get_payout_from_rshares(rshares):
fund_per_share = Amount(reward_balance).amount / float(recent_claims)
payout = float(rshares) * fund_per_share * Amount(base_price).amount
return payout
p = Post("@emrebeyler/steem-blockchain-i-anlamak-1")
total_payout = 0
for vote in p["active_votes"]:
total_payout += get_payout_from_rshares(vote["rshares"])
print("Estimated payout for this post: $%.2f" % total_payout)
Output is:
Estimated payout for this post: $21.33
Let's double check with the steemit.
Voila!
Splitting Author, Curator rewards
However, that value is a total and includes total payout for a post. Let's find out how I share the post rewards with the curators.
In order to calculate curation rewards, I need to know when the post is created and when the curated voted for the post.
Let's implement a simple function based on these information which returns the percent of the rshares will be included in the curation rewards.
def curation_reward_pct(post_created_at, vote_created_at):
reward = ((vote_created_at - post_created_at).seconds / 1800) * 100
if reward > 100:
reward = 100
return reward
Let's put together everything and create a working function which calculating estimations on post rewards.
def get_payout_from_rshares(rshares):
fund_per_share = Amount(reward_balance).amount / float(recent_claims)
payout = float(rshares) * fund_per_share * Amount(base_price).amount
return payout
def curation_reward_pct(post_created_at, vote_created_at):
reward = ((vote_created_at - post_created_at).seconds / 1800) * 100
if reward > 100:
reward = 100
return reward
def get_payouts(p):
total_payout = 0
curation_payout = 0
for vote in p["active_votes"]:
total_payout += get_payout_from_rshares(vote["rshares"])
curation_reward_percent = curation_reward_pct(
p["created"], parse(vote["time"]))
curation_payout += get_payout_from_rshares(
float(vote["rshares"]) * curation_reward_percent / 400)
author_payout = total_payout - curation_payout
if p.get("beneficiaries"):
beneficiaries_payout = sum(
b["weight"] for b in p["beneficiaries"]) / 100
author_payout = author_payout * (
100 - beneficiaries_payout) / 100
total = round(total_payout, 2)
curation = round(curation_payout, 2)
author = round(author_payout, 2)
beneficiaries = round((total - curation - author), 2)
return total, curation, author, beneficiaries
payouts = get_payouts(
Post("@emrebeyler/steem-python-for-dummies-6-delegating"))
print("Total payout: $%s" % payouts[0])
print("Curator payout: $%s" % payouts[1])
print("Author payout: $%s" % payouts[2])
print("Beneficiaries payout: $%s" % payouts[3])
Which gives the output of:
That's all for this post. Feel free to ask questions or request topics about steem-python for the incoming posts.
Posted on Utopian.io - Rewarding Open Source Contributors
Hey @emrebeyler I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
okay this is real helpful.. thanks my guy
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Very helpful..Thanks for the share.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
WoW :0 Its gread!!! Thanks!!! :D
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
👍
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hi
I'm porting "Post Reward" algorithm to android. I'm using SteemJ.
My problem is that the results were 1 000 000 times bigger than showing by Steemit page.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thanks for the informative post @emrebeyler, but can you help me how to find payout for older posts. Using this technique reward can be calculated for newer posts(within 1 week) with good accuracy but for older posts(say 6 months ago) reward calculated is quite different from original payout reward.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Look at that birthday pos. !BEER
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
View or trade
BEER
.Hey @emrebeyler, here is a little bit of
BEER
from @isnochys for you. Enjoy it!Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit