Hi. I tried to implement Bitstamp support, but do not quite know how to do it, and the getTicket()
API do not seem to match the available API from Bitstamp very well. When I run the example code from the README, I get this output.
% python x.py
At MtGox I can get 1.34 BTC for my 10.00 USD (that's 13.40 USD/BTC)
{u'volume': u'2665.99756783', u'last': u'13.00', u'bid': u'13.00', u'high': u'13.25', u'low': u'12.98', u'ask': u'13.13'}
MEXBTCAPI: You are using a number (13.25) that is not suitable to convert to Decimal!
MEXBTCAPI: You are using a number (12.98) that is not suitable to convert to Decimal!
MEXBTCAPI: You are using a number (13.00) that is not suitable to convert to Decimal!
MEXBTCAPI: You are using a number (13.13) that is not suitable to convert to Decimal!
MEXBTCAPI: You are using a number (13.00) that is not suitable to convert to Decimal!
At Bitstamp I can get 1.31 BTC for my 10.00 USD (that's 13.13 USD/BTC)
%
Here is the patch so far:
diff --git a/mexbtcapi/init.py b/mexbtcapi/init.py
index f308d06..4ffe5ed 100644
--- a/mexbtcapi/init.py
+++ b/mexbtcapi/init.py
@@ -1,5 +1,6 @@
from logger import log
from api import mtgox
+from api import bitstamp
-apis = [mtgox]
+apis = [mtgox, bitstamp]
--- /dev/null 2012-12-21 05:01:59.399416992 +0100
+++ mexbtcapi/api/bitstamp/init.py 2012-12-27 21:48:35.000000000 +0100
@@ -0,0 +1,29 @@
+# -- coding: utf-8 --
+
+# Copyright © 2012 Petter Reinholdtsen [email protected]
+#
+# Permission is hereby granted, free of charge, to any person
+# obtaining a copy of this software and associated documentation
+# files (the "Software"), to deal in the Software without
+# restriction, including without limitation the rights to use,
+# copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following
+# conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+# OTHER DEALINGS IN THE SOFTWARE.
+
+from mexbtcapi.api.bitstamp.rest.high_level import MARKET_NAME, Market
+
+name = MARKET_NAME
+market = Market
--- /dev/null 2012-12-21 05:01:59.399416992 +0100
+++ mexbtcapi/api/bitstamp/rest/high_level.py 2012-12-27 21:48:45.000000000 +0100
@@ -0,0 +1,82 @@
+# -- coding: utf-8 --
+
+# Copyright © 2012 Petter Reinholdtsen [email protected]
+#
+# Permission is hereby granted, free of charge, to any person
+# obtaining a copy of this software and associated documentation
+# files (the "Software"), to deal in the Software without
+# restriction, including without limitation the rights to use,
+# copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following
+# conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+# OTHER DEALINGS IN THE SOFTWARE.
+
+from decimal import Decimal
+import functools
+import datetime
+
+import mexbtcapi
+from mexbtcapi import concepts
+from mexbtcapi.concepts.currencies import BTC, USD
+from mexbtcapi.concepts.market import Market as BaseMarket
+
+import urllib
+import urllib2
+import json
+
+MARKET_NAME= "Bitstamp"
+_URL = "https://www.bitstamp.net/api/"
+
+class BitStampTicker( concepts.market.Ticker):
+class Market(BaseMarket):
- def init( self, currency ):
-
mexbtcapi.concepts.market.Market.**init**(self, MARKET_NAME, BTC, currency)
- def json_request(self, url, data=None):
-
-
data = urllib.urlencode(data)
-
req = urllib2.Request(url, data)
-
-
req = urllib2.Request(url)
-
-
-
-
- def getTicker(self):
-
-
-
raise BitstampError("Unknown currency: " + currency)
+#GET https://www.bitstamp.net/api/ticker/
+# Returns JSON dictionary:
+#last - last BTC price
+#high - last 24 hours price high
+#low - last 24 hours price low
+#volume - last 24 hours volume
+#bid - highest buy order
+#ask - lowest sell order
-
-
data = self.json_request(url)
-
data['avg'] = 0 # FIXME - not available from API
-
-
for name in ('high', 'low', 'avg', 'last', 'ask', 'bid'):
-
data2[name] = concepts.currency.ExchangeRate(BTC, USD, data[name])
-
time= datetime.datetime.now()
-
return BitStampTicker( market=self, time=time, high=data2['high'],
-
low=data2['low'], average=data2['avg'],
-
last=data2['last'], sell=data2['ask'],
-