示例#1
0
    def curation_stats(self):
        trailing_24hr_t = time.time() - datetime.timedelta(
            hours=24).total_seconds()
        trailing_7d_t = time.time() - datetime.timedelta(
            days=7).total_seconds()

        reward_24h = 0.0
        reward_7d = 0.0

        for reward in take(5000,
                           self.history_reverse(filter_by="curation_reward")):

            timestamp = parse_time(reward['timestamp']).timestamp()
            if timestamp > trailing_7d_t:
                reward_7d += Amount(reward['reward']).amount

            if timestamp > trailing_24hr_t:
                reward_24h += Amount(reward['reward']).amount

        reward_7d = self.converter.vests_to_sp(reward_7d)
        reward_24h = self.converter.vests_to_sp(reward_24h)
        return {
            "24hr": reward_24h,
            "7d": reward_7d,
            "avg": reward_7d / 7,
        }
示例#2
0
 def sbd_median_price(self):
     """ Obtain the sbd price as derived from the median over all
         witness feeds. Return value will be SBD
     """
     return (Amount(self.steemd.get_feed_history()['current_median_history']
                    ['base']).amount /
             Amount(self.steemd.get_feed_history()['current_median_history']
                    ['quote']).amount)
示例#3
0
    def get_balances(self):
        available = {
            'STEEM': Amount(self['balance']).amount,
            'SBD': Amount(self['sbd_balance']).amount,
            'VESTS': Amount(self['vesting_shares']).amount,
        }

        savings = {
            'STEEM': Amount(self['savings_balance']).amount,
            'SBD': Amount(self['savings_sbd_balance']).amount,
        }

        rewards = {
            'STEEM': Amount(self['reward_steem_balance']).amount,
            'SBD': Amount(self['reward_sbd_balance']).amount,
            'VESTS': Amount(self['reward_vesting_balance']).amount,
        }

        totals = {
            'STEEM':
            sum([available['STEEM'], savings['STEEM'], rewards['STEEM']]),
            'SBD': sum([available['SBD'], savings['SBD'], rewards['SBD']]),
            'VESTS': sum([available['VESTS'], rewards['VESTS']]),
        }

        total = walk_values(rpartial(round, 3), totals)

        return {
            'available': available,
            'savings': savings,
            'rewards': rewards,
            'total': total,
        }
示例#4
0
    def get_ticker(self):
        """ Returns the ticker for all markets.

            Output Parameters:

            * ``latest``: Price of the order last filled
            * ``lowest_ask``: Price of the lowest ask
            * ``highest_bid``: Price of the highest bid
            * ``sbd_volume``: Volume of SBD
            * ``steem_volume``: Volume of STEEM
            * ``percent_change``: 24h change percentage (in %)

            .. note::

                Market is STEEM:SBD and prices are SBD per STEEM!

            Sample Output:

            .. code-block:: js

                 {'highest_bid': 0.30100226633322913,
                  'latest': 0.0,
                  'lowest_ask': 0.3249636958897082,
                  'percent_change': 0.0,
                  'sbd_volume': 108329611.0,
                  'steem_volume': 355094043.0}


        """
        t = self.steemd.get_ticker()
        return {
            'highest_bid': float(t['highest_bid']),
            'latest': float(t["latest"]),
            'lowest_ask': float(t["lowest_ask"]),
            'percent_change': float(t["percent_change"]),
            'sbd_volume': Amount(t["sbd_volume"]),
            'steem_volume': Amount(t["steem_volume"])
        }
示例#5
0
    def sbd_to_rshares(self, sbd_payout):
        """ Obtain r-shares from SBD

            :param number sbd_payout: Amount of SBD
        """
        steem_payout = self.sbd_to_steem(sbd_payout)

        props = self.steemd.get_dynamic_global_properties()
        total_reward_fund_steem = Amount(props['total_reward_fund_steem'])
        total_reward_shares2 = int(props['total_reward_shares2'])

        post_rshares2 = (steem_payout /
                         total_reward_fund_steem) * total_reward_shares2

        rshares = math.sqrt(self.CONTENT_CONSTANT**2 +
                            post_rshares2) - self.CONTENT_CONSTANT
        return rshares
示例#6
0
    def refresh(self):
        post_author, post_permlink = resolve_identifier(self.identifier)
        post = self.steemd.get_content(post_author, post_permlink)
        if not post["permlink"]:
            raise PostDoesNotExist("Post does not exist: %s" % self.identifier)

        # If this 'post' comes from an operation, it might carry a patch
        if "body" in post and re.match("^@@", post["body"]):
            self.patched = True

        # This field is returned from blockchain, but it's empty. Fill it
        post['reblogged_by'] = [
            i for i in self.steemd.get_reblogged_by(post_author, post_permlink)
            if i != post_author
        ]

        # Parse Times
        parse_times = [
            "active", "cashout_time", "created", "last_payout", "last_update",
            "max_cashout_time"
        ]
        for p in parse_times:
            post[p] = parse_time(post.get(p, "1970-01-01T00:00:00"))

        # Parse Amounts
        sbd_amounts = [
            'total_payout_value',
            'max_accepted_payout',
            'pending_payout_value',
            'curator_payout_value',
            'total_pending_payout_value',
            'promoted',
        ]
        for p in sbd_amounts:
            post[p] = Amount(post.get(p, '0.000 SBD'))

        # calculate trending and hot scores for sorting
        post['score_trending'] = calculate_trending(post.get('net_rshares', 0),
                                                    post['created'])
        post['score_hot'] = calculate_hot(post.get('net_rshares', 0),
                                          post['created'])

        # turn json_metadata into python dict
        meta_str = post.get('json_metadata', '{}')
        post['json_metadata'] = silent(json.loads)(meta_str) or {}

        post['tags'] = []
        post['community'] = ''
        if isinstance(post['json_metadata'], dict):
            if post["depth"] == 0:
                tags = [post["parent_permlink"]]
                tags += get_in(post, ['json_metadata', 'tags'], default=[])
                tags_added = set()
                post['tags'] = [
                    tag for tag in tags
                    if not (tag in tags_added or tags_added.add(tag))
                ]

            post['community'] = get_in(post, ['json_metadata', 'community'],
                                       default='')

        # If this post is a comment, retrieve the root comment
        self.root_identifier, self.category = self._get_root_identifier(post)

        self._store_post(post)
示例#7
0
 def reward(self):
     """Return a float value of estimated total SBD reward.
     """
     return Amount(self.get("total_payout_value", "0 SBD")) + \
            Amount(self.get("pending_payout_value", "0 SBD"))
示例#8
0
 def steem_per_mvests(self):
     """ Obtain STEEM/MVESTS ratio
     """
     info = self.steemd.get_dynamic_global_properties()
     return (Amount(info["total_vesting_fund_steem"]).amount /
             (Amount(info["total_vesting_shares"]).amount / 1e6))
示例#9
0
def test_amount_init():
    a = Amount('1 STEEM')
    assert dict(a) == {'amount': 1.0, 'asset': 'STEEM'}
示例#10
0
 def sp(self):
     vests = Amount(self['vesting_shares']).amount
     return round(self.converter.vests_to_sp(vests), 3)