Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: holgern/beem
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.22.5
Choose a base ref
...
head repository: holgern/beem
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.22.6
Choose a head ref
  • 2 commits
  • 9 files changed
  • 1 contributor

Commits on Mar 24, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e1e2fcc View commit details
  2. release 0.22.6

    * Add hive_btc_ticker and hive_usd_ticker
    * use coingecko API
    * add HIVE/HBD to all marker operation in beempy
    holgern committed Mar 24, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    08b730f View commit details
Showing with 139 additions and 33 deletions.
  1. +6 −0 CHANGELOG.rst
  2. +30 −17 beem/cli.py
  3. +95 −11 beem/market.py
  4. +3 −0 beem/steem.py
  5. +1 −1 beem/version.py
  6. +1 −1 beemapi/version.py
  7. +1 −1 beembase/version.py
  8. +1 −1 beemgraphenebase/version.py
  9. +1 −1 setup.py
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Changelog
=========
0.22.6
------
* Add hive_btc_ticker and hive_usd_ticker
* use coingecko API
* add HIVE/HBD to all marker operation in beempy

0.22.5
------
* Add workaround to allow transfers of HIVE/HBD in HIVE (operation need to use STEEM/SBD internally)
47 changes: 30 additions & 17 deletions beem/cli.py
Original file line number Diff line number Diff line change
@@ -409,7 +409,7 @@ def currentnode(version, url):
'--show', '-s', is_flag=True, default=False,
help="Prints the updated nodes")
@click.option(
'--hive', '-t', is_flag=True, default=False,
'--hive', '-h', is_flag=True, default=False,
help="Use only HIVE nodes, when set to true.")
@click.option(
'--test', '-t', is_flag=True, default=False,
@@ -852,7 +852,7 @@ def transfer(to, amount, asset, memo, account):
@click.option('--account', '-a', help='Powerup from this account')
@click.option('--to', help='Powerup this account', default=None)
def powerup(amount, account, to):
"""Power up (vest STEEM as STEEM POWER)"""
"""Power up (vest STEEM/HIVE as STEEM/HIVE POWER)"""
stm = shared_steem_instance()
if stm.rpc is not None:
stm.rpc.rpcconnect()
@@ -935,7 +935,7 @@ def delegate(amount, to_account, account):
@click.option('--percentage', default=100, help='The percent of the withdraw to go to the "to" account')
@click.option('--account', '-a', help='Powerup from this account')
@click.option('--auto_vest', help='Set to true if the from account should receive the VESTS as'
'VESTS, or false if it should receive them as STEEM.', is_flag=True)
'VESTS, or false if it should receive them as STEEM/HIVE.', is_flag=True)
def powerdownroute(to, percentage, account, auto_vest):
"""Setup a powerdown route"""
stm = shared_steem_instance()
@@ -957,7 +957,7 @@ def powerdownroute(to, percentage, account, auto_vest):
@click.argument('amount', nargs=1)
@click.option('--account', '-a', help='Powerup from this account')
def convert(amount, account):
"""Convert STEEMDollars to Steem (takes a week to settle)"""
"""Convert SBD/HBD to Steem/Hive (takes a week to settle)"""
stm = shared_steem_instance()
if stm.rpc is not None:
stm.rpc.rpcconnect()
@@ -1779,7 +1779,7 @@ def ticker(sbd_to_steem):
ticker = market.ticker()
for key in ticker:
if key in ["highest_bid", "latest", "lowest_ask"] and sbd_to_steem:
t.add_row([key, str(ticker[key].as_base("SBD"))])
t.add_row([key, str(ticker[key].as_base(stm.sbd_symbol))])
elif key in "percent_change" and sbd_to_steem:
t.add_row([key, "%.2f %%" % -ticker[key]])
elif key in "percent_change":
@@ -1813,7 +1813,7 @@ def pricehistory(width, height, ascii):
else:
charset = u'utf8'
chart = AsciiChart(height=height, width=width, offset=4, placeholder='{:6.2f} $', charset=charset)
print("\n Price history for STEEM (median price %4.2f $)\n" % (float(current_base) / float(current_quote)))
print("\n Price history for %s (median price %4.2f $)\n" % (stm.steem_symbol, float(current_base) / float(current_quote)))

chart.adapt_on_series(price)
chart.new_chart()
@@ -1861,9 +1861,11 @@ def tradehistory(days, hours, sbd_to_steem, limit, width, height, ascii):
charset = u'utf8'
chart = AsciiChart(height=height, width=width, offset=3, placeholder='{:6.2f} ', charset=charset)
if sbd_to_steem:
print("\n Trade history %s - %s \n\nSBD/STEEM" % (formatTimeString(start), formatTimeString(stop)))
print("\n Trade history %s - %s \n\n%s/%s" % (formatTimeString(start), formatTimeString(stop),
stm.sbd_symbol, stm.steem_symbol))
else:
print("\n Trade history %s - %s \n\nSTEEM/SBD" % (formatTimeString(start), formatTimeString(stop)))
print("\n Trade history %s - %s \n\n%s/%s" % (formatTimeString(start), formatTimeString(stop),
stm.steem_symbol, stm.sbd_symbol))
chart.adapt_on_series(price)
chart.new_chart()
chart.add_axis()
@@ -1886,7 +1888,7 @@ def orderbook(chart, limit, show_date, width, height, ascii):
market = Market(steem_instance=stm)
orderbook = market.orderbook(limit=limit, raw_data=False)
if not show_date:
header = ["Asks Sum SBD", "Sell Orders", "Bids Sum SBD", "Buy Orders"]
header = ["Asks Sum " + stm.sbd_symbol, "Sell Orders", "Bids Sum " + stm.sbd_symbol, "Buy Orders"]
else:
header = ["Asks date", "Sell Orders", "Bids date", "Buy Orders"]
t = PrettyTable(header, hrules=0)
@@ -1902,13 +1904,13 @@ def orderbook(chart, limit, show_date, width, height, ascii):
n = 0
for order in orderbook["asks"]:
asks.append(order)
sum_asks += float(order.as_base("SBD")["base"])
sum_asks += float(order.as_base(stm.sbd_symbol)["base"])
sumsum_asks.append(sum_asks)
if n < len(asks):
n = len(asks)
for order in orderbook["bids"]:
bids.append(order)
sum_bids += float(order.as_base("SBD")["base"])
sum_bids += float(order.as_base(stm.sbd_symbol)["base"])
sumsum_bids.append(sum_bids)
if n < len(bids):
n = len(bids)
@@ -1974,9 +1976,9 @@ def orderbook(chart, limit, show_date, width, height, ascii):
@click.option('--account', '-a', help='Buy with this account (defaults to "default_account")')
@click.option('--orderid', help='Set an orderid')
def buy(amount, asset, price, account, orderid):
"""Buy STEEM or SBD from the internal market
"""Buy STEEM/HIVE or SBD/HBD from the internal market
Limit buy price denoted in (SBD per STEEM)
Limit buy price denoted in (SBD per STEEM or HBD per HIVE)
"""
stm = shared_steem_instance()
if stm.rpc is not None:
@@ -2019,9 +2021,9 @@ def buy(amount, asset, price, account, orderid):
@click.option('--account', '-a', help='Sell with this account (defaults to "default_account")')
@click.option('--orderid', help='Set an orderid')
def sell(amount, asset, price, account, orderid):
"""Sell STEEM or SBD from the internal market
"""Sell STEEM/HIVE or SBD/HBD from the internal market
Limit sell price denoted in (SBD per STEEM)
Limit sell price denoted in (SBD per STEEM) or (HBD per HIVE)
"""
stm = shared_steem_instance()
if stm.rpc is not None:
@@ -2352,24 +2354,35 @@ def witnessfeed(witness, wif, base, quote, support_peg):
old_quote = witness["sbd_exchange_rate"]["quote"]
last_published_price = Price(witness["sbd_exchange_rate"], steem_instance=stm)
steem_usd = None
hive_usd = None
print("Old price %.3f (base: %s, quote %s)" % (float(last_published_price), old_base, old_quote))
if quote is None and not support_peg:
quote = Amount("1.000 %s" % stm.steem_symbol, steem_instance=stm)
elif quote is None:
elif quote is None and not stm.is_hive:
latest_price = market.ticker()['latest']
if steem_usd is None:
steem_usd = market.steem_usd_implied()
sbd_usd = float(latest_price.as_base(stm.sbd_symbol)) * steem_usd
quote = Amount(1. / sbd_usd, stm.steem_symbol, steem_instance=stm)
elif quote is None and stm.is_hive:
latest_price = market.ticker()['latest']
if hive_usd is None:
hive_usd = market.hive_usd_implied()
hbd_usd = float(latest_price.as_base(stm.sbd_symbol)) * hive_usd
quote = Amount(1. / hbd_usd, stm.steem_symbol, steem_instance=stm)
else:
if str(quote[-5:]).upper() == stm.steem_symbol:
quote = Amount(quote, steem_instance=stm)
else:
quote = Amount(quote, stm.steem_symbol, steem_instance=stm)
if base is None:
if base is None and not stm.is_hive:
if steem_usd is None:
steem_usd = market.steem_usd_implied()
base = Amount(steem_usd, stm.sbd_symbol, steem_instance=stm)
elif base is None and stm.is_hive:
if hive_usd is None:
hive_usd = market.hive_usd_implied()
base = Amount(hive_usd, stm.sbd_symbol, steem_instance=stm)
else:
if str(quote[-3:]).upper() == stm.sbd_symbol:
base = Amount(base, steem_instance=stm)
106 changes: 95 additions & 11 deletions beem/market.py
Original file line number Diff line number Diff line change
@@ -83,8 +83,8 @@ def __init__(
base = Asset(base, steem_instance=self.steem)
super(Market, self).__init__({"base": base, "quote": quote})
elif base is None and quote is None:
quote = Asset("SBD", steem_instance=self.steem)
base = Asset("STEEM", steem_instance=self.steem)
quote = Asset(self.steem.sbd_symbol, steem_instance=self.steem)
base = Asset(self.steem.steem_symbol, steem_instance=self.steem)
super(Market, self).__init__({"base": base, "quote": quote})
else:
raise ValueError("Unknown Market config")
@@ -725,11 +725,12 @@ def btc_usd_ticker(verbose=False):
prices = {}
responses = []
urls = [
"https://api.bitfinex.com/v1/pubticker/BTCUSD",
"https://api.gdax.com/products/BTC-USD/ticker",
"https://api.kraken.com/0/public/Ticker?pair=XBTUSD",
"https://www.okcoin.com/api/v1/ticker.do?symbol=btc_usd",
"https://www.bitstamp.net/api/v2/ticker/btcusd/",
#"https://api.bitfinex.com/v1/pubticker/BTCUSD",
#"https://api.gdax.com/products/BTC-USD/ticker",
#"https://api.kraken.com/0/public/Ticker?pair=XBTUSD",
#"https://www.okcoin.com/api/v1/ticker.do?symbol=btc_usd",
#"https://www.bitstamp.net/api/v2/ticker/btcusd/",
"https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd&include_24hr_vol=true",
]
try:
responses = list(requests.get(u, timeout=30) for u in urls)
@@ -764,6 +765,11 @@ def btc_usd_ticker(verbose=False):
prices['bitstamp'] = {
'price': float(data['last']),
'volume': float(data['volume'])}
elif "coingecko" in r.url:
data = r.json()["bitcoin"]
prices['coingecko'] = {
'price': float(data['usd']),
'volume': float(data['usd_24h_vol'])}
except KeyError as e:
log.info(str(e))

@@ -787,10 +793,11 @@ def steem_btc_ticker():
responses = []
urls = [
# "https://poloniex.com/public?command=returnTicker",
"https://bittrex.com/api/v1.1/public/getmarketsummary?market=BTC-STEEM",
"https://api.binance.com/api/v1/ticker/24hr",
"https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=steembtc",
"https://crix-api.upbit.com/v1/crix/trades/ticks?code=CRIX.UPBIT.BTC-STEEM&count=1",
# "https://bittrex.com/api/v1.1/public/getmarketsummary?market=BTC-STEEM",
# "https://api.binance.com/api/v1/ticker/24hr",
# "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=steembtc",
# "https://crix-api.upbit.com/v1/crix/trades/ticks?code=CRIX.UPBIT.BTC-STEEM&count=1",
"https://api.coingecko.com/api/v3/simple/price?ids=steem&vs_currencies=btc&include_24hr_vol=true",
]
headers = {'Content-type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36'}
@@ -826,6 +833,11 @@ def steem_btc_ticker():
prices['upbit'] = {
'price': float(data['tradePrice']),
'volume': float(data['tradeVolume'])}
elif "coingecko" in r.url:
data = r.json()["steem"]
prices['coingecko'] = {
'price': float(data['btc']),
'volume': float(data['btc_24h_vol'])}
except KeyError as e:
log.info(str(e))

@@ -839,3 +851,75 @@ def steem_btc_ticker():
def steem_usd_implied(self):
"""Returns the current STEEM/USD market price"""
return self.steem_btc_ticker() * self.btc_usd_ticker()

@staticmethod
def hive_btc_ticker():
""" Returns the HIVE/BTC price from bittrex and upbit. The mean price is
weighted by the exchange volume.
"""
prices = {}
responses = []
urls = [
# "https://bittrex.com/api/v1.1/public/getmarketsummary?market=BTC-HIVE",
# "https://api.binance.com/api/v1/ticker/24hr",
# "https://api.probit.com/api/exchange/v1/ticker?market_ids=HIVE-USDT",
"https://api.coingecko.com/api/v3/simple/price?ids=hive&vs_currencies=btc&include_24hr_vol=true",
]
headers = {'Content-type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36'}
try:
responses = list(requests.get(u, headers=headers, timeout=30) for u in urls)
except Exception as e:
log.debug(str(e))

for r in [x for x in responses
if hasattr(x, "status_code") and x.status_code == 200 and x.json()]:
try:
if "poloniex" in r.url:
data = r.json()["BTC_HIVE"]
prices['poloniex'] = {
'price': float(data['last']),
'volume': float(data['baseVolume'])}
elif "bittrex" in r.url:
data = r.json()["result"][0]
price = (data['Bid'] + data['Ask']) / 2
prices['bittrex'] = {'price': price, 'volume': data['BaseVolume']}
elif "binance" in r.url:
data = [x for x in r.json() if x['symbol'] == 'HIVEBTC'][0]
prices['binance'] = {
'price': float(data['lastPrice']),
'volume': float(data['quoteVolume'])}
elif "huobi" in r.url:
data = r.json()["data"][-1]
prices['huobi'] = {
'price': float(data['close']),
'volume': float(data['vol'])}
elif "upbit" in r.url:
data = r.json()[-1]
prices['upbit'] = {
'price': float(data['tradePrice']),
'volume': float(data['tradeVolume'])}
elif "probit" in r.url:
data = r.json()["data"]
prices['huobi'] = {
'price': float(data['last']),
'volume': float(data['base_volume'])}
elif "coingecko" in r.url:
data = r.json()["hive"]
prices['coingecko'] = {
'price': float(data['btc']),
'volume': float(data['btc_24h_vol'])}
except KeyError as e:
log.info(str(e))

if len(prices) == 0:
raise RuntimeError("Obtaining HIVE/BTC prices has failed from all sources.")

return Market._weighted_average(
[x['price'] for x in prices.values()],
[x['volume'] for x in prices.values()])

def hive_usd_implied(self):
"""Returns the current HIVE/USD market price"""
return self.hive_btc_ticker() * self.btc_usd_ticker()

3 changes: 3 additions & 0 deletions beem/steem.py
Original file line number Diff line number Diff line change
@@ -830,6 +830,9 @@ def prefix(self):

@property
def is_hive(self):
config = self.get_config()
if config is None:
return False
return 'HIVE_CHAIN_ID' in self.get_config()

def set_default_account(self, account):
2 changes: 1 addition & 1 deletion beem/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""THIS FILE IS GENERATED FROM beem SETUP.PY."""
version = '0.22.5'
version = '0.22.6'
2 changes: 1 addition & 1 deletion beemapi/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""THIS FILE IS GENERATED FROM beem SETUP.PY."""
version = '0.22.5'
version = '0.22.6'
2 changes: 1 addition & 1 deletion beembase/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""THIS FILE IS GENERATED FROM beem SETUP.PY."""
version = '0.22.5'
version = '0.22.6'
2 changes: 1 addition & 1 deletion beemgraphenebase/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""THIS FILE IS GENERATED FROM beem SETUP.PY."""
version = '0.22.5'
version = '0.22.6'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
ascii = codecs.lookup('ascii')
codecs.register(lambda name, enc=ascii: {True: enc}.get(name == 'mbcs'))

VERSION = '0.22.5'
VERSION = '0.22.6'

tests_require = ['mock >= 2.0.0', 'pytest', 'pytest-mock', 'parameterized']