Example #1
0
    def buy(self,
            amount,
            quote_symbol,
            rate,
            expiration=7 * 24 * 60 * 60,
            killfill=False,
            account=None,
            order_id=None):
        """ Places a buy order in a given market (buy ``quote``, sell
            ``base`` in market ``quote_base``). If successful, the
            method will return the order creating (signed) transaction.

            :param number amount: Amount of ``quote`` to buy

            :param str quote_symbol: STEEM, or SBD

            :param float price: price denoted in ``base``/``quote``

            :param number expiration: (optional) expiration time of the
            order in seconds (defaults to 7 days)

            :param bool killfill: flag that indicates if the order shall be
            killed if it is not filled (defaults to False)

            :param str account: (optional) the source account for the
            transfer if not ``default_account``

            :param int order_id: (optional) a 32bit orderid for tracking of
            the created order (random by default)

            Prices/Rates are denoted in 'base', i.e. the STEEM:SBD market
            is priced in SBD per STEEM.
        """
        if not account:
            if "default_account" in config:
                account = config["default_account"]
        if not account:
            raise ValueError("You need to provide an account")

        # We buy quote and pay with base
        quote, base = self._get_assets(quote=quote_symbol)
        op = operations.LimitOrderCreate(
            **{
                "owner":
                account,
                "orderid":
                order_id or random.getrandbits(32),
                "amount_to_sell":
                '{:.{prec}f} {asset}'.format(amount * rate,
                                             prec=base["precision"],
                                             asset=base["symbol"]),
                "min_to_receive":
                '{:.{prec}f} {asset}'.format(
                    amount, prec=quote["precision"], asset=quote["symbol"]),
                "fill_or_kill":
                killfill,
                "expiration":
                transactions.fmt_time_from_now(expiration)
            })
        return self.steemd.commit.finalizeOp(op, account, "active")
Example #2
0
    def test_order_create(self):
        op = operations.LimitOrderCreate(
            **{
                "owner": "",
                "orderid": 0,
                "amount_to_sell": "0.000 STEEM",
                "min_to_receive": "0.000 STEEM",
                "fill_or_kill": False,
                "expiration": "2016-12-31T23:59:59"
            })
        ops = [operations.Operation(op)]
        tx = SignedTransaction(ref_block_num=ref_block_num,
                               ref_block_prefix=ref_block_prefix,
                               expiration=expiration,
                               operations=ops)
        tx = tx.sign([wif], chain=self.steem.chain_params)

        tx_wire = hexlify(bytes(tx)).decode("ascii")
        compare = ("f68585abf4dce7c8045701050000000000000000000000000003535"
                   "445454d0000000000000000000003535445454d0000007f46685800"
                   "011f28a2fc52dcfc19378c5977917b158dfab93e7760259aab7ecdb"
                   "cb82df7b22e1a5527e02fd3aab7d64302ec550c3edcbba29d73226c"
                   "f088273e4fafda89eb7de8")
        self.assertEqual(compare[:-130], tx_wire[:-130])