Пример #1
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_sbd': 2493387,
                  'close_steem': 7743431,
                  'high_sbd': 1943872,
                  'high_steem': 5999610,
                  'id': '7.1.5252',
                  'low_sbd': 534928,
                  'low_steem': 1661266,
                  'open': '2016-07-08T11:25:00',
                  'open_sbd': 534928,
                  'open_steem': 1661266,
                  'sbd_volume': 9714435,
                  'seconds': 300,
                  'steem_volume': 30088443},
        """
        return self.steem.rpc.get_market_history(
            bucket_seconds,
            transactions.formatTimeFromNow(-start_age - stop_age),
            transactions.formatTimeFromNow(-stop_age),
            api="market_history")
Пример #2
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.steem.rpc.get_trade_history(
            transactions.formatTimeFromNow(-time),
            transactions.formatTimeFromNow(),
            limit,
            api="market_history")
Пример #3
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.steem.rpc.get_trade_history(
            transactions.formatTimeFromNow(-time),
            transactions.formatTimeFromNow(),
            limit,
            api="market_history"
        )
Пример #4
0
def castvote(op):
    expiration = transactions.formatTimeFromNow(180)
    ref_block_num, ref_block_prefix = transactions.getBlockParams(rpc)
    tx = transactions.Signed_Transaction(ref_block_num=ref_block_num,
                                         ref_block_prefix=ref_block_prefix,
                                         expiration=expiration,
                                         operations=[op])
    tx = tx.sign([wif])
    dobroadcast(tx)
Пример #5
0
def proceed(op):
  expiration = transactions.formatTimeFromNow(60)
  ops    = [transactions.Operation(op)]
  ref_block_num, ref_block_prefix = transactions.getBlockParams(rpc)
  tx     = transactions.Signed_Transaction(ref_block_num=ref_block_num,
                                         ref_block_prefix=ref_block_prefix,
                                         expiration=expiration,
                                         operations=ops)
  tx = tx.sign([wif])

  # Broadcast JSON to network
  rpc.broadcast_transaction(tx.json(), api="network_broadcast")
Пример #6
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.steem.expiration)
     ref_block_num, ref_block_prefix = transactions.getBlockParams(
         self.steem.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())
Пример #7
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: 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 orderid: (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 = 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.steem.finalizeOp(op, account, "active")
Пример #8
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.steem.expiration)
     ref_block_num, ref_block_prefix = transactions.getBlockParams(self.steem.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())
Пример #9
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_sbd': 2493387,
                  'close_steem': 7743431,
                  'high_sbd': 1943872,
                  'high_steem': 5999610,
                  'id': '7.1.5252',
                  'low_sbd': 534928,
                  'low_steem': 1661266,
                  'open': '2016-07-08T11:25:00',
                  'open_sbd': 534928,
                  'open_steem': 1661266,
                  'sbd_volume': 9714435,
                  'seconds': 300,
                  'steem_volume': 30088443},
        """
        return self.steem.rpc.get_market_history(
            bucket_seconds,
            transactions.formatTimeFromNow(-start_age - stop_age),
            transactions.formatTimeFromNow(-stop_age),
            api="market_history"
        )
Пример #10
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: 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 orderid: (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 = 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.steem.finalizeOp(op, account, "active")
Пример #11
0
def transfer(sender, recipient, amount, memo):
    expiration = transactions.formatTimeFromNow(60)
    op = transactions.Transfer(**{
        "from": sender,
        "to": recipient,
        "amount": amount,
        "memo": memo
    })
    ops = [transactions.Operation(op)]
    ref_block_num, ref_block_prefix = transactions.getBlockParams(rpc)
    tx = transactions.Signed_Transaction(ref_block_num=ref_block_num,
                                         ref_block_prefix=ref_block_prefix,
                                         expiration=expiration,
                                         operations=ops)
    tx = tx.sign([wif])

    # Broadcast JSON to network
    rpc.broadcast_transaction(tx.json(), api="network_broadcast")
Пример #12
0
def transfer(sender,recipient,amount,memo):
  expiration = transactions.formatTimeFromNow(60)
  op = transactions.Transfer(
    **{"from": sender,
       "to": recipient,
       "amount": amount,
       "memo": memo}
  )
  ops    = [transactions.Operation(op)]
  ref_block_num, ref_block_prefix = transactions.getBlockParams(rpc)
  tx     = transactions.Signed_Transaction(ref_block_num=ref_block_num,
                                         ref_block_prefix=ref_block_prefix,
                                         expiration=expiration,
                                         operations=ops)
  tx = tx.sign([wif])

  # Broadcast JSON to network
  rpc.broadcast_transaction(tx.json(), api="network_broadcast")
Пример #13
0
    if oldmissed == 0:
      oldmissed = missed
      print('Starting at '+str(missed)+' missed blocks')
    else:
      if missed > oldmissed or misscount > 0:
        checkcount = checkcount + 1

        if missed > oldmissed:
          misscount = misscount + 1
          oldmissed = missed
          print('Missed '+str(misscount)+' block(s) in '+str(checkcount)+' minutes. Total missed: '+str(missed))
          message = "Your node missed "+str(misscount)+" blocks, "+str(missed)+" total."
          sendmail(message,"Missed blocks...")

        if checkcount > 1 and misscount > 1:
          expiration = transactions.formatTimeFromNow(60)
          op = transactions.Witness_update(
            **{"owner": account,
             "url": witness['url'],
             "block_signing_key": backupkey,
             "props": witness['props'],
             "fee": str(fee)+' STEEM'}
          )
          proceed(op)
          print('Failover activated because of too many missed blocks')
          sendmail("Failover activated","Witness failover activated")
          sys.exit()

        if checkcount > 5:
            checkcount = 0
            misscount = 0