def _price_view(): """Template for get the current exchange rate and cryptocurrency volumes TRON""" data = requests.get(constants.URL_COINMARKET_API_TRON).json()['data'] data_usd = data['quotes']['USD'] data_btc = data['quotes']['BTC'] return views.PRICE_VIEW.format(price='{:.3f}'.format(data_usd['price']), price_btc='{:.8f}'.format( data_btc['price']), rank=data['rank'], market_cap=currency(data_usd["market_cap"]), volume_24h=currency(data_usd["volume_24h"]))
def balance(bot, update, args): """Get a balance at""" data = ' '.join(args).split(' ') try: info = currency(tron.trx.get_balance(data[0], True)) except Exception as e: info = str(e) bot.send_message(chat_id=update.message.chat_id, parse_mode=telegram.ParseMode.MARKDOWN, text=info)
def _accounts_view(): """Template for getting information about TOP 10 addresses with large balances""" data = requests.get( constants.API_TRONSCAN + '/account/list?sort=-balance&limit=10&start=0').json()['data'] text = '' for account in data: text += views.ACCOUNTS_VIEW.format( address=account['address'], balance=currency(tron.fromSun(account['balance']))) return text
def _tx_view(tx_id): """Template for obtaining transaction details Args: tx_id (str): Transaction ID """ data = requests.get(constants.API_TRONSCAN + "/transaction-info?hash=" + tx_id).json() text = "Sorry, the transaction could not be found." token = 'TRX' amount = 0 contract_type = get_contract_type(data['contractType']) if data['contractType'] == 1: amount = tron.fromSun(data['contractData']['amount']) elif data['contractType'] == 44: amount = tron.fromSun(data['contractData']['quant']) elif data['contractType'] == 4: amount = tron.fromSun(data['contractData']['votes'][0]['vote_count']) token = 'TP' elif data['contractType'] == 11: amount = tron.fromSun(data['contractData']['frozen_balance']) else: if 'amount' in data['contractData']: amount = data['contractData']['amount'] if data['contractType'] not in [4, 12, 31]: if 'token' in data['contractData']: token = data['contractData']['token'] # Статус транзакции status = "UNCONFIRMED" if data['confirmed']: status = "CONFIRMED" text = views.TX_VIEW.format( hash=str(data['hash']), status=status, block=str(data['block']), time=helpers.date_format(data['timestamp']), owner_address=data['ownerAddress'], to_address=data['toAddress'], value=currency(amount), contract_type=contract_type, token=token ) return text