Beispiel #1
0
    def balance_as(self, currency):
        """Returns your balance as a formatted string in a particular currency.

        :param currency: One of the :ref:`supported currencies`.
        :type currency: ``str``
        :rtype: ``str``
        """
        return satoshi_to_currency_cached(self.balance, currency)
Beispiel #2
0
 def get_action_balance(self):
     if not self.check_input_arguments(["address"]):
         return self._response(error_msg.PARAMS_ERROR)
     satoshi = NetworkAPI.get_balance(self._input["address"])
     if satoshi != 0:
         cny = satoshi_to_currency_cached(satoshi, "cny")
     else:
         cny = 0
     data = dict(satoshi=str(satoshi), cny=float(cny))
     return self._response(data=data)
Beispiel #3
0
 def get_action_balance(self):
     if not self.check_input_arguments(["address"]):
         return self._response(error_msg.PARAMS_ERROR)
     #url = ("{}/q/addressbalance/{}?confirmations=6".format(
     #    self.URL,
     #    self._input["address"]))
     url = ("{}/unspent?active={}&confirmations=6".format(
         self.URL, self._input["address"]))
     try:
         r = requests.get(url).json().get("unspent_outputs", [])
         satoshi = 0
         for i in r:
             satoshi += i.get("value", 0)
     except Exception as e:
         logger.error("requests address error{}".format(e))
         data = dict(satoshi=0, cny=0, balance=0)
         return self._response(data=data)
     if satoshi != 0:
         cny = satoshi_to_currency_cached(satoshi, "cny")
     else:
         cny = 0
     data = dict(satoshi=str(satoshi), cny=float(cny), balance=str(satoshi))
     return self._response(data=data)
Beispiel #4
0
def get_balance_in_usd(address):
    if address == my_address.address:
        return my_address.get_balance('usd')
    else:
        res = requests.get('https://api.blockcypher.com/v1/btc/test3/addrs/'+address+'/balance')
        return satoshi_to_currency_cached(res.json()['balance'], 'usd')
Beispiel #5
0
def btc_to_fiat(amount, currency):
    amount = amount * (10**8)
    conversion = satoshi_to_currency_cached(amount, currency)
    return conversion
Beispiel #6
0
def btc_balance(address, private):
    if private:
        s_k = Key.from_hex(address)
        address = s_k.address
    btc_balance = NetworkAPI.get_balance(address)
    return satoshi_to_currency_cached(btc_balance, "btc")