def get_Last_Ether_Price_Supply(): from etherscan.stats import Stats with open("Illicit_Accounts/api_key.json", mode='r') as key_file: key = json.loads(key_file.read())['key'] api = Stats(api_key=key) ether_last_price_json = api.get_ether_last_price() ether_btc = ether_last_price_json['ethbtc'] ether_datetime = convertTimestampToDateTime( ether_last_price_json['ethbtc_timestamp']) ether_usd_price = ether_last_price_json['ethusd'] #ether_usd_price_datetime = convertTimestampToDateTime(ether_last_price_json['ethusd_timestamp']) total_ether_supply = api.get_total_ether_supply() print("Time of price: ", ether_datetime, " Ether_BTC price: ", ether_btc, " Ether_USD price: ", ether_usd_price) print("Total Ether supply available: ", total_ether_supply)
class Calculator(): """Handles calculations regarding given account.""" def __init__(self, address, api_key=''): self.account = Account(address, api_key=api_key) self.stats = Stats(api_key=api_key) self.address = address self.ethexplorer = ApiMethods() def calculate_total_eth_fees(self) -> tuple: """Calculates the total amount of fees paid in Eth""" tx_df = pd.DataFrame(self.account.get_transaction_page()) '''Calculate the total amount of fees paid by summing over all transactions. Fee (ETH) paid for a transation = gasPrice * gasUsed * 1e-18 returns (fee(ETH) , fee(USD)) ''' fee_in_eth = ((pd.to_numeric(tx_df['gasPrice']) * pd.to_numeric(tx_df['gasUsed'])) * (1e-18)).sum() fee_in_usd = fee_in_eth * float( self.stats.get_ether_last_price()['ethusd']) return (fee_in_eth, fee_in_usd) def calculate_portfolio_value(self) -> dict: """Returns a dictionary of all tokens and their value.""" tokens = {} address_info = self.ethexplorer.get_address_info(self.address) tokens['ETH'] = [ address_info['ETH']['balance'], float(self.stats.get_ether_last_price()['ethusd']) ] for tkn in address_info['tokens']: if 'name' in tkn['tokenInfo']: token_name = tkn['tokenInfo']['name'] token_amount = float(tkn['balance']) / pow( 10, float(tkn['tokenInfo']['decimals'])) token_value = float(tkn['tokenInfo']['price']['rate']) tokens[token_name] = [token_amount, token_value] print(tokens)
class Calculator(): '''Handles calculations regarding given account.''' def __init__(self, address, api_key = ''): self.account = Account(address, api_key = api_key) self.stats = Stats(api_key = api_key) self.api_methods = ApiMethods() def calculate_total_eth_fees(self) -> tuple: '''Calculates the total amount of fees paid in Eth''' tx_df = pd.DataFrame(self.account.get_transaction_page()) '''Calculate the total amount of fees paid by summing over all transactions. Fee (ETH) paid for a transation = gasPrice * gasUsed * 1e-18 returns (fee(ETH) , fee(USD)) ''' fee_in_eth = ((pd.to_numeric(tx_df['gasPrice']) * pd.to_numeric(tx_df['gasUsed'])) * (1e-18)).sum() fee_in_usd = fee_in_eth * float(self.stats.get_ether_last_price()['ethusd']) return (fee_in_eth, fee_in_usd)
from etherscan.stats import Stats import json with open('./key.json', mode='r') as key_file: key = json.loads(key_file.read())['key'] api = Stats(api_key=key) # get ether last price last_price = api.get_ether_last_price() print(last_price) # get total ether supply # call with default address, The DAO supply = api.get_total_ether_supply() print(supply)
from etherscan.stats import Stats import json with open('../../api_key.json', mode='r') as key_file: key = json.loads(key_file.read())['key'] api = Stats(api_key=key) last_price = api.get_ether_last_price() print(last_price)
block = api.get_block_by_number(number) tx_count = api.get_block_transaction_count_by_number(block_number=block_numb) code = api.get_code(address) block0 = api.get_most_recent_block() value = api.get_storage_at(address, 0x0) transaction = api.get_transaction_by_blocknumber_index(block_number=block_numb, index=index) transaction = api.get_transaction_by_hash(tx_hash=TX_HASH) count = api.get_transaction_count(address) receipt = api.get_transaction_receipt(TX_HASH) uncles = api.get_uncle_by_blocknumber_index(block_number=block_numb, index=index) # Stats api = Stats(api_key=key) last_price = api.get_ether_last_price() supply = api.get_total_ether_supply() # Tokens address = '0xe04f27eb70e025b78871a2ad7eabe85e61212761' contract_address = '0x57d90b64a1a57749b0f932f1a3395792e12e7055' api = Tokens(contract_address=contract_address, api_key=key) balance = api.get_token_balance(address=address) supply = api.get_total_supply() # Transactions
def getrate(): api1 = Stats(api_key=key) last_price = api1.get_ether_last_price() return last_price['ethusd']
def __init__(self, address, api_key=''): self.account = Account(address, api_key=api_key) self.stats = Stats(api_key=api_key) self.address = address self.ethexplorer = ApiMethods()
from etherscan.stats import Stats import json with open('../../api_key.json', mode='r') as key_file: key = json.loads(key_file.read())['key'] # call with default address, The DAO api = Stats(api_key=key) supply = api.get_total_ether_supply() print(supply)
def __init__(self, address, api_key = ''): self.account = Account(address, api_key = api_key) self.stats = Stats(api_key = api_key) self.api_methods = ApiMethods()
from etherscan.stats import Stats from EtherscanAPI import EtherscanAPI import os import json DATA_DIR = './StatsData' api = EtherscanAPI() API_KEY = api.key api._create_data_folder(DATA_DIR) def save_json(data, filename, save): if save: filepath = os.path.join(DATA_DIR, filename) with open(filepath, 'w') as json_file: json.dump(data, json_file, indent=4) if __name__ == '__main__': # test_address = '0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359' api = Stats(api_key=API_KEY) last_price = api.get_ether_last_price() filename = f'last_price.json' save_json(last_price, filename, save=True) print(last_price) supply = api.get_total_ether_supply() print(supply)
def price(): api = Stats(api_key=etherscan_key) last_price = api.get_ether_last_price() return float(last_price['ethusd'])