summaryrefslogtreecommitdiff
path: root/cfetch/plugins/bter.py
diff options
context:
space:
mode:
Diffstat (limited to 'cfetch/plugins/bter.py')
-rw-r--r--cfetch/plugins/bter.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/cfetch/plugins/bter.py b/cfetch/plugins/bter.py
index e18c9f1..2346591 100644
--- a/cfetch/plugins/bter.py
+++ b/cfetch/plugins/bter.py
@@ -1,6 +1,6 @@
##
## coinfetch-api-bter - BTer API plugin for coinfetch
-## Copyright (C) 2015 Delwink, LLC
+## Copyright (C) 2015-2016 Delwink, LLC
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU Affero General Public License as published by
@@ -15,11 +15,25 @@
## 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
+from requests import get
class BterTicker(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)
+
+ if kind not in res:
+ if res['result'] == 'false':
+ raise NoSuchPairException('{}/{}'.format(a, b))
+
+ raise NoSuchKindException(kind)
+
+ return (float(res[kind]) ** power) * amt
+
register_ticker('bter', 'The BTer ticker (built-in)',
BterTicker('http://data.bter.com/api/1/ticker/'))