scotbot: get account history api endpoint

in #scotbot5 years ago (edited)

New get account history api

There is a new account history api for scotbot which can be used to get information about the following types:

  • curation_reward
  • author_reward
  • staking_reward
  • mining_reward
  • comment_benefactor_reward

Endpoint

GET /get_account_history

Query Parameters

NameTypeDescriptionRequired
accountstringsaccount nameyes
tokenstringstoken name
typestringslimit result by reward type
limitintlimit results (default 1000)
offsetintskips results (default 0)
authorstringsWhen set, output is limited to this author

Some examples

The results include only rewards from the 12.08.2019.

Python script to receive detailed reward information about all rewards from the last 7 days

#!/usr/bin/python
from datetime import datetime, timedelta
from beem.utils import formatTimeString
import requests

def get_scot_token():
    url = "http://scot-api.steem-engine.com/info"
    # sending get request and saving the response as response object 
    r = requests.get(url = url) 
    
    # extracting data in json format 
    data = r.json()
    token_list = []
    for token in data:
        token_list.append(token)
    return token_list

def get_rewards_from_last_week(account_name, rewards, offset=0):
    url = "http://scot-api.steem-engine.com/get_account_history"
    start_date = datetime.utcnow() - timedelta(days=7)
    params = {"account": account_name, "offset": offset}
    # sending get request and saving the response as response object 
    r = requests.get(url = url, params = params) 
    
    # extracting data in json format 
    data = r.json()
    n = 0
    for reward in data:
        timestamp = formatTimeString(reward["timestamp"]).replace(tzinfo=None)
        if timestamp < start_date:
            continue
        rewards[reward["type"]][reward["token"]] += reward["int_amount"] / 10**reward["precision"]
        n += 1
    return rewards, n

if __name__ == "__main__":
    account = "holger80"
    scot_token_list = get_scot_token()
    reward_types = ["curation_reward", "author_reward", "staking_reward", "mining_reward", "comment_benefactor_reward"]
    rewards = {}
    for reward_type in reward_types:
        rewards[reward_type] = {}
        for token in scot_token_list:
            rewards[reward_type][token] = 0
    n = 0
    rewards, n = get_rewards_from_last_week(account, rewards)
    offset = 1000
    while n == 1000:
        rewards = get_rewards_from_last_week(account, rewards, offset=offset)
        offset += 1000
    for reward_type in reward_types:
        print("%s from the last 7 days:" % reward_type)
        for token in scot_token_list:
            if rewards[reward_type][token] > 0:
                print("%f %s" % (rewards[reward_type][token], token))
        print("--------------")
                
Sort:  

Works like a charm!
I have setup on my desktop now but I had to add a "raw_input()" to the end of the script so it would not automatically close the terminal window at the completion of the script.

Are we able to pull data for more than a 7 day period?

Yes you can get more than 7 days. I think all you have to do is edit this line (20)
"start_date = datetime.utcnow() - timedelta(days=7)". If you want e.g. 14 days you would change it to
"start_date = datetime.utcnow() - timedelta(days=14)".

When I try that it does not give me the correct outputs. When looking at the transaction history on SE explorer the script only seems to go back 9 days max. When I set it to 14 days the same output is given. Maybe a limitation of the api?

Yes I just checked and I have the same thing. Looks like a limitation of the api to me.
Edit: "The results include only rewards from the 12.08.2019."

Ahh, so I guess that is the zero day for our history through the api. I just tried and we are at 10 days available now, up one from yesterday.

Nice work @holger80. If permlink can be added as one of the query parameters, it will be awesome. I can pass account and permlink to get full details about a post in one shot.

So does this mean we can get a tribes version of Steemworld?

Posted using Partiko iOS

@steemchiller just added SE tokens to his interface. You can switch to a view of your account for a specific token.

Posted using Partiko Android

Thank you so much for participating in the Partiko Delegation Plan Round 1! We really appreciate your support! As part of the delegation benefits, we just gave you a 3.00% upvote! Together, let’s change the world!

Hi, @holger80!

You just got a 4.89% upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in here to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.

This post has been rewarded with an upvote from city trail as part of Neoxian City Curation program . We are glad to see you using #neoxian tag in your posts. If you still not in our discord, you can join our Discord Server for more goodies and giveaways.

Do you know that you can earn NEOXAG tokens as passive income by delegating to @neoxiancityvb. Here are some handy links for delegations: 100SP, 250SP, 500SP, 1000SP. Read more about the bot in this post.

This post has been included in the latest edition of The Steem News - a compilation of the key news stories on the Steem blockchain.

Hi @holger80!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your UA account score is currently 7.611 which ranks you at #49 across all Steem accounts.
Your rank has not changed in the last three days.

In our last Algorithmic Curation Round, consisting of 147 contributions, your post is ranked at #1. Congratulations!

Evaluation of your UA score:
  • Your follower network is great!
  • The readers appreciate your great work!
  • Great user engagement! You rock!

Feel free to join our @steem-ua Discord server

@holger80, Keep bringing more updates which making this Ecosystem more enhancing.

Posted using Partiko Android

FYI it doesn't actually seem to be filtering results by token:
eg http://scot-api.steem-engine.com/get_account_history?account=ausbitbank&symbol=PAL&limit=100 returns non PAL results as well

Hi, I've noticed the mistake!

It should be token and not symbol like so:

http://scot-api.steem-engine.com/get_account_history?account=ausbitbank&token=PAL&limit=100

!steem2email

Emailed 👌


Powered by witness untersatz!