scotbot: get_account_history api endpoint

in #sct5 years ago

새로운 get_account_history api

다음와 같은 정보를 얻을 수 있는 계정 히스토리 api가 scotbot에 추가되었습니다:

  • curation_reward
  • author_reward
  • staking_reward
  • mining_reward
  • comment_benefactor_reward

Endpoint

GET /get_account_history

쿼리 매개변수

이름타입설명필수조건
accountstrings계정 이름필수
tokenstrings토큰 이름
typestrings보상 종류에 해당하는 결과만 보기
limitint결과 제한 (기본값 1000)
offsetint결과 건너뛰기 (기본값 0)
authorstrings설정 시, 해당 저자에 대한 결과만 보여줌

예시

최근 7일간 발생한 모든 보상에 대한 상세 보상 정보를 조회하는 파이썬 스크립트

#!/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("--------------")

원문은 https://www.steemcoinpan.com/scotbot/@holger80/scotbot-get-account-history-api-endpoint 이며 스팀 엔진 팀 동의하에 번역을 진행했고, 스팀 코인판 공식 번역가 @dakeshi가 번역을 담당했습니다.


이전 번역 글 목록