summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid McMackins II <contact@mcmackins.org>2015-08-30 07:35:00 -0500
committerDavid McMackins II <contact@mcmackins.org>2015-08-30 07:35:00 -0500
commit276fa880dbcb57d3df3f71801d71a6a31cb72690 (patch)
treeca395896dac237ec6e84193c80b23bf641378e53
parentd7080699d7266b6693f4388b8f1d4444b67120ba (diff)
Added Bitstamp API
-rw-r--r--cfetch/plugins/bitstamp.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/cfetch/plugins/bitstamp.py b/cfetch/plugins/bitstamp.py
new file mode 100644
index 0000000..f82b3f3
--- /dev/null
+++ b/cfetch/plugins/bitstamp.py
@@ -0,0 +1,41 @@
+##
+## coinfetch-api-bitstamp - Bitstamp API plugin for coinfetch
+## Copyright (C) 2015 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
+## the Free Software Foundation, version 3 only.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU Affero General Public License for more details.
+##
+## You should have received a copy of the GNU Affero General Public License
+## along with this program. If not, see <http://www.gnu.org/licenses/>.
+##
+
+from cfetch import register_ticker, Ticker
+from requests import get
+
+class BitstampTicker(Ticker):
+ def __init__(self, path, kind='vwap'):
+ super().__init__(path, kind)
+
+ def get_pair_data(self, response, pair):
+ return response.json()
+
+ def get_rate(self, a, b, amt=1):
+ if a == 'btc' and b == 'usd':
+ r = get(self.path)
+ res = self.get_pair_data(r, (a, b))
+ return float(res[self.kind]) * amt
+ elif a == 'usd' and b == 'btc':
+ r = get(self.path)
+ res = self.get_pair_data(r, (a, b))
+ return (float(res[self.kind]) ** -1) * amt
+ else:
+ raise ValueError('{}/{}'.format(a, b))
+
+register_ticker('bs', 'The Bitstamp ticker',
+ BitstampTicker('https://www.bitstamp.net/api/ticker/'))