diff options
Diffstat (limited to 'cfetch/plugins/ccc.py')
-rw-r--r-- | cfetch/plugins/ccc.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/cfetch/plugins/ccc.py b/cfetch/plugins/ccc.py index 07bdb99..3104c46 100644 --- a/cfetch/plugins/ccc.py +++ b/cfetch/plugins/ccc.py @@ -15,7 +15,8 @@ ## along with this program. If not, see <http://www.gnu.org/licenses/>. ## -from cfetch import register_ticker, Ticker +from cfetch import register_ticker, NoSuchKindException, NoSuchPairException +from cfetch import Ticker class CccTicker(Ticker): def __init__(self, path): @@ -24,6 +25,18 @@ class CccTicker(Ticker): def get_pair_data(self, response, pair=None): return response.json() + def get_rate_pow(self, a, b, amt, power, kind): + r = get(self.path + self.get_pair(a, b)) + res = self.get_pair_data(r, (a, b)) + + if kind not in res: + raise NoSuchKindException(kind) + + if res[kind] is None: + raise NoSuchPairException('{}/{}'.format(a, b)) + + return (float(res[kind]) ** power) * amt + def get_rate(self, a, b, amt=1, kind='price'): return super().get_rate(a, b, amt, kind) |