add price cmd

This commit is contained in:
lza_menace 2021-05-10 20:55:50 -07:00
parent 246711b1f6
commit 0db75f3e7e
2 changed files with 33 additions and 1 deletions

View File

@ -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'
},
}

View File

@ -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 -_-')