Esempio n. 1
0
 def getDefactoRate(self):
     if self['msats'] == 0:
         return None
     if not self['asset_stable']:
         return Rate('BTC', 'BTC', 1.0)
     b = self['msats'] / MSATS_PER_BTC
     r = self['asset_units'] / b
     rate = Rate('BTC', self['code'], r)
     return rate
Esempio n. 2
0
 def fetch_btcgbp_callback(self, btcgbp):
     if btcgbp:
         print("BTCGBP: %0.2f" % float(btcgbp))
         r = Rate("BTC", "GBP", btcgbp)
         self.rate_db.add_rate(r)
         self.app.rate_change_cb(r, "GBP")
         reactor.callLater(FETCH_DELAY, self.start_btcgbp)
Esempio n. 3
0
 def fetch_btceur_callback(self, btceur):
     if btceur:
         print("BTCEUR: %0.2f" % float(btceur))
         r = Rate("BTC", "EUR", btceur)
         self.rate_db.add_rate(r)
         self.app.rate_change_cb(r, "EUR")
         reactor.callLater(FETCH_DELAY, self.start_btceur)
Esempio n. 4
0
 def fetch_btcusd_callback(self, btcusd):
     if btcusd:
         print("BTCUSD: %0.2f" % float(btcusd))
         r = Rate("BTC", "USD", btcusd)
         self.rate_db.add_rate(r)
         self.app.rate_change_cb(r, "USD")
         reactor.callLater(FETCH_DELAY, self.start_btcusd)
Esempio n. 5
0
    def createpegged(self, parsed):
        print("symbol: %s" % parsed.symbol)
        print("code: %s" % parsed.code)
        print("peg_amount: %s" % parsed.peg_amount)
        print("pegged_to_code: %s" % parsed.pegged_to_code)
        symbol = parsed.symbol
        code = parsed.code
        peg_amount = float(parsed.peg_amount)
        pegged_to_code = parsed.pegged_to_code
        if not self.rate_db.has_rate("BTC", pegged_to_code):
            return "*** do not have BTC rate for %s" % pegged_to_code

        if self.rate_db.has_pegged(code):
            return "*** already tracking code %s" % code

        peg_rate = Rate(code, pegged_to_code, float(peg_amount))
        print("peg_rate: %s" % peg_rate)
        self.rate_db.add_symbol(code, symbol)
        self.rate_db.add_pegged(peg_rate)
        return None
Esempio n. 6
0
 def recalc_pegged(self):
     for rate in self.get_pegged():
         bridge_rate = self.get_rate('BTC', rate['quote_code'])
         rates = [rate, bridge_rate]
         derived_rate = Rate.derive(rate['base_code'], 'BTC', rates)
         self.add_rate(derived_rate)
Esempio n. 7
0
 def get_pegged(self):
     return [Rate.from_dict(r) for r in self.db['pegged'].values()]
Esempio n. 8
0
 def get_rate(self, base_code, quote_code):
     k = self.key_str(base_code, quote_code)
     return Rate.from_dict(self.db['rates'][k])
Esempio n. 9
0
 def get_rates(self):
     return [Rate.from_dict(r) for r in self.db['rates'].values()]
Esempio n. 10
0
        return Wad(msats, True, cad, "CAD")

    @staticmethod
    def custom(units, rate, code, countries, decimals, name, symbol):
        btc, btc_code = rate.convert(units, code)
        assert btc_code == "BTC"
        msats = btc * MSATS_PER_BTC
        return Wad(msats, True, units, code,
                   countries=countries, decimals=decimals, name=name,
                   symbol=symbol)


if __name__ == "__main__":
    EGGPLANT = "🍆"

    rate_ltcbtc = Rate("LTC", "BTC", 0.00420700)

    rate_btcusd = Rate("BTC", "USD", 10723.12)
    print("rate_btcusd: %s" % rate_btcusd)
    rate_usdbtc = rate_btcusd.invert()
    print("rate_usdbtc: %s" % rate_usdbtc)

    rate_btccad = Rate("BTC", "CAD", 14011.28)
    print("rate_btccad: %s" % rate_btccad)

    rate_cadbtc = rate_btccad.invert()
    print("rate_catbtc: %s" % rate_cadbtc)

    rate_eggplantcad = Rate("EGGPLANT", "CAD", 2.49)
    print("rate_eggplantcad: %s" % rate_eggplantcad)