nxy/nxy/plugins/bitcoin.py

31 lines
958 B
Python

# -*- coding: utf-8 -*-
import irc3
import requests
from docopt import Dict as DocOptDict
from irc3.plugins.command import command
from irc3.utils import IrcString
from . import Plugin
from ..utils import fmt
# noinspection PyUnusedLocal
@irc3.plugin
class Bitcoin(Plugin):
requires = ['irc3.plugins.command']
@command
def btc(self, mask: IrcString, channel: IrcString, args: DocOptDict):
"""Gets the Bitcoin values from BitStamp
%%btc
"""
data = requests.get('https://www.bitstamp.net/api/ticker').json()
values = {k: float(data[k]) for k in ['last', 'high', 'low', 'volume']}
return fmt('{bold}[BitStamp]{reset} '
'Current: {bold}{color}{orange}${last:,.2f}{reset} - '
'High: {bold}{color}{green}${high:,.2f}{reset} - '
'Low: {bold}{color}{maroon}${low:,.2f}{reset} - '
'Volume: {bold}฿{volume:,.2f}', **values)