Example #1
0
    def test_pricefeed(self):
        feed = objects.PriceFeed(
            **{
                "settlement_price":
                objects.Price(
                    base=objects.Asset(amount=214211, asset_id="1.3.0"),
                    quote=objects.Asset(amount=1241, asset_id="1.3.14"),
                ),
                "core_exchange_rate":
                objects.Price(
                    base=objects.Asset(amount=1241, asset_id="1.3.0"),
                    quote=objects.Asset(amount=6231, asset_id="1.3.14"),
                ),
                "maximum_short_squeeze_ratio":
                1100,
                "maintenance_collateral_ratio":
                1750,
            })

        self.op = operations.Asset_publish_feed(
            fee=objects.Asset(amount=100, asset_id="1.3.0"),
            publisher="1.2.0",
            asset_id="1.3.3",
            feed=feed,
        )
        self.cm = ("f68585abf4dce7c8045701136400000000000000000003c344030"
                   "00000000000d9040000000000000ed6064c04d904000000000000"
                   "0057180000000000000e0000012009e13f9066fedc3c8c1eb2ac3"
                   "3b15dc67ecebf708890d0f8ab62ec8283d1636002315a189f1f5a"
                   "a8497b41b8e6bb7c4dc66044510fae25d8f6aebb02c7cdef10")
        self.doit()
    def test_pricefeed(self):
        feed = objects.PriceFeed(
            **{
                "settlement_price":
                objects.Price(
                    base=objects.Asset(amount=214211, asset_id="1.3.0"),
                    quote=objects.Asset(amount=1241, asset_id="1.3.14"),
                ),
                "core_exchange_rate":
                objects.Price(
                    base=objects.Asset(amount=1241, asset_id="1.3.0"),
                    quote=objects.Asset(amount=6231, asset_id="1.3.14"),
                ),
                "maximum_short_squeeze_ratio":
                1100,
                "maintenance_collateral_ratio":
                1750,
            })

        op = operations.Asset_publish_feed(fee=objects.Asset(amount=100,
                                                             asset_id="1.3.0"),
                                           publisher="1.2.0",
                                           asset_id="1.3.3",
                                           feed=feed)
        ops = [Operation(op)]
        tx = Signed_Transaction(ref_block_num=ref_block_num,
                                ref_block_prefix=ref_block_prefix,
                                expiration=expiration,
                                operations=ops)
        tx = tx.sign([wif], chain=prefix)
        tx.verify([PrivateKey(wif).pubkey], "BTS")
        txWire = hexlify(bytes(tx)).decode("ascii")

        compare = ("f68585abf4dce7c8045701136400000000000000000003c344030"
                   "00000000000d9040000000000000ed6064c04d904000000000000"
                   "0057180000000000000e0000012009e13f9066fedc3c8c1eb2ac3"
                   "3b15dc67ecebf708890d0f8ab62ec8283d1636002315a189f1f5a"
                   "a8497b41b8e6bb7c4dc66044510fae25d8f6aebb02c7cdef10")
        self.assertEqual(compare[:-130], txWire[:-130])
Example #3
0
    def publish_price_feed(self,
                           symbol,
                           settlement_price,
                           cer=None,
                           mssr=110,
                           mcr=200,
                           account=None):
        """ Publish a price feed for a market-pegged asset

            :param str symbol: Symbol of the asset to publish feed for
            :param bitshares.price.Price settlement_price: Price for settlement
            :param bitshares.price.Price cer: Core exchange Rate (default ``settlement_price + 5%``)
            :param float mssr: Percentage for max short squeeze ratio (default: 110%)
            :param float mcr: Percentage for maintenance collateral ratio (default: 200%)
            :param str account: (optional) the account to allow access
                to (defaults to ``default_account``)

            .. note:: The ``account`` needs to be allowed to produce a
                      price feed for ``symbol``. For witness produced
                      feeds this means ``account`` is a witness account!
        """
        assert isinstance(
            settlement_price, Price
        ), "settlement_price needs to be instance of `bitshares.price.Price`!"
        if not account:
            if "default_account" in config:
                account = config["default_account"]
        if not account:
            raise ValueError("You need to provide an account")
        account = Account(account, bitshares_instance=self)
        asset = Asset(symbol, bitshares_instance=self, full=True)
        assert asset["id"] == settlement_price["base"]["asset"]["id"] or \
            asset["id"] == settlement_price["quote"]["asset"]["id"], \
            "Price needs to contain the asset of the symbol you'd like to produce a feed for!"
        assert asset.is_bitasset, "Symbol needs to be a bitasset!"
        assert settlement_price["base"]["asset"]["id"] == asset["bitasset_data"]["options"]["short_backing_asset"] or \
            settlement_price["quote"]["asset"]["id"] == asset["bitasset_data"]["options"]["short_backing_asset"], \
            "The Price needs to be relative to the backing collateral!"

        # Base needs to be short backing asset
        if settlement_price["base"]["asset"]["id"] == asset["bitasset_data"][
                "options"]["short_backing_asset"]:
            settlement_price = settlement_price.invert()

        if cer:
            if cer["base"]["asset"]["id"] == asset["bitasset_data"]["options"][
                    "short_backing_asset"]:
                cer = cer.invert()
        else:
            cer = settlement_price * 1.05

        op = operations.Asset_publish_feed(
            **{
                "fee": {
                    "amount": 0,
                    "asset_id": "1.3.0"
                },
                "publisher": account["id"],
                "asset_id": asset["id"],
                "feed": {
                    "settlement_price": settlement_price.json(),
                    "core_exchange_rate": cer.json(),
                    "maximum_short_squeeze_ratio": int(mssr * 10),
                    "maintenance_collateral_ratio": int(mcr * 10),
                },
                "prefix": self.rpc.chain_params["prefix"]
            })
        return self.finalizeOp(op, account["name"], "active")