Posts

scotbot: get account history api endpoint

avatar of @holger80
25
@holger80
·
0 views
·
2 min read

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("--------------")