-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc_debt_ratio.py
68 lines (50 loc) · 2.38 KB
/
calc_debt_ratio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
__author__ = "http://hive.blog/@cervantes"
__copyright__ = "Copyright (C) 2020 hive's @cervantes"
__license__ = "MIT"
__version__ = "1.1"
from beem import Steem
def average(mylist):
'''Compute median value'''
sum=0
for e in mylist:
sum=sum+int(e)
average_value = (sum/len(mylist))/1000
return(average_value)
def get_debt_ratio():
stm = Steem("https://anyx.io")
prop = stm.get_dynamic_global_properties()
#for k in prop:
#print("%s: %s"%(k,prop[k]))
virtual_supply = int(prop["virtual_supply"]["amount"]) / 1000
current_supply = int(prop["current_supply"]["amount"]) / 1000
current_sbd_supply = int(prop["current_sbd_supply"]["amount"]) / 1000
median_base = int(stm.get_current_median_history()["base"]["amount"])
median_quote = int(stm.get_current_median_history()["quote"]["amount"])
median_price = (median_base / median_quote)
prices = [k["base"]["amount"] for k in stm.get_feed_history()["price_history"]]
median_price = average(prices)
#median_price = 0.45
steem_market_cap = virtual_supply * median_price
debt_ratio = (current_sbd_supply / (virtual_supply * median_price)) * 100
result = {}
result["virtual_supply"] = virtual_supply
result["current_supply"] = current_supply
result["current_sbd_supply"] = current_sbd_supply
result["median_price_history"] = prices
result["median_price"] = median_price
result["steem_market_cap"] = steem_market_cap
result["debt_ratio"] = debt_ratio
return(result)
if __name__ == '__main__':
result = get_debt_ratio()
#print(result)
print("\n")
print("################ HBD/HIVE DEBT RATIO #######")
print("virtual_supply: %s Mio HIVE" % str(round((result["virtual_supply"]/1000000),2)))
print("current_supply: %s Mio HIVE" % str(round((result["current_supply"]/1000000),2)))
print("current_sbd_supply: %s Mio HDB " % str(round((result["current_sbd_supply"]/1000000),2)))
print("average_price_feed: %s $" % str(round(result["median_price"],5)))
print("hive_market_cap: %s Mio $" % str(round(result["steem_market_cap"]/1000000,3)))
print("debt_ratio: %s %% " % str(round(result["debt_ratio"],4)))
print("#############################################\n")
print("The average feed price is over the last %s samples : %s " % (len(result["median_price_history"]), average(result["median_price_history"])))