Beispiel #1
0
    def returnTradeHistory(self, time=1 * 60 * 60, limit=100):
        """ Returns the trade history for the internal market

            :param int hours: Show the last x seconds of trades (default 1h)
            :param int limit: amount of trades to show (<100) (default: 100)
        """
        assert limit <= 100, "'limit' has to be smaller than 100"
        return self.dpay.rpc.get_trade_history(
            transactions.formatTimeFromNow(-time),
            transactions.formatTimeFromNow(),
            limit,
            api="market_history"
        )
Beispiel #2
0
 def constructTx(self):
     if isinstance(self.op, list):
         ops = [Operation(o) for o in self.op]
     else:
         ops = [Operation(self.op)]
     expiration = transactions.formatTimeFromNow(self.dpay.expiration)
     ref_block_num, ref_block_prefix = transactions.getBlockParams(
         self.dpay.rpc)
     tx = Signed_Transaction(ref_block_num=ref_block_num,
                             ref_block_prefix=ref_block_prefix,
                             expiration=expiration,
                             operations=ops)
     super(TransactionBuilder, self).__init__(tx.json())
Beispiel #3
0
    def returnMarketHistory(
        self,
        bucket_seconds=60 * 5,
        start_age=1 * 60 * 60,
        stop_age=0,
    ):
        """ Return the market history (filled orders).

            :param int bucket_seconds: Bucket size in seconds (see `returnMarketHistoryBuckets()`)
            :param int start_age: Age (in seconds) of the start of the window (default: 1h/3600)
            :param int end_age: Age (in seconds) of the end of the window (default: now/0)

            Example:

            .. code-block:: js

                 {'close_bbd': 2493387,
                  'close_dpay': 7743431,
                  'high_bbd': 1943872,
                  'high_dpay': 5999610,
                  'id': '7.1.5252',
                  'low_bbd': 534928,
                  'low_dpay': 1661266,
                  'open': '2016-07-08T11:25:00',
                  'open_bbd': 534928,
                  'open_dpay': 1661266,
                  'bbd_volume': 9714435,
                  'seconds': 300,
                  'dpay_volume': 30088443},
        """
        return self.dpay.rpc.get_market_history(
            bucket_seconds,
            transactions.formatTimeFromNow(-start_age - stop_age),
            transactions.formatTimeFromNow(-stop_age),
            api="market_history"
        )
Beispiel #4
0
    def buy(self,
            amount,
            quote_symbol,
            rate,
            expiration=7 * 24 * 60 * 60,
            killfill=False,
            account=None,
            orderid=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: BEX, or BBD
            :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 orderid: (optional) a 32bit orderid for tracking of the created order (random by default)

            Prices/Rates are denoted in 'base', i.e. the BEX:BBD market
            is priced in BBD per BEX.
        """
        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 = transactions.Limit_order_create(**{
            "owner": account,
            "orderid": orderid 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.formatTimeFromNow(expiration)
        })
        return self.dpay.finalizeOp(op, account, "active")