Уважаемые пользователи Голос!
Сайт доступен в режиме «чтение» до сентября 2020 года. Операции с токенами Golos, Cyber можно проводить, используя альтернативные клиенты или через эксплорер Cyberway. Подробности здесь: https://golos.io/@goloscore/operacii-s-tokenami-golos-cyber-1594822432061
С уважением, команда “Голос”
GOLOS
RU
EN
UA
kiwi
8 лет назад

Отчет делегата kiwi #2 - Неделя 44/2016

Отчет делегата kiwi #2 - Неделя 44/2016


Это была занятая неделя:


English version:

It was a busy week.

class Gold(object):
    """
    Return value of 1mg Gold in USD.
    """

    URL = "http://data-asg.goldprice.org/GetData/USD-XAU/1"
    GRAM_PER_OZ = 31.1034768

    @staticmethod
    def price_oz():
        """
        Return price of 1 ounce of Gold in USD

        :return: XAU OZ price in USD, 0.0 if incorrect response
        :rtype float
        """
        rs = grequests.get(Gold.URL, timeout=2)
        response = grequests.map([rs], exception_handler=lambda x, y: "")[0]
        if hasattr(response, "status_code") and response.status_code == 200:
            return float(response.json()[0].split(",")[1])
        return 0.0

    @staticmethod
    def price_mg():
        """
        Return price of 1mg of Gold in USD

        :return: XAU 1mg price in USD
        :rtype: float
        """
        return Gold.price_oz() / Gold.GRAM_PER_OZ / 1000.0


class ICOFeed(object):
    """
    Update witness GBG/GOLOS feed based on ICO balance.
    """
    ICO_TOKENS = 45120000
    ICO_ACCOUNT = "3CWicRKHQqcj1N6fT1pC9J3hUzHw1KyPv3"
    ICO_BALANCE_URL = \
        "http://btc.blockr.io/api/v1/address/balance/%s?confirmations=2"

    def __init__(self, witness_account_name, witness_wif):
        self.wif = witness_wif
        self.account = witness_account_name
        try:
            self.golos = Steem(node="wss://node.golos.ws",
                               apis=["login_api", "network_broadcast_api"])
        except Exception as e:
            print(e)
        self.ticker = Ticker()
        self.gold = Gold()

    @staticmethod
    def ico_balance():
        """
        Return ICO balance in BTC.

        :return: ICO balance
        :rtype: float
        """
        url = ICOFeed.ICO_BALANCE_URL % ICOFeed.ICO_ACCOUNT
        rs = grequests.get(url, timeout=2)
        response = grequests.map([rs], exception_handler=lambda x, y: "")[0]
        if hasattr(response, "status_code") and response.status_code == 200:
            return float(response.json()['data']['balance'])
        else:
            raise TickerError("Could not retrieve ICO balance!")

    def publish_feed(self):
        """
        Publish GBG / GOLOS price feed.

        :return: True if publish was successful, false otherwise
        :rtype: bool
        """
        btc_usd = self.ticker.price("btc/usd")
        mg_gold = self.gold.price_mg()
        ico_balance = ICOFeed.ico_balance()
        golos_usd = ico_balance * btc_usd / ICOFeed.ICO_TOKENS
        golos_per_gbg = mg_gold / golos_usd
        print("Trying to publish 1.000 GBG / %s GOLOS" % golos_per_gbg)
        op = Feed_publish(
            **{
                "publisher": self.account,
                "exchange_rate": {
                    "base": "1.00 GBG",
                    "quote": "%s GOLOS" % golos_per_gbg,
                }
            }
        )
        tx = self.golos.constructTx(op, self.wif)
        pprint(tx)
        ...
0
5.946 GOLOS
На Golos с October 2016
Комментарии (0)
Сортировать по:
Сначала старые