Отчет делегата kiwi #2 - Неделя 44/2016
Это была занятая неделя:
python-goloslib (GitHub)
https://github.com/GolosChain/python-goloslib/pull/3Я работаю над Python Price Feed (для делегатов)
На следующей неделе: новые инструменты "Megaphone/Мегафон"
English version:
It was a busy week.
python-goloslib merged to master
https://github.com/GolosChain/python-goloslib/pull/3I am working on publish feed script and added two new classes.
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)
...
- plan for the next week: work on 'Megaphone', see https://github.com/Netherdrake/steemtools/issues/4