From 0db75f3e7e8d26f670dc8ffb2ef7fbe76faee359 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Mon, 10 May 2021 20:55:50 -0700 Subject: [PATCH] add price cmd --- tipbot/commands/__init__.py | 7 ++++++- tipbot/commands/network.py | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/tipbot/commands/__init__.py b/tipbot/commands/__init__.py index 8a930e7..d6d3056 100644 --- a/tipbot/commands/__init__.py +++ b/tipbot/commands/__init__.py @@ -5,7 +5,7 @@ from tipbot.commands.tip import tip from tipbot.commands.withdraw import withdraw from tipbot.commands.balance import balance from tipbot.commands.deposit import deposit -from tipbot.commands.network import mine, mempool, network +from tipbot.commands.network import mine, mempool, network, price all_commands = { @@ -58,4 +58,9 @@ all_commands = { 'example': '/network', 'help': 'Show details about the Wownero network' }, + 'price': { + 'func': price, + 'example': '/price', + 'help': 'Show Wownero price and market data from CoinGecko' + }, } diff --git a/tipbot/commands/network.py b/tipbot/commands/network.py index 19ee605..e956c47 100644 --- a/tipbot/commands/network.py +++ b/tipbot/commands/network.py @@ -69,3 +69,30 @@ def network(update, context): )) except: update.message.reply_text('Something borked -_-') + +@log_event +@check_debug +def price(update, context): + try: + data = { + 'localization': False, + 'tickers': False, + 'market_data': True, + 'community_data': False, + 'developer_data': False, + 'sparkline': False + } + headers = {'accept': 'application/json'} + url = 'https://api.coingecko.com/api/v3/coins/wownero' + r = requests.get(url, headers=headers, data=data, timeout=5) + r.raise_for_status() + j = r.json() + mcap = j['market_cap_rank'] + sats = j['market_data']['current_price']['btc'] + mname = j['tickers'][0]['market']['name'] + volbtc = j['tickers'][0]['converted_volume']['btc'] + tgt = j['tickers'][0]['target'] + bse = j['tickers'][0]['base'] + update.message.reply_text(f'{tgt}-{bse} is {sats:.8f} {tgt} on {mname} with {volbtc:.2f} {tgt} volume. Currently market cap rank #{mcap}.') + except: + update.message.reply_text('Something borked -_-')