Esempio n. 1
0
 def _handle_response(self, response):
     try:
         json_response = json.loads(response)
     except ValueError:
         raise InvalidExchangeRateResponseError(
             self.name, "invalid rate response : %s" % response)
     if 'data' not in json_response:
         raise InvalidExchangeRateResponseError(self.name,
                                                'result not found')
     return 1.0 / json_response['data']['btc_usd']
Esempio n. 2
0
 def _handle_response(self, response):
     try:
         json_response = json.loads(response)
     except ValueError:
         raise InvalidExchangeRateResponseError(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 InvalidExchangeRateResponseError(self.name,
                                                'result not found')
     return float(json_response['ticker']['price'])
Esempio n. 3
0
 def get_rate_from_response(self, json_response):
     if 'result' not in json_response:
         raise InvalidExchangeRateResponseError(self.name,
                                                'result not found')
     trades = json_response['result']
     if len(trades) == 0:
         raise InvalidExchangeRateResponseError(self.name,
                                                '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 InvalidExchangeRateResponseError(
             self.name, 'quantities were not positive')
     vwap = totals / qtys
     return float(1.0 / vwap)
Esempio n. 4
0
 def get_rate_from_response(self, json_response):
     if 'data' not in json_response or \
        'ticker' not in json_response['data'] or \
        'last' not in json_response['data']['ticker']:
         raise InvalidExchangeRateResponseError(self.name,
                                                'result not found')
     return 1.0 / float(json_response['data']['ticker']['last'])
Esempio n. 5
0
 def get_rate_from_response(self, json_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 InvalidExchangeRateResponseError(self.name,
                                                'result not found')
     return float(json_response['ticker']['price'])
Esempio n. 6
0
 def get_rate_from_response(self, json_response):
     if 'data' not in json_response:
         raise InvalidExchangeRateResponseError(self.name,
                                                'result not found')
     return 1.0 / json_response['data']['btc_usd']
Esempio n. 7
0
 def _handle_response(self, response):
     json_response = json.loads(response)
     if 'data' not in json_response:
         raise InvalidExchangeRateResponseError(self.name,
                                                'result not found')
     return 1.0 / json_response['data']['lbc_btc']
Esempio n. 8
0
 def get_rate_from_response(self, json_response):
     if len(json_response) != 1 or 'trade_price' not in json_response[0]:
         raise InvalidExchangeRateResponseError(self.name,
                                                'result not found')
     return 1.0 / float(json_response[0]['trade_price'])
Esempio n. 9
0
 def get_rate_from_response(self, json_response):
     if 'result' not in json_response:
         raise InvalidExchangeRateResponseError(self.name,
                                                'result not found')
     return 1.0 / float(json_response['result'])
Esempio n. 10
0
 def get_rate_from_response(self, json_response):
     if 'ticker' not in json_response or 'price' not in json_response[
             'ticker']:
         raise InvalidExchangeRateResponseError(self.name,
                                                'result not found')
     return float(json_response['ticker']['price'])
 def get_response(self):
     raise InvalidExchangeRateResponseError(self.name, 'bad stuff')