def get_account_history(account_id): if not is_object(account_id): api = Database method_fun = 'lookup_account_names' params = [[account_id], 0] result, ret_orgin_data = client.request(api, method_fun, params) if not result: return False, [] account_id = ret_orgin_data['result'][0]['id'] api = History method_fun = 'get_account_history' params = [account_id, '1.11.1', 20, '1.11.999999999'] result, ret_orgin_data = client.request(api, method_fun, params) if not result: return False, [] account_history = ret_orgin_data['result'] if len(account_history) > 0: for transaction in account_history: ret_result, ret_block_header = get_block_header( transaction['block_num']) if not ret_result: transaction["timestamp"] = 0 transaction["witness"] = 0 continue transaction["timestamp"] = ret_block_header["timestamp"] transaction["witness"] = ret_block_header["witness"] return True, account_history
def get_workers(): api = Database method_fun = 'get_worker_count' params = [] result, ret_orgin_data = client.request(api, method_fun, params) if not result: return False, [] workers_count = int(ret_orgin_data['result']) if workers_count <= 0: return False, [] ret_objects = [] for i in range(workers_count): api = Database method_fun = 'get_objects' params = [['1.14.{}'.format(i)]] result, ret_object = client.request(api, method_fun, params) if not result: continue if not ret_object['result'][0]: continue ret_objects.append(ret_object['result'][0]) # get the votes of worker 1.14.0 - refund 400k ret_result, refund400k = get_object('1.14.0') if not ret_result: return ret_result, refund400k thereshold = int(refund400k["total_votes_for"]) result = [] for worker in ret_objects: if worker: api = Database method_fun = 'get_accounts' params = [worker["worker_account"]] result, ret_orgin_data = client.request(api, method_fun, params) if not result: continue worker["worker_account_name"] = ret_orgin_data['result'][0]['name'] current_votes = int(worker["total_votes_for"]) perc = (current_votes * 100) / thereshold worker["perc"] = perc result.append([worker]) result = result[::-1] # Reverse list. return True, result
def get_asset_holders_count(asset_id): api = Asset method_fun = 'get_asset_holders_count' params = [asset_id] result, ret_orgin_data = client.request(api, method_fun, params) if not result: return False, [] return True, ret_orgin_data['result']
def lookup_accounts(start): api = Database method_fun = 'lookup_accounts' params = [start, 1000] result, accounts = client.request(api, method_fun, params) if not result: return result, [] return True, accounts
def get_account(account_id): api = 'database' method_fun = 'get_accounts' params = [[account_id]] result, ret_orgin_data = client.request(api, method_fun, params) if not result: return False, [] return True, ret_orgin_data['result']
def get_accounts(): api = Asset method_fun = 'get_asset_holders' params = ['1.3.0', 0, 100] result, ret_orgin_data = client.request(api, method_fun, params) if not result: return False, [] ret_data = ret_orgin_data['result'] return True, ret_data
def get_global_properties(): api = 'database' method_fun = 'get_global_properties' params = [] result, ret_orgin_data = client.request(api, method_fun, params) if not result: return False, [] ret_data = ret_orgin_data['result'] return True, ret_data
def get_block(block_num): api = Database method_fun = 'get_block' params = [block_num, 0] result, ret_orgin_data = client.request(api, method_fun, params) if not result: return False, [] ret_data = ret_orgin_data['result'] return True, ret_data
def ensure_asset_id(asset_id): api = Database method_fun = 'lookup_asset_symbols' params = [[asset_id], 0] ret_result, ret_orgin_data = client.request(api, method_fun, params) if not ret_result: return ret_result, [] ret_list_account = ret_orgin_data['result'][0] return True, ret_list_account['id']
def get_asset_holders(asset_id, start, limit): api = Asset method_fun = 'get_asset_holders' params = [asset_id, start, limit] result, ret_orgin_data = client.request(api, method_fun, params) if not result: return False, [] ret_data = ret_orgin_data['result'] return True, ret_data
def get_object(object_id): api = Database method_fun = 'get_objects' params = [[object_id]] result, ret_orgin_data = client.request(api, method_fun, params) if not result: return False, [] ret_data = ret_orgin_data['result'][0] return True, ret_data
def get_last_block_number(): api = Database method_fun = 'get_dynamic_global_properties' params = [''] ret_result, dynamic_global_properties = client.request( api, method_fun, params) if not ret_result: return ret_result, dynamic_global_properties return True, dynamic_global_properties['result']["head_block_number"]
def get_account_history_pager(account_id, page): ret_result, account_id = get_account_id(account_id) if not ret_result: return ret_result, account_id # need to get total ops for account api = Database method_fun = 'get_accounts' params = [[account_id]] ret_result, ret_account = client.request(api, method_fun, params) if not ret_result or ret_account == [None]: return ret_result, ret_account account = ret_account['result'][0] ret_result, statistics = get_object(account["statistics"]) if not ret_result: return ret_result, statistics total_ops = statistics["total_ops"] start = total_ops - (20 * int(page)) stop = total_ops - (40 * int(page)) if stop < 0: stop = 0 if start > 0: api = History method_fun = 'get_relative_account_history' params = [account_id, stop, 20, start] ret_result, account_history = client.request(api, method_fun, params) if not ret_result: return ret_result, account_history for transaction in account_history['result']: ret_result, block_header = get_block_header( transaction["block_num"]) if not ret_result: continue transaction["timestamp"] = block_header["timestamp"] transaction["witness"] = block_header["witness"] return True, account_history['result'] else: return False, []
def get_header(): api = 'database' method_fun = 'get_dynamic_global_properties' params = [] result, ret = client.request(api, method_fun, params) if not result: return False, {} ret_requst = ret['result'] method_fun = 'get_witness_count' result, ret_witness_count = client.request(api, method_fun, params) if not result: return False, [] ret_requst['witness_count'] = ret_witness_count['result'] method_fun = 'get_committee_count' result, ret_committee_count = client.request(api, method_fun, params) if not result: return False, [] ret_requst['commitee_count'] = ret_committee_count['result'] method_fun = 'get_objects' params = [['2.3.0']] result, ret_get_object = client.request(api, method_fun, params) if not result: return False, [] current_supply = ret_get_object['result'][0]["current_supply"] confidental_supply = ret_get_object['result'][0]["confidential_supply"] market_cap = int(current_supply) + int(confidental_supply) ret_requst["bts_market_cap"] = int(market_cap / 100000000) # method_fun = 'get_24_volume' # params = [] # result, ret_24_volume = client.request(api, method_fun, params) # if not result: # return False, [] ret_requst[ "quote_volume"] = 0 # ret_24_volume['result'][0]["quote_volume"] ret_data = sorted(ret_requst.items(), key=lambda d: d[0]) return True, ret_data
def get_account_id(account_name): if not is_object(account_name): api = 'database' method_fun = 'lookup_account_names' params = [[account_name], 0] result, ret_orgin_data = client.request(api, method_fun, params) if not result: return False, [] return True, ret_orgin_data['result'][0]['id'] else: return True, account_name
def get_operation(operation_id): api = 'database' method_fun = 'get_objects' params = [[operation_id]] result, ret_orgin_data = client.request(api, method_fun, params) if not result: return False, [] ret_object = ret_orgin_data['result'][0] if not ret_object: return True, {} method_fun = 'get_dynamic_global_properties' params = [] result, ret_orgin_data = client.request(api, method_fun, params) if not result: return False, [] ret_data = ret_orgin_data['result'] ret_object["accounts_registered_this_interval"] = ret_data[ 'accounts_registered_this_interval'] api = 'database' method_fun = 'get_objects' params = [['2.3.0']] result, ret_orgin_data = client.request(api, method_fun, params) if not result: return False, [] current_supply = ret_orgin_data['result'][0]["current_supply"] confidental_supply = ret_orgin_data['result'][0]["confidential_supply"] market_cap = int(current_supply) + int(confidental_supply) ret_object["bts_market_cap"] = int(market_cap / 100000000) ret_result, global_properties = get_global_properties() if not ret_result: ret_object["commitee_count"] = 0 ret_object["witness_count"] = 0 return ret_result, ret_object ret_object["commitee_count"] = len( global_properties["active_committee_members"]) ret_object["witness_count"] = len(global_properties["active_witnesses"]) return True, ret_object
def get_block_asset(asset_id): api = Database method_fun = 'lookup_asset_symbols' params = [[asset_id], 0] if not is_object(asset_id): result, ret_orgin_data = client.request(api, method_fun, params) if not result: return False, [] else: method_fun = 'get_assets' result, ret_orgin_data = client.request(api, method_fun, params) if not result: return False, [] ret_list_account = ret_orgin_data['result'][0] api = 'database' method_fun = 'get_objects' params = [[ret_list_account["dynamic_asset_data_id"]]] result, dynamic_asset_data = client.request(api, method_fun, params) if not result: return False, [] ret_list_account["current_supply"] = dynamic_asset_data['result'][0][ "current_supply"] ret_list_account["confidential_supply"] = dynamic_asset_data['result'][0][ "confidential_supply"] ret_list_account["accumulated_fees"] = dynamic_asset_data['result'][0][ "accumulated_fees"] ret_list_account["fee_pool"] = dynamic_asset_data['result'][0]["fee_pool"] api = 'database' method_fun = 'get_objects' params = [[ret_list_account["issuer"]]] result, issuer = client.request(api, method_fun, params) if not result: return False, [] ret_list_account["issuer_name"] = issuer['result'][0]["name"] ret_data = ret_list_account return True, ret_data
def get_market_chart_data(base, quote): api = Database method_fun = 'lookup_asset_symbols' params = [[base], 0] ret_result, ret_base_data = client.request(api, method_fun, params) if not ret_result: return ret_result, [] base_id = ret_base_data['result'][0]["id"] base_precision = 10**float(ret_base_data[0]["precision"]) params = [[quote], 0] ret_result, ret_quote_data = client.request(api, method_fun, params) if not ret_result or ret_quote_data == [None]: return ret_result, [] quote_id = ret_quote_data['result'][0]["id"] quote_precision = 10**float(ret_quote_data['result'][0]["precision"]) api = History method_fun = 'get_market_history' now = datetime.date.today() ago = now - datetime.timedelta(days=100) params = [ base_id, quote_id, 86400, ago.strftime("%Y-%m-%dT%H:%M:%S"), now.strftime("%Y-%m-%dT%H:%M:%S") ] ret_result, market_history = client(api, method_fun, params) if not ret_result: return ret_result, [] data = [] for market_operation in market_history['result']: open_quote = float(market_operation["open_quote"]) high_quote = float(market_operation["high_quote"]) low_quote = float(market_operation["low_quote"]) close_quote = float(market_operation["close_quote"]) open_base = float(market_operation["open_base"]) high_base = float(market_operation["high_base"]) low_base = float(market_operation["low_base"]) close_base = float(market_operation["close_base"]) open = 1 / (float(open_base / base_precision) / float(open_quote / quote_precision)) high = 1 / (float(high_base / base_precision) / float(high_quote / quote_precision)) low = 1 / (float(low_base / base_precision) / float(low_quote / quote_precision)) close = 1 / (float(close_base / base_precision) / float(close_quote / quote_precision)) ohlc = [open, close, low, high] data.append(ohlc) append = [0, 0, 0, 0] if len(data) < 99: complete = 99 - len(data) for c in range(0, complete): data.insert(0, append) return True, data