Esempio n. 1
0
 def _handle_response(self, response):
     try:
         json_response = json.loads(response)
     except ValueError:
         raise InvalidExchangeRateResponse(self.name, "invalid rate response : %s" % response)
     if 'data' not in json_response:
         raise InvalidExchangeRateResponse(self.name, 'result not found')
     return defer.succeed(1.0 / json_response['data']['btc_usd'])
Esempio n. 2
0
 def _handle_response(self, response):
     response = response[3:] # response starts with "// "
     json_response = json.loads(response)[0]
     if 'l' not in json_response:
         raise InvalidExchangeRateResponse(self.name, 'last trade not found')
     last_trade_price = float(json_response['l'])
     if last_trade_price <= 0:
         raise InvalidExchangeRateResponse(self.name, 'trade price was not positive')
     return defer.succeed(last_trade_price)
Esempio n. 3
0
 def _handle_response(self, response):
     try:
         json_response = json.loads(response)
     except ValueError:
         raise InvalidExchangeRateResponse(self.name, "invalid rate response")
     if 'ticker' not in json_response or len(json_response['ticker']) == 0 or \
                     'success' not in json_response or json_response['success'] is not True:
         raise InvalidExchangeRateResponse(self.name, 'result not found')
     return defer.succeed(float(json_response['ticker']['price']))
Esempio n. 4
0
 def _handle_response(self, response):
     json_response = json.loads(response)
     if 'result' not in json_response:
         raise InvalidExchangeRateResponse(self.name, 'result not found')
     trades = json_response['result']
     if len(trades) == 0:
         raise InvalidExchangeRateResponse(self.market, 'trades not found')
     totals = sum([i['Total'] for i in trades])
     qtys = sum([i['Quantity'] for i in trades])
     if totals <= 0 or qtys <= 0:
         raise InvalidExchangeRateResponse(self.market, 'quantities were not positive')
     vwap = totals/qtys
     return defer.succeed(float(1.0 / vwap))
Esempio n. 5
0
 def _handle_response(self, response):
     json_response = json.loads(response)
     if 'data' not in json_response:
         raise InvalidExchangeRateResponse(self.name, 'result not found')
     return defer.succeed(1.0 / json_response['data']['lbc_btc'])