How to use the beem.asset.Asset function in beem

To help you get started, we’ve selected a few beem examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github holgern / beem / tests / beem / test_market.py View on Github external
def test_market(self):
        bts = self.bts
        m1 = Market(u'STEEM', u'SBD', steem_instance=bts)
        self.assertEqual(m1.get_string(), u'SBD:STEEM')
        m2 = Market(steem_instance=bts)
        self.assertEqual(m2.get_string(), u'SBD:STEEM')
        m3 = Market(u'STEEM:SBD', steem_instance=bts)
        self.assertEqual(m3.get_string(), u'STEEM:SBD')
        self.assertTrue(m1 == m2)

        base = Asset("SBD", steem_instance=bts)
        quote = Asset("STEEM", steem_instance=bts)
        m = Market(base, quote, steem_instance=bts)
        self.assertEqual(m.get_string(), u'STEEM:SBD')
github holgern / beem / tests / beem / test_amount.py View on Github external
def test_json_appbase2(self):
        asset = Asset("SBD", steem_instance=self.bts)
        amount = Amount("1", asset, new_appbase_format=True, steem_instance=self.bts)
        if self.bts.rpc.get_use_appbase():
            self.assertEqual(
                amount.json(),
                {'amount': str(1 * 10 ** asset.precision), 'nai': asset.asset, 'precision': asset.precision})
        else:
            self.assertEqual(amount.json(), "1.000 SBD")
github holgern / beem / tests / beem / test_amount.py View on Github external
def test_json_appbase(self):
        asset = Asset("SBD", steem_instance=self.bts)
        amount = Amount("1", asset, new_appbase_format=False, steem_instance=self.bts)
        if self.bts.rpc.get_use_appbase():
            self.assertEqual(
                amount.json(),
                [str(1 * 10 ** asset.precision), asset.precision, asset.asset])
        else:
            self.assertEqual(amount.json(), "1.000 SBD")
github holgern / beem / tests / beem / test_asset.py View on Github external
stm = self.bts
        else:
            stm = self.steemit
        asset1 = Asset("SBD", full=False, steem_instance=stm)
        asset2 = Asset("SBD", full=False, steem_instance=stm)
        self.assertTrue(asset1 == asset2)
        self.assertTrue(asset1 == "SBD")
        self.assertTrue(asset2 == "SBD")
        asset3 = Asset("STEEM", full=False, steem_instance=stm)
        self.assertTrue(asset1 != asset3)
        self.assertTrue(asset3 != "SBD")
        self.assertTrue(asset1 != "STEEM")

        a = {'asset': '@@000000021', 'precision': 3, 'id': 'STEEM', 'symbol': 'STEEM'}
        b = {'asset': '@@000000021', 'precision': 3, 'id': '@@000000021', 'symbol': 'STEEM'}
        self.assertTrue(Asset(a, steem_instance=stm) == Asset(b, steem_instance=stm))
github holgern / beem / beem / price.py View on Github external
self,
        price=None,
        base=None,
        quote=None,
        base_asset=None,  # to identify sell/buy
        steem_instance=None
    ):

        self.steem = steem_instance or shared_steem_instance()
        if price == "":
            price = None
        if (price is not None and isinstance(price, string_types) and not base and not quote):
            import re
            price, assets = price.split(" ")
            base_symbol, quote_symbol = assets_from_string(assets)
            base = Asset(base_symbol, steem_instance=self.steem)
            quote = Asset(quote_symbol, steem_instance=self.steem)
            frac = Fraction(float(price)).limit_denominator(10 ** base["precision"])
            self["quote"] = Amount(amount=frac.denominator, asset=quote, steem_instance=self.steem)
            self["base"] = Amount(amount=frac.numerator, asset=base, steem_instance=self.steem)

        elif (price is not None and isinstance(price, dict) and
                "base" in price and
                "quote" in price):
            if "price" in price:
                raise AssertionError("You cannot provide a 'price' this way")
            # Regular 'price' objects according to steem-core
            # base_id = price["base"]["asset_id"]
            # if price["base"]["asset_id"] == base_id:
            self["base"] = Amount(price["base"], steem_instance=self.steem)
            self["quote"] = Amount(price["quote"], steem_instance=self.steem)
            # else:
github holgern / beem / beem / cli.py View on Github external
def buy(amount, asset, price, account, orderid):
    """Buy STEEM or SBD from the internal market

        Limit buy price denoted in (SBD per STEEM)
    """
    stm = shared_steem_instance()
    if stm.rpc is not None:
        stm.rpc.rpcconnect()
    if account is None:
        account = stm.config["default_account"]
    if asset == stm.sbd_symbol:
        market = Market(base=Asset(stm.steem_symbol), quote=Asset(stm.sbd_symbol), steem_instance=stm)
    else:
        market = Market(base=Asset(stm.sbd_symbol), quote=Asset(stm.steem_symbol), steem_instance=stm)
    if price is None:
        orderbook = market.orderbook(limit=1, raw_data=False)
        if asset == stm.steem_symbol and len(orderbook["bids"]) > 0:
            p = Price(orderbook["bids"][0]["base"], orderbook["bids"][0]["quote"], steem_instance=stm).invert()
            p_show = p
        elif len(orderbook["asks"]) > 0:
            p = Price(orderbook["asks"][0]["base"], orderbook["asks"][0]["quote"], steem_instance=stm).invert()
            p_show = p
        price_ok = click.prompt("Is the following Price ok: %s [y/n]" % (str(p_show)))
        if price_ok not in ["y", "ye", "yes"]:
            return
    else:
        p = Price(float(price), u"%s:%s" % (stm.sbd_symbol, stm.steem_symbol), steem_instance=stm)
    if not unlock_wallet(stm):
        return
github holgern / beem / beem / price.py View on Github external
elif (price is not None and isinstance(price, dict) and
                "base" in price and
                "quote" in price):
            if "price" in price:
                raise AssertionError("You cannot provide a 'price' this way")
            # Regular 'price' objects according to steem-core
            # base_id = price["base"]["asset_id"]
            # if price["base"]["asset_id"] == base_id:
            self["base"] = Amount(price["base"], steem_instance=self.steem)
            self["quote"] = Amount(price["quote"], steem_instance=self.steem)
            # else:
            #    self["quote"] = Amount(price["base"], steem_instance=self.steem)
            #    self["base"] = Amount(price["quote"], steem_instance=self.steem)

        elif (price is not None and isinstance(base, Asset) and isinstance(quote, Asset)):
            frac = Fraction(float(price)).limit_denominator(10 ** base["precision"])
            self["quote"] = Amount(amount=frac.denominator, asset=quote, steem_instance=self.steem)
            self["base"] = Amount(amount=frac.numerator, asset=base, steem_instance=self.steem)

        elif (price is not None and isinstance(base, string_types) and isinstance(quote, string_types)):
            base = Asset(base, steem_instance=self.steem)
            quote = Asset(quote, steem_instance=self.steem)
            frac = Fraction(float(price)).limit_denominator(10 ** base["precision"])
            self["quote"] = Amount(amount=frac.denominator, asset=quote, steem_instance=self.steem)
            self["base"] = Amount(amount=frac.numerator, asset=base, steem_instance=self.steem)

        elif (price is None and isinstance(base, string_types) and isinstance(quote, string_types)):
            self["quote"] = Amount(quote, steem_instance=self.steem)
            self["base"] = Amount(base, steem_instance=self.steem)
        elif (price is not None and isinstance(price, string_types) and isinstance(base, string_types)):
            self["quote"] = Amount(price, steem_instance=self.steem)
github holgern / beem / beem / amount.py View on Github external
def check_asset(other, self, stm):
    if isinstance(other, dict) and "asset" in other and isinstance(self, dict) and "asset" in self:
        if not Asset(other["asset"], steem_instance=stm) == Asset(self["asset"], steem_instance=stm):
            raise AssertionError()
    else:
        if not other == self:
            raise AssertionError()
github holgern / beem / beem / cli.py View on Github external
def sell(amount, asset, price, account, orderid):
    """Sell STEEM or SBD from the internal market

        Limit sell price denoted in (SBD per STEEM)
    """
    stm = shared_steem_instance()
    if stm.rpc is not None:
        stm.rpc.rpcconnect()
    if asset == stm.sbd_symbol:
        market = Market(base=Asset(stm.steem_symbol), quote=Asset(stm.sbd_symbol), steem_instance=stm)
    else:
        market = Market(base=Asset(stm.sbd_symbol), quote=Asset(stm.steem_symbol), steem_instance=stm)
    if not account:
        account = stm.config["default_account"]
    if not price:
        orderbook = market.orderbook(limit=1, raw_data=False)
        if asset == stm.sbd_symbol and len(orderbook["bids"]) > 0:
            p = Price(orderbook["bids"][0]["base"], orderbook["bids"][0]["quote"], steem_instance=stm).invert()
            p_show = p
        else:
            p = Price(orderbook["asks"][0]["base"], orderbook["asks"][0]["quote"], steem_instance=stm).invert()
            p_show = p
        price_ok = click.prompt("Is the following Price ok: %s [y/n]" % (str(p_show)))
        if price_ok not in ["y", "ye", "yes"]:
            return
    else:
github holgern / beem / beem / price.py View on Github external
# len(args) > 1

        elif isinstance(price, Amount) and isinstance(base, Amount):
            self["quote"], self["base"] = price, base

        # len(args) == 0
        elif (price is None and isinstance(base, Amount) and isinstance(quote, Amount)):
            self["quote"] = quote
            self["base"] = base

        elif ((isinstance(price, float) or isinstance(price, integer_types) or isinstance(price, Decimal)) and
                isinstance(base, string_types)):
            import re
            base_symbol, quote_symbol = assets_from_string(base)
            base = Asset(base_symbol, steem_instance=self.steem)
            quote = Asset(quote_symbol, steem_instance=self.steem)
            frac = Fraction(float(price)).limit_denominator(10 ** base["precision"])
            self["quote"] = Amount(amount=frac.denominator, asset=quote, steem_instance=self.steem)
            self["base"] = Amount(amount=frac.numerator, asset=base, steem_instance=self.steem)

        else:
            raise ValueError("Couldn't parse 'Price'.")