cosgrove 0.0.4.0 → 0.0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/README.md +42 -10
- data/cosgrove.gemspec +7 -7
- data/example-authorize-hive-sql.sh +5 -0
- data/lib/cosgrove.rb +2 -2
- data/lib/cosgrove/account.rb +27 -14
- data/lib/cosgrove/bot.rb +8 -8
- data/lib/cosgrove/comment_job.rb +4 -4
- data/lib/cosgrove/config.rb +28 -0
- data/lib/cosgrove/find_communities_job.rb +47 -0
- data/lib/cosgrove/market.rb +637 -90
- data/lib/cosgrove/support.rb +97 -24
- data/lib/cosgrove/upvote_job.rb +12 -8
- data/lib/cosgrove/utils.rb +186 -24
- data/lib/cosgrove/version.rb +1 -1
- metadata +55 -61
- data/example-authorize-steem-sql.sh +0 -5
data/lib/cosgrove/market.rb
CHANGED
@@ -1,18 +1,25 @@
|
|
1
1
|
module Cosgrove
|
2
2
|
module Market
|
3
3
|
include Support
|
4
|
+
include Utils
|
4
5
|
include ActionView::Helpers::NumberHelper
|
5
6
|
|
6
|
-
def base_per_mvest(chain = :
|
7
|
+
def base_per_mvest(chain = :hive)
|
7
8
|
api(chain).get_dynamic_global_properties do |properties|
|
8
|
-
|
9
|
-
|
9
|
+
case chain
|
10
|
+
when :steem
|
11
|
+
total_vesting_fund_base = properties.total_vesting_fund_steem.to_f
|
12
|
+
total_vesting_shares_mvest = properties.total_vesting_shares.to_f / 1e6
|
13
|
+
when :hive
|
14
|
+
total_vesting_fund_base = properties.total_vesting_fund_hive.to_f
|
15
|
+
total_vesting_shares_mvest = properties.total_vesting_shares.to_f / 1e6
|
16
|
+
end
|
10
17
|
|
11
|
-
|
18
|
+
total_vesting_fund_base / total_vesting_shares_mvest
|
12
19
|
end
|
13
20
|
end
|
14
21
|
|
15
|
-
def price_feed(chain = :
|
22
|
+
def price_feed(chain = :hive)
|
16
23
|
api(chain).get_feed_history do |feed_history|
|
17
24
|
current_median_history = feed_history.current_median_history
|
18
25
|
base = current_median_history.base
|
@@ -42,29 +49,17 @@ module Cosgrove
|
|
42
49
|
|
43
50
|
def market_data
|
44
51
|
pol_btc_steem = JSON[open("https://poloniex.com/public?command=returnOrderBook¤cyPair=BTC_STEEM&depth=10").read]
|
45
|
-
pol_btc_sbd = JSON[open("https://poloniex.com/public?command=returnOrderBook¤cyPair=BTC_SBD&depth=10").read]
|
46
52
|
pol_usdt_btc = JSON[open("https://poloniex.com/public?command=returnOrderBook¤cyPair=USDT_BTC&depth=10").read]
|
47
53
|
|
48
54
|
pol_btc_steem = pol_btc_steem['asks'].first.first.to_f
|
49
|
-
pol_btc_sbd = pol_btc_sbd['asks'].first.first.to_f
|
50
55
|
pol_usdt_btc = pol_usdt_btc['asks'].first.first.to_f
|
51
56
|
|
52
|
-
pol_usdt_sbd = pol_usdt_btc * pol_btc_sbd
|
53
57
|
pol_usdt_steem = pol_usdt_btc * pol_btc_steem
|
54
|
-
# pol_sbd_steem = pol_usdt_sbd * ( pol_usdt_btc * pol_btc_steem )
|
55
58
|
|
56
|
-
btx_btc_golos = JSON[open("https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-golos").read]
|
57
|
-
btx_btc_gbg = JSON[open("https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-gbg").read]
|
58
59
|
btx_usdt_btc = JSON[open("https://bittrex.com/api/v1.1/public/getmarketsummary?market=usdt-btc").read]
|
59
60
|
|
60
|
-
btx_btc_golos = btx_btc_golos['result'].first['Ask'].to_f
|
61
|
-
btx_btc_gbg = btx_btc_gbg['result'].first['Ask'].to_f
|
62
61
|
btx_usdt_btc = btx_usdt_btc['result'].first['Ask'].to_f
|
63
62
|
|
64
|
-
btx_usdt_gbg = btx_usdt_btc * btx_btc_gbg
|
65
|
-
btx_usdt_golos = btx_usdt_btc * btx_btc_golos
|
66
|
-
# btx_gbg_golos = btx_usdt_gbg * ( btx_usdt_btc * btx_btc_golos )
|
67
|
-
|
68
63
|
btx_btc_steem = JSON[open("https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-steem").read]
|
69
64
|
btx_btc_sbd = JSON[open("https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-sbd").read]
|
70
65
|
|
@@ -73,22 +68,63 @@ module Cosgrove
|
|
73
68
|
|
74
69
|
btx_usdt_sbd = btx_usdt_btc * btx_btc_sbd
|
75
70
|
btx_usdt_steem = btx_usdt_btc * btx_btc_steem
|
76
|
-
# btx_sbd = btx_usdt_sbd * ( btx_usdt_btc * btx_btc_steem )
|
77
71
|
|
78
|
-
[pol_usdt_steem,
|
72
|
+
[pol_usdt_steem, btx_usdt_steem, btx_usdt_sbd]
|
73
|
+
end
|
74
|
+
|
75
|
+
def btx_market_data
|
76
|
+
btx_usdt_btc = JSON[open("https://bittrex.com/api/v1.1/public/getmarketsummary?market=usdt-btc").read]
|
77
|
+
|
78
|
+
btx_usdt_btc = btx_usdt_btc['result'].first['Last'].to_f
|
79
|
+
|
80
|
+
btx_btc_steem = JSON[open("https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-steem").read]
|
81
|
+
btx_btc_sbd = JSON[open("https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-sbd").read]
|
82
|
+
|
83
|
+
btx_btc_steem = btx_btc_steem['result'].first['Last'].to_f
|
84
|
+
btx_btc_sbd = btx_btc_sbd['result'].first['Last'].to_f
|
85
|
+
|
86
|
+
btx_usdt_sbd = btx_usdt_btc * btx_btc_sbd
|
87
|
+
btx_usdt_steem = btx_usdt_btc * btx_btc_steem
|
88
|
+
|
89
|
+
btx_btc_hive = JSON[open("https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-hive").read]
|
90
|
+
btx_usdt_hive = JSON[open("https://bittrex.com/api/v1.1/public/getmarketsummary?market=usdt-hive").read]
|
91
|
+
btx_btc_hbd = JSON[open("https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-hbd").read]
|
92
|
+
|
93
|
+
btx_btc_hive = btx_btc_hive['result'].first['Last'].to_f
|
94
|
+
btx_usdt_hive = btx_usdt_hive['result'].first['Last'].to_f
|
95
|
+
btx_btc_hbd = btx_btc_hbd['result'].first['Last'].to_f
|
96
|
+
|
97
|
+
btx_usdt_hbd = btx_usdt_btc * btx_btc_hbd
|
98
|
+
|
99
|
+
{
|
100
|
+
usdt_steem: btx_usdt_steem,
|
101
|
+
usdt_sbd: btx_usdt_sbd,
|
102
|
+
btc_steem: btx_btc_steem,
|
103
|
+
btc_sbd: btx_btc_sbd,
|
104
|
+
usdt_hive: btx_usdt_hive,
|
105
|
+
usdt_hbd: btx_usdt_hbd,
|
106
|
+
btc_hive: btx_btc_hive,
|
107
|
+
btc_hbd: btx_btc_hbd
|
108
|
+
}
|
79
109
|
end
|
80
110
|
|
81
|
-
def mvests(chain = :
|
82
|
-
|
111
|
+
def mvests(chain = :hive, account_names = [])
|
112
|
+
chain = chain.to_s.downcase.to_sym
|
113
|
+
_btx_market_data = btx_market_data
|
114
|
+
btx_usdt_steem, btx_usdt_sbd = _btx_market_data[:usdt_steem], _btx_market_data[:usdt_sbd]
|
115
|
+
btx_usdt_hive, btx_usdt_hbd = _btx_market_data[:usdt_hive], _btx_market_data[:usdt_hbd]
|
83
116
|
base_per_mvest, base_per_debt = price_feed(chain)
|
84
117
|
|
85
118
|
if account_names.none?
|
86
|
-
btx_base_per_dept_as_usdt =
|
119
|
+
btx_base_per_dept_as_usdt = case chain
|
120
|
+
when :steem then base_per_mvest * btx_usdt_steem
|
121
|
+
when :hive then base_per_mvest * btx_usdt_hive
|
122
|
+
end
|
87
123
|
btx_base_per_dept_as_usdt = number_to_currency(btx_base_per_dept_as_usdt, precision: 3)
|
88
124
|
|
89
125
|
base_per_mvest = number_with_precision(base_per_mvest, precision: 3, delimiter: ',', separator: '.')
|
90
126
|
|
91
|
-
base_per_debt = if chain == :steem
|
127
|
+
base_per_debt = if chain == :steem || chain == :hive
|
92
128
|
number_to_currency(base_per_debt, precision: 3)
|
93
129
|
else
|
94
130
|
_btc_gld, usdt_gld_per_milli = gold_price
|
@@ -103,6 +139,7 @@ module Cosgrove
|
|
103
139
|
when :steem then "`1 MV = 1M VESTS = #{base_per_mvest} STEEM = #{base_per_debt} = #{btx_base_per_dept_as_usdt} on Bittrex`"
|
104
140
|
when :golos then "`1 MG = 1M GESTS = #{base_per_mvest} GOLOS = #{base_per_debt} GBG = #{base_per_debt_as_usdt}`"
|
105
141
|
when :test then "`1 MT = 1M TESTS = #{base_per_mvest} TEST = #{base_per_debt}`"
|
142
|
+
when :hive then "`1 MV = 1M VESTS = #{base_per_mvest} HIVE = #{base_per_debt} = #{btx_base_per_dept_as_usdt} on Bittrex`"
|
106
143
|
end
|
107
144
|
end
|
108
145
|
|
@@ -132,7 +169,102 @@ module Cosgrove
|
|
132
169
|
end
|
133
170
|
|
134
171
|
account_names = account_names.map(&:downcase).uniq
|
135
|
-
accounts = SteemApi::Account.where(name: account_names)
|
172
|
+
# accounts = SteemApi::Account.where(name: account_names)
|
173
|
+
# account = accounts.limit(1).first
|
174
|
+
|
175
|
+
# if accounts.count == account_names.size
|
176
|
+
# vests = accounts.pluck(:vesting_shares).map(&:to_f).sum
|
177
|
+
# delegated_vests = accounts.pluck(:delegated_vesting_shares).map(&:to_f).sum
|
178
|
+
# received_vests = accounts.pluck(:received_vesting_shares).map(&:to_f).sum
|
179
|
+
# elsif !wildcards
|
180
|
+
# valid_names = accounts.distinct(:name)
|
181
|
+
# unknown_names = account_names - valid_names
|
182
|
+
# return unknown_account(unknown_names.first)
|
183
|
+
# end
|
184
|
+
|
185
|
+
# if accounts.count == 1 && vests == 0.0
|
186
|
+
# # Falling back to RPC because balance is out of date and we only want
|
187
|
+
# # a single account.
|
188
|
+
# api(:steem).get_accounts([account.name]) do |accounts|
|
189
|
+
# account = accounts.first
|
190
|
+
# vests = account.vesting_shares.split(' ').first.to_f
|
191
|
+
# delegated_vests = account.delegated_vesting_shares.split(' ').first.to_f
|
192
|
+
# received_vests = account.received_vesting_shares.split(' ').first.to_f
|
193
|
+
# end
|
194
|
+
# end
|
195
|
+
|
196
|
+
# mvests = vests / 1000000
|
197
|
+
# delegated_vests = (received_vests - delegated_vests) / 1000000
|
198
|
+
# steem = base_per_mvest * mvests
|
199
|
+
# sbd = base_per_debt * mvests
|
200
|
+
# btx_sbd = base_per_mvest * mvests * btx_usdt_steem
|
201
|
+
#
|
202
|
+
# mvests = number_with_precision(mvests, precision: 3, delimiter: ',', separator: '.')
|
203
|
+
# delegated_sign = delegated_vests >= 0.0 ? '+' : '-'
|
204
|
+
# delegated_vests = number_with_precision(delegated_vests.abs, precision: 3, delimiter: ',', separator: '.')
|
205
|
+
# steem = number_with_precision(steem, precision: 3, delimiter: ',', separator: '.')
|
206
|
+
# sbd = number_to_currency(sbd, precision: 3)
|
207
|
+
# btx_sbd = number_to_currency(btx_sbd, precision: 3)
|
208
|
+
#
|
209
|
+
# if accounts.size == 1
|
210
|
+
# balance = ["#{mvests} MVESTS = #{steem} STEEM = #{sbd} = #{btx_sbd} on Bittrex"]
|
211
|
+
# unless delegated_vests == '0.000'
|
212
|
+
# balance << "(#{delegated_sign}#{delegated_vests} MVESTS delegated)"
|
213
|
+
# end
|
214
|
+
#
|
215
|
+
# "**#{account.name}:** `#{balance.join(' ')}`"
|
216
|
+
# else
|
217
|
+
# balance = ["#{mvests} MVESTS = #{steem} STEEM = #{sbd} = #{btx_sbd} on Bittrex"]
|
218
|
+
# unless delegated_vests == '0.000'
|
219
|
+
# balance << "(#{delegated_sign}#{delegated_vests} MVESTS delegated)"
|
220
|
+
# end
|
221
|
+
#
|
222
|
+
# "**#{pluralize(accounts.count, 'account')}:** `#{balance.join(' ')}`"
|
223
|
+
# end
|
224
|
+
when :golos
|
225
|
+
account = nil
|
226
|
+
gests = nil
|
227
|
+
|
228
|
+
api(:golos).get_accounts(account_names) do |accounts, error|
|
229
|
+
account = accounts.first
|
230
|
+
gests = account.vesting_shares.split(' ').first.to_f
|
231
|
+
end
|
232
|
+
|
233
|
+
mgests = gests / 1000000
|
234
|
+
golos = base_per_mvest * mgests
|
235
|
+
gbg = base_per_debt * mgests
|
236
|
+
_btc_gld, usdt_gld_per_milli = gold_price
|
237
|
+
usd = gbg * usdt_gld_per_milli
|
238
|
+
|
239
|
+
mgests = number_with_precision(mgests, precision: 3, delimiter: ',', separator: '.')
|
240
|
+
golos = number_with_precision(golos, precision: 3, delimiter: ',', separator: '.')
|
241
|
+
gbg = number_with_precision(gbg, precision: 3, delimiter: ',', separator: '.')
|
242
|
+
usd = number_to_currency(usd, precision: 3)
|
243
|
+
|
244
|
+
"**#{account.name}:** `#{mgests} MGESTS = #{golos} GOLOS = #{gbg} GBG = #{usd}`"
|
245
|
+
when :hive
|
246
|
+
vests = 0
|
247
|
+
delegated_vests = 0
|
248
|
+
received_vests = 0
|
249
|
+
account = nil
|
250
|
+
wildcards = false
|
251
|
+
|
252
|
+
account_names.each do |a|
|
253
|
+
if a =~ /.*\*$/
|
254
|
+
wildcards = true
|
255
|
+
lower_bound_name = a.split('*').first
|
256
|
+
api(chain).lookup_accounts(a, 1000) do |names, error|
|
257
|
+
if names.any?
|
258
|
+
account_names -= [a]
|
259
|
+
account_names += [lower_bound_name]
|
260
|
+
account_names += names.map { |name| name if name =~ /#{lower_bound_name}.*/ }.compact
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
account_names = account_names.map(&:downcase).uniq
|
267
|
+
accounts = HiveSQL::Account.where(name: account_names)
|
136
268
|
account = accounts.limit(1).first
|
137
269
|
|
138
270
|
if accounts.count == account_names.size
|
@@ -148,7 +280,7 @@ module Cosgrove
|
|
148
280
|
if accounts.count == 1 && vests == 0.0
|
149
281
|
# Falling back to RPC because balance is out of date and we only want
|
150
282
|
# a single account.
|
151
|
-
api(
|
283
|
+
api(chain).get_accounts([account.name]) do |accounts|
|
152
284
|
account = accounts.first
|
153
285
|
vests = account.vesting_shares.split(' ').first.to_f
|
154
286
|
delegated_vests = account.delegated_vesting_shares.split(' ').first.to_f
|
@@ -158,59 +290,41 @@ module Cosgrove
|
|
158
290
|
|
159
291
|
mvests = vests / 1000000
|
160
292
|
delegated_vests = (received_vests - delegated_vests) / 1000000
|
161
|
-
|
162
|
-
|
163
|
-
|
293
|
+
hive = base_per_mvest * mvests
|
294
|
+
hbd = base_per_debt * mvests
|
295
|
+
btx_hbd = base_per_mvest * mvests * btx_usdt_hive
|
164
296
|
|
165
297
|
mvests = number_with_precision(mvests, precision: 3, delimiter: ',', separator: '.')
|
166
298
|
delegated_sign = delegated_vests >= 0.0 ? '+' : '-'
|
167
299
|
delegated_vests = number_with_precision(delegated_vests.abs, precision: 3, delimiter: ',', separator: '.')
|
168
|
-
|
169
|
-
|
170
|
-
|
300
|
+
hive = number_with_precision(hive, precision: 3, delimiter: ',', separator: '.')
|
301
|
+
hbd = number_to_currency(hbd, precision: 3)
|
302
|
+
btx_hbd = number_to_currency(btx_hbd, precision: 3)
|
171
303
|
|
172
304
|
if accounts.size == 1
|
173
|
-
balance = ["#{mvests} MVESTS = #{
|
305
|
+
balance = ["#{mvests} MVESTS = #{hive} HIVE = #{hbd} = #{btx_hbd} on Bittrex"]
|
174
306
|
unless delegated_vests == '0.000'
|
175
307
|
balance << "(#{delegated_sign}#{delegated_vests} MVESTS delegated)"
|
176
308
|
end
|
177
309
|
|
178
310
|
"**#{account.name}:** `#{balance.join(' ')}`"
|
179
311
|
else
|
180
|
-
balance = ["#{mvests} MVESTS = #{
|
312
|
+
balance = ["#{mvests} MVESTS = #{hive} HIVE = #{hbd} = #{btx_hbd} on Bittrex"]
|
181
313
|
unless delegated_vests == '0.000'
|
182
314
|
balance << "(#{delegated_sign}#{delegated_vests} MVESTS delegated)"
|
183
315
|
end
|
184
316
|
|
185
317
|
"**#{pluralize(accounts.count, 'account')}:** `#{balance.join(' ')}`"
|
186
318
|
end
|
187
|
-
when :golos
|
188
|
-
account = nil
|
189
|
-
gests = nil
|
190
|
-
|
191
|
-
api(:golos).get_accounts(account_names) do |accounts, error|
|
192
|
-
account = accounts.first
|
193
|
-
gests = account.vesting_shares.split(' ').first.to_f
|
194
|
-
end
|
195
|
-
|
196
|
-
mgests = gests / 1000000
|
197
|
-
golos = base_per_mvest * mgests
|
198
|
-
gbg = base_per_debt * mgests
|
199
|
-
_btc_gld, usdt_gld_per_milli = gold_price
|
200
|
-
usd = gbg * usdt_gld_per_milli
|
201
|
-
|
202
|
-
mgests = number_with_precision(mgests, precision: 3, delimiter: ',', separator: '.')
|
203
|
-
golos = number_with_precision(golos, precision: 3, delimiter: ',', separator: '.')
|
204
|
-
gbg = number_with_precision(gbg, precision: 3, delimiter: ',', separator: '.')
|
205
|
-
usd = number_to_currency(usd, precision: 3)
|
206
|
-
|
207
|
-
"**#{account.name}:** `#{mgests} MGESTS = #{golos} GOLOS = #{gbg} GBG = #{usd}`"
|
208
319
|
when :test then "Query not supported. No database for Testnet."
|
209
320
|
end
|
210
321
|
end
|
211
322
|
|
212
|
-
def rewardpool(chain = :
|
213
|
-
|
323
|
+
def rewardpool(chain = :hive)
|
324
|
+
chain = chain.to_s.downcase.to_sym
|
325
|
+
_btx_market_data = btx_market_data
|
326
|
+
btx_usdt_steem, btx_usdt_sbd = _btx_market_data[:usdt_steem], _btx_market_data[:usdt_sbd]
|
327
|
+
btx_usdt_hive, btx_usdt_hbd = _btx_market_data[:usdt_hive], _btx_market_data[:usdt_hbd]
|
214
328
|
base_per_mvest, base_per_debt = price_feed(chain)
|
215
329
|
|
216
330
|
case chain
|
@@ -242,30 +356,424 @@ module Cosgrove
|
|
242
356
|
"Total Reward Fund: `#{total} GOLOS (Worth: #{total_gbg} GBG internally; #{btx_total_usd} on Bittrex)`"
|
243
357
|
when :test
|
244
358
|
"Total Reward Fund: `#{('%.3f' % total)} TEST (Worth: #{('%.3f' % total_usd)} TBD internally)`"
|
359
|
+
when :hive
|
360
|
+
total = api(chain).get_reward_fund('post') do |reward_fund|
|
361
|
+
reward_fund.reward_balance.split(' ').first.to_f
|
362
|
+
end
|
363
|
+
|
364
|
+
total_usd = (total / base_per_mvest) * base_per_debt
|
365
|
+
btx_total_usd = total * btx_usdt_hive
|
366
|
+
|
367
|
+
total = number_with_precision(total, precision: 0, delimiter: ',', separator: '.')
|
368
|
+
total_usd = number_to_currency(total_usd, precision: 0)
|
369
|
+
btx_total_usd = number_to_currency(btx_total_usd, precision: 0)
|
370
|
+
|
371
|
+
"Total Reward Fund: `#{total} HIVE (Worth: #{total_usd} internally; #{btx_total_usd} on Bittrex)`"
|
245
372
|
end
|
246
373
|
end
|
247
374
|
|
248
|
-
def ticker
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
375
|
+
def render_ticker(message, event, ticker = {}, chain = :hive)
|
376
|
+
chain ||= :hive
|
377
|
+
ticker ||= {}
|
378
|
+
chain = chain.to_s.downcase.to_sym
|
379
|
+
return if ticker.size < 1
|
380
|
+
|
381
|
+
start_typing event
|
382
|
+
|
383
|
+
ticker_text = case chain
|
384
|
+
when :steem
|
385
|
+
"```markdown\n" +
|
386
|
+
"| | USD/STEEM | USD/SBD | BTC/STEEM | BTC/SBD |\n" +
|
387
|
+
"|-------------------|-------------|-------------|-------------|-------------|\n"
|
388
|
+
when :hive
|
389
|
+
"```markdown\n" +
|
390
|
+
"| | USD/HIVE | USD/HBD | BTC/HIVE | BTC/HBD |\n" +
|
391
|
+
"|-------------------|------------|-------------|------------|-------------|\n"
|
392
|
+
end
|
393
|
+
|
394
|
+
ticker_text += ticker.map do |key, value|
|
395
|
+
"| #{key} | #{value} |"
|
396
|
+
end.join("\n")
|
397
|
+
|
398
|
+
ticker_text += "\n```\n"
|
399
|
+
|
400
|
+
if message.nil? && !!event
|
401
|
+
message = event.respond ticker_text
|
402
|
+
elsif !!message
|
403
|
+
message.edit ticker_text
|
404
|
+
end
|
405
|
+
|
406
|
+
message || ticker_text
|
263
407
|
end
|
264
408
|
|
265
|
-
def
|
266
|
-
|
409
|
+
def ticker(event = nil, chain = :hive)
|
410
|
+
chain = chain.to_s.downcase.to_sym
|
411
|
+
message = nil
|
412
|
+
threads = []
|
413
|
+
|
414
|
+
case chain
|
415
|
+
when :steem
|
416
|
+
key_bittrex = 'bittrex.com '
|
417
|
+
key_binance = 'binance.com '
|
418
|
+
key_huobi = 'huobi.pro '
|
419
|
+
key_upbit = 'upbit.com '
|
420
|
+
# key_postpromoter = 'postpromoter.net '
|
421
|
+
key_coingecko = 'coingecko.com '
|
422
|
+
key_poloniex = 'poloniex.com '
|
423
|
+
# key_steem_engine = 'steem-engine.com '
|
424
|
+
ticker = {
|
425
|
+
key_bittrex => nil,
|
426
|
+
key_binance => nil,
|
427
|
+
key_huobi => nil,
|
428
|
+
key_upbit => nil,
|
429
|
+
# key_postpromoter => nil,
|
430
|
+
key_coingecko => nil,
|
431
|
+
key_poloniex => nil,
|
432
|
+
# key_steem_engine => nil
|
433
|
+
}
|
434
|
+
|
435
|
+
threads << Thread.new do
|
436
|
+
begin
|
437
|
+
_btx_market_data = btx_market_data
|
438
|
+
btx_usdt_steem, btx_usdt_sbd = _btx_market_data[:usdt_steem], _btx_market_data[:usdt_sbd]
|
439
|
+
btx_btc_steem, btx_btx_sbd = _btx_market_data[:btc_steem], _btx_market_data[:btc_sbd]
|
440
|
+
|
441
|
+
btx_usdt_steem = number_to_currency(btx_usdt_steem, precision: 4).rjust(11)
|
442
|
+
btx_usdt_sbd = number_to_currency(btx_usdt_sbd, precision: 4).rjust(11)
|
443
|
+
btx_btc_steem = number_to_currency(btx_btc_steem, precision: 8, unit: '').rjust(11)
|
444
|
+
btx_btx_sbd = number_to_currency(btx_btx_sbd, precision: 8, unit: '').rjust(11)
|
445
|
+
|
446
|
+
ticker[key_bittrex] = "#{btx_usdt_steem} | #{btx_usdt_sbd} | #{btx_btc_steem} | #{btx_btx_sbd}"
|
447
|
+
rescue => e
|
448
|
+
puts e
|
449
|
+
end
|
450
|
+
end
|
451
|
+
|
452
|
+
threads << Thread.new do
|
453
|
+
begin
|
454
|
+
bin_steem_btc = JSON[open('https://api.binance.com/api/v1/ticker/price?symbol=STEEMBTC').read].fetch('price').to_f
|
455
|
+
bin_btc_usdt = JSON[open('https://api.binance.com/api/v1/ticker/price?symbol=BTCUSDT').read].fetch('price').to_f
|
456
|
+
bin_usdt_steem = bin_btc_usdt * bin_steem_btc
|
457
|
+
bin_usdt_steem = number_to_currency(bin_usdt_steem, precision: 4).rjust(11)
|
458
|
+
bin_steem_btc = number_to_currency(bin_steem_btc, precision: 8, unit: '').rjust(11)
|
459
|
+
|
460
|
+
ticker[key_binance] = "#{bin_usdt_steem} | | #{bin_steem_btc} | "
|
461
|
+
rescue => e
|
462
|
+
puts e
|
463
|
+
end
|
464
|
+
end
|
465
|
+
|
466
|
+
threads << Thread.new do
|
467
|
+
begin
|
468
|
+
hub_steem_usdt = JSON[open('https://api.huobi.pro/market/detail/merged?symbol=steemusdt').read].fetch('tick').fetch('close').to_f
|
469
|
+
hub_steem_btc = JSON[open('https://api.huobi.pro/market/detail/merged?symbol=steembtc').read].fetch('tick').fetch('close').to_f
|
470
|
+
hub_steem_usdt = number_to_currency(hub_steem_usdt, precision: 4).rjust(11)
|
471
|
+
hub_steem_btc = number_to_currency(hub_steem_btc, precision: 8, unit: '').rjust(11)
|
472
|
+
|
473
|
+
ticker[key_huobi] = "#{hub_steem_usdt} | | #{hub_steem_btc} | "
|
474
|
+
rescue => e
|
475
|
+
puts e
|
476
|
+
end
|
477
|
+
end
|
478
|
+
|
479
|
+
threads << Thread.new do
|
480
|
+
begin
|
481
|
+
upb_btc_steem = JSON[open('https://api.upbit.com/v1/trades/ticks?market=BTC-STEEM').read][0].fetch('trade_price').to_f
|
482
|
+
upb_btc_sbd = JSON[open('https://api.upbit.com/v1/trades/ticks?market=BTC-SBD').read][0].fetch('trade_price').to_f
|
483
|
+
upb_usdt_btc = JSON[open('https://api.upbit.com/v1/trades/ticks?market=USDT-BTC').read][0].fetch('trade_price').to_f
|
484
|
+
upb_usdt_steem = upb_usdt_btc * upb_btc_steem
|
485
|
+
upb_usdt_sbd = upb_usdt_btc * upb_btc_sbd
|
486
|
+
upb_usdt_steem = number_to_currency(upb_usdt_steem, precision: 4).rjust(11)
|
487
|
+
upb_usdt_sbd = number_to_currency(upb_usdt_sbd, precision: 4).rjust(11)
|
488
|
+
upb_btc_steem = number_to_currency(upb_btc_steem, precision: 8, unit: '').rjust(11)
|
489
|
+
upb_btc_sbd = number_to_currency(upb_btc_sbd, precision: 8, unit: '').rjust(11)
|
490
|
+
|
491
|
+
ticker[key_upbit] = "#{upb_usdt_steem} | #{upb_usdt_sbd} | #{upb_btc_steem} | #{upb_btc_sbd}"
|
492
|
+
rescue => e
|
493
|
+
puts e
|
494
|
+
end
|
495
|
+
end
|
496
|
+
|
497
|
+
# threads << Thread.new do
|
498
|
+
# begin
|
499
|
+
# post_promoter_feed = JSON[open('https://postpromoter.net/api/prices').read]
|
500
|
+
# pp_usd_steem = post_promoter_feed.fetch('steem_price').to_f
|
501
|
+
# pp_usd_sbd = post_promoter_feed.fetch('sbd_price').to_f
|
502
|
+
# pp_usd_steem = number_to_currency(pp_usd_steem, precision: 4).rjust(11)
|
503
|
+
# pp_usd_sbd = number_to_currency(pp_usd_sbd, precision: 4).rjust(11)
|
504
|
+
#
|
505
|
+
# ticker[key_postpromoter] = "#{pp_usd_steem} | #{pp_usd_sbd} | | "
|
506
|
+
# rescue => e
|
507
|
+
# puts e
|
508
|
+
# end
|
509
|
+
# end
|
510
|
+
|
511
|
+
threads << Thread.new do
|
512
|
+
begin
|
513
|
+
cg_steem = JSON[open('https://api.coingecko.com/api/v3/coins/steem').read]
|
514
|
+
cg_sbd = JSON[open('https://api.coingecko.com/api/v3/coins/steem-dollars').read]
|
515
|
+
cg_usd_steem = cg_steem.fetch('market_data').fetch('current_price').fetch('usd').to_f
|
516
|
+
cg_btc_steem = cg_steem.fetch('market_data').fetch('current_price').fetch('btc').to_f
|
517
|
+
cg_usd_sbd = cg_sbd.fetch('market_data').fetch('current_price').fetch('usd').to_f
|
518
|
+
cg_btc_sbd = cg_sbd.fetch('market_data').fetch('current_price').fetch('btc').to_f
|
519
|
+
cg_usd_steem = number_to_currency(cg_usd_steem, precision: 4).rjust(11)
|
520
|
+
cg_usd_sbd = number_to_currency(cg_usd_sbd, precision: 4).rjust(11)
|
521
|
+
cg_btc_steem = number_to_currency(cg_btc_steem, precision: 8, unit: '').rjust(11)
|
522
|
+
cg_btc_sbd = number_to_currency(cg_btc_sbd, precision: 8, unit: '').rjust(11)
|
523
|
+
|
524
|
+
ticker[key_coingecko] = "#{cg_usd_steem} | #{cg_usd_sbd} | #{cg_btc_steem} | #{cg_btc_sbd}"
|
525
|
+
rescue => e
|
526
|
+
puts e
|
527
|
+
end
|
528
|
+
end
|
529
|
+
|
530
|
+
threads << Thread.new do
|
531
|
+
begin
|
532
|
+
pol_usdt_btc = JSON[open("https://poloniex.com/public?command=returnOrderBook¤cyPair=USDT_BTC&depth=10").read]
|
533
|
+
pol_btc_steem = JSON[open("https://poloniex.com/public?command=returnOrderBook¤cyPair=BTC_STEEM&depth=10").read]
|
534
|
+
pol_usdt_btc = pol_usdt_btc['asks'].first.first.to_f
|
535
|
+
pol_btc_steem = pol_btc_steem['asks'].first.first.to_f
|
536
|
+
pol_usdt_steem = pol_usdt_btc * pol_btc_steem
|
537
|
+
pol_usdt_steem = number_to_currency(pol_usdt_steem, precision: 4).rjust(11)
|
538
|
+
pol_btc_steem = number_to_currency(pol_btc_steem, precision: 8, unit: '').rjust(11)
|
539
|
+
|
540
|
+
ticker[key_poloniex] = "#{pol_usdt_steem} | | #{pol_btc_steem} | "
|
541
|
+
rescue => e
|
542
|
+
puts e
|
543
|
+
end
|
544
|
+
end
|
545
|
+
|
546
|
+
# threads << Thread.new do
|
547
|
+
# begin
|
548
|
+
# # btc_history_data = steem_engine_contracts(:find, {
|
549
|
+
# # contract: 'market',
|
550
|
+
# # table: 'tradesHistory',
|
551
|
+
# # query: {
|
552
|
+
# # symbol: 'BTCP'
|
553
|
+
# # },
|
554
|
+
# # limit: 1,
|
555
|
+
# # offset: 0,
|
556
|
+
# # indexes: [{index: '_id', descending: true}]
|
557
|
+
# # })
|
558
|
+
#
|
559
|
+
# # se_prices = JSON[open('https://postpromoter.net/api/prices').read]
|
560
|
+
# # se_usd_steem = se_prices['steem_price']
|
561
|
+
# # # se_steem_usd = btc_history_data[0]['price'].to_f * se_usd_steem
|
562
|
+
# # # se_btc_steem = se_usd_steem / se_steem_usd
|
563
|
+
# # se_usd_steem = number_to_currency(se_usd_steem, precision: 4).rjust(11)
|
564
|
+
# # # se_btc_steem = number_to_currency(se_btc_steem, precision: 8, unit: '').rjust(11)
|
565
|
+
# #
|
566
|
+
# # ticker[key_steem_engine] = "#{se_usd_steem} | | | "
|
567
|
+
# rescue => e
|
568
|
+
# puts e
|
569
|
+
# end
|
570
|
+
# end
|
571
|
+
when :hive
|
572
|
+
key_ionomy = 'ionomy.com '
|
573
|
+
key_bittrex = 'bittrex.com '
|
574
|
+
key_binance = 'binance.com '
|
575
|
+
key_huobi = 'huobi.pro '
|
576
|
+
key_probit = 'probit.com '
|
577
|
+
key_blocktrades = 'blocktrades.us '
|
578
|
+
key_coingecko = 'coingecko.com '
|
579
|
+
# key_hive_engine = 'hive-engine.com '
|
580
|
+
ticker = {
|
581
|
+
key_ionomy => nil,
|
582
|
+
key_bittrex => nil,
|
583
|
+
key_binance => nil,
|
584
|
+
key_huobi => nil,
|
585
|
+
key_probit => nil,
|
586
|
+
key_blocktrades => nil,
|
587
|
+
key_coingecko => nil,
|
588
|
+
# key_hive_engine => nil
|
589
|
+
}
|
590
|
+
|
591
|
+
threads << Thread.new do
|
592
|
+
begin
|
593
|
+
_btx_market_data = btx_market_data
|
594
|
+
btx_usdt_hive, btx_usdt_hbd = _btx_market_data[:usdt_hive], _btx_market_data[:usdt_hbd]
|
595
|
+
btx_btc_hive, btx_btx_hbd = _btx_market_data[:btc_hive], _btx_market_data[:btc_hbd]
|
596
|
+
|
597
|
+
btx_usdt_hive = number_to_currency(btx_usdt_hive, precision: 4).rjust(10)
|
598
|
+
btx_usdt_hbd = number_to_currency(btx_usdt_hbd, precision: 4).rjust(10)
|
599
|
+
btx_btc_hive = number_to_currency(btx_btc_hive, precision: 8, unit: '').rjust(10)
|
600
|
+
btx_btx_hbd = number_to_currency(btx_btx_hbd, precision: 8, unit: '').rjust(10)
|
601
|
+
|
602
|
+
ticker[key_bittrex] = "#{btx_usdt_hive} | #{btx_usdt_hbd} | #{btx_btc_hive} | #{btx_btx_hbd}"
|
603
|
+
rescue => e
|
604
|
+
puts e
|
605
|
+
end
|
606
|
+
end
|
607
|
+
|
608
|
+
threads << Thread.new do
|
609
|
+
begin
|
610
|
+
bin_hive_usdt = JSON[open('https://api.binance.com/api/v1/ticker/price?symbol=HIVEUSDT').read].fetch('price').to_f
|
611
|
+
bin_hive_btc = JSON[open('https://api.binance.com/api/v1/ticker/price?symbol=HIVEBTC').read].fetch('price').to_f
|
612
|
+
bin_hive_usdt = number_to_currency(bin_hive_usdt, precision: 4).rjust(10)
|
613
|
+
bin_hive_btc = number_to_currency(bin_hive_btc, precision: 8, unit: '').rjust(10)
|
614
|
+
|
615
|
+
ticker[key_binance] = "#{bin_hive_usdt} | | #{bin_hive_btc} | "
|
616
|
+
rescue => e
|
617
|
+
puts e
|
618
|
+
end
|
619
|
+
end
|
620
|
+
|
621
|
+
threads << Thread.new do
|
622
|
+
begin
|
623
|
+
hub_hive_usdt = JSON[open('https://api.huobi.pro/market/detail/merged?symbol=hiveusdt').read].fetch('tick').fetch('close').to_f
|
624
|
+
hub_hive_btc = JSON[open('https://api.huobi.pro/market/detail/merged?symbol=hivebtc').read].fetch('tick').fetch('close').to_f
|
625
|
+
hub_hive_usdt = number_to_currency(hub_hive_usdt, precision: 4).rjust(10)
|
626
|
+
hub_hive_btc = number_to_currency(hub_hive_btc, precision: 8, unit: '').rjust(10)
|
627
|
+
|
628
|
+
ticker[key_huobi] = "#{hub_hive_usdt} | | #{hub_hive_btc} | "
|
629
|
+
rescue => e
|
630
|
+
puts e
|
631
|
+
end
|
632
|
+
end
|
633
|
+
|
634
|
+
threads << Thread.new do
|
635
|
+
begin
|
636
|
+
ionomy_market = JSON[open('https://ionomy.com/api/v1/public/markets-summaries').read].fetch('data')
|
637
|
+
in_btc_hive = ionomy_market.find{|m| m.fetch('market') == 'btc-hive'}.fetch('price').to_f
|
638
|
+
in_btc_hive = number_to_currency(in_btc_hive, precision: 8, unit: '').rjust(10)
|
639
|
+
|
640
|
+
ticker[key_ionomy] = " | | #{in_btc_hive} | "
|
641
|
+
rescue => e
|
642
|
+
puts e
|
643
|
+
end
|
644
|
+
end
|
645
|
+
|
646
|
+
threads << Thread.new do
|
647
|
+
begin
|
648
|
+
probit_market = JSON[open('https://api.probit.com/api/exchange/v1/ticker?market_ids=HIVE-USDT').read].fetch('data')
|
649
|
+
pb_usd_hive = probit_market.find{|m| m.fetch('market_id') == 'HIVE-USDT'}.fetch('last').to_f
|
650
|
+
pb_usd_hive = number_to_currency(pb_usd_hive, precision: 4).rjust(10)
|
651
|
+
|
652
|
+
ticker[key_probit] = "#{pb_usd_hive} | | | "
|
653
|
+
rescue => e
|
654
|
+
puts e
|
655
|
+
end
|
656
|
+
end
|
657
|
+
|
658
|
+
threads << Thread.new do
|
659
|
+
begin
|
660
|
+
# See: https://cryptofresh.com/a/TRADE.HIVE
|
661
|
+
hive_market = JSON[open('https://cryptofresh.com/api/asset/markets?asset=TRADE.HIVE').read]
|
662
|
+
# See: https://cryptofresh.com/a/TRADE.HBD
|
663
|
+
hbd_market = JSON[open('https://cryptofresh.com/api/asset/markets?asset=TRADE.HIVE').read]
|
664
|
+
btr_usd_hive = hive_market.fetch('TRADE.USDT', {}).fetch('price', '')
|
665
|
+
btr_usd_hbd = hbd_market.fetch('TRADE.USDT', {}).fetch('price', '')
|
666
|
+
btr_btc_hive = hive_market.fetch('TRADE.BTC', {}).fetch('price', '')
|
667
|
+
btr_btc_hbd = hbd_market.fetch('TRADE.BTC', {}).fetch('price', '')
|
668
|
+
|
669
|
+
btr_usd_hive = number_to_currency(btr_usd_hive, precision: 4).rjust(10)
|
670
|
+
btr_usd_hbd = number_to_currency(btr_usd_hbd, precision: 4).rjust(10)
|
671
|
+
btr_btc_hive = number_to_currency(btr_btc_hive, precision: 8, unit: '').rjust(10)
|
672
|
+
btr_btc_hbd = number_to_currency(btr_btc_hbd, precision: 8, unit: '').rjust(10)
|
673
|
+
|
674
|
+
if btr_usd_hive =~ /[0-9]+/ || btr_usd_hbd =~ /[0-9]+/ || btr_btc_hive =~ /[0-9]+/ || btr_btc_hbd =~ /[0-9]+/
|
675
|
+
ticker[key_blocktrades] = "#{btr_usd_hive} | #{btr_usd_hbd} | #{btr_btc_hive} | #{btr_btc_hbd}"
|
676
|
+
else
|
677
|
+
ticker.delete(key_blocktrades)
|
678
|
+
end
|
679
|
+
rescue => e
|
680
|
+
puts e
|
681
|
+
end
|
682
|
+
end
|
683
|
+
|
684
|
+
threads << Thread.new do
|
685
|
+
begin
|
686
|
+
cg_hive = JSON[open('https://api.coingecko.com/api/v3/coins/hive').read] rescue {}
|
687
|
+
cg_hbd = JSON[open('https://api.coingecko.com/api/v3/coins/hive_dollar').read] rescue {}
|
688
|
+
cg_usd_hive = cg_hive.fetch('market_data').fetch('current_price').fetch('usd').to_f rescue -1
|
689
|
+
cg_btc_hive = cg_hive.fetch('market_data').fetch('current_price').fetch('btc').to_f rescue -1
|
690
|
+
cg_usd_hbd = cg_hbd.fetch('market_data').fetch('current_price').fetch('usd').to_f rescue -1
|
691
|
+
cg_btc_hbd = cg_hbd.fetch('market_data').fetch('current_price').fetch('btc').to_f rescue -1
|
692
|
+
|
693
|
+
cg_usd_hive = if cg_usd_hive == -1
|
694
|
+
'N/A'
|
695
|
+
else
|
696
|
+
number_to_currency(cg_usd_hive, precision: 4)
|
697
|
+
end.rjust(10)
|
698
|
+
|
699
|
+
cg_usd_hbd = if cg_usd_hbd == -1
|
700
|
+
'N/A'
|
701
|
+
else
|
702
|
+
number_to_currency(cg_usd_hbd, precision: 4)
|
703
|
+
end.rjust(10)
|
704
|
+
|
705
|
+
cg_btc_hive = if cg_btc_hive == -1
|
706
|
+
'N/A'
|
707
|
+
else
|
708
|
+
number_to_currency(cg_btc_hive, precision: 8, unit: '')
|
709
|
+
end.rjust(10)
|
710
|
+
|
711
|
+
cg_btc_hbd = if cg_btc_hbd == -1
|
712
|
+
'N/A'
|
713
|
+
else
|
714
|
+
number_to_currency(cg_btc_hbd, precision: 8, unit: '')
|
715
|
+
end.rjust(10)
|
716
|
+
|
717
|
+
ticker[key_coingecko] = "#{cg_usd_hive} | #{cg_usd_hbd} | #{cg_btc_hive} | #{cg_btc_hbd}"
|
718
|
+
rescue => e
|
719
|
+
puts e
|
720
|
+
end
|
721
|
+
end
|
722
|
+
|
723
|
+
# threads << Thread.new do
|
724
|
+
# begin
|
725
|
+
# hive_history_data = hive_engine_contracts(:find, {
|
726
|
+
# contract: 'market',
|
727
|
+
# table: 'tradesHistory',
|
728
|
+
# query: {
|
729
|
+
# symbol: 'SWAP.HIVE'
|
730
|
+
# },
|
731
|
+
# limit: 1,
|
732
|
+
# offset: 0,
|
733
|
+
# indexes: [{index: '_id', descending: true}]
|
734
|
+
# })
|
735
|
+
#
|
736
|
+
# # btc_history_data = hive_engine_contracts(:find, {
|
737
|
+
# # contract: 'market',
|
738
|
+
# # table: 'tradesHistory',
|
739
|
+
# # query: {
|
740
|
+
# # symbol: 'SWAP.BTC'
|
741
|
+
# # },
|
742
|
+
# # limit: 1,
|
743
|
+
# # offset: 0,
|
744
|
+
# # indexes: [{index: '_id', descending: true}]
|
745
|
+
# # })
|
746
|
+
#
|
747
|
+
# cg_prices = JSON[open('https://api.coingecko.com/api/v3/simple/price?ids=HIVE&vs_currencies=USD').read]
|
748
|
+
# cg_usd_hive = cg_prices['hive']['usd']
|
749
|
+
# he_usd_hive = hive_history_data[0]['price'].to_f * cg_usd_hive
|
750
|
+
# # # se_hive_usd = btc_history_data[0]['price'].to_f * se_usd_hive
|
751
|
+
# # # se_btc_hive = se_usd_hive / se_hive_usd
|
752
|
+
# # se_usd_hive = number_to_currency(se_usd_hive, precision: 4).rjust(10)
|
753
|
+
# # # se_btc_hive = number_to_currency(se_btc_hive, precision: 8, unit: '').rjust(10)
|
754
|
+
# #
|
755
|
+
# ticker[key_steem_engine] = "#{he_usd_hive} | | | "
|
756
|
+
# rescue => e
|
757
|
+
# puts e
|
758
|
+
# end
|
759
|
+
# end
|
760
|
+
end
|
761
|
+
|
762
|
+
start_typing event
|
763
|
+
threads.each(&:join)
|
267
764
|
|
268
|
-
|
765
|
+
render_ticker(message, event, ticker, chain)
|
766
|
+
end
|
767
|
+
|
768
|
+
def promoted(chain = :hive, period = :today)
|
769
|
+
chain = chain.to_s.downcase.to_sym
|
770
|
+
|
771
|
+
promoted = case chain
|
772
|
+
# when :steem then SteemApi::Tx::Transfer.where(to: 'null', amount_symbol: 'SBD').send(period)
|
773
|
+
when :hive then HiveSQL::Tx::Transfer.where(to: 'null', amount_symbol: 'HBD').send(period)
|
774
|
+
else
|
775
|
+
return "Query not supported. No database for #{chain.to_s.capitalize}."
|
776
|
+
end
|
269
777
|
count_promoted = promoted.count
|
270
778
|
sum_promoted = promoted.sum(:amount)
|
271
779
|
|
@@ -283,20 +791,33 @@ module Cosgrove
|
|
283
791
|
"#{pluralize(count_promoted, 'post')} promoted #{period} totalling #{sum_promoted} (#{ratio} the size of reward pool)."
|
284
792
|
end
|
285
793
|
|
286
|
-
def supply(chain)
|
794
|
+
def supply(chain = :hive)
|
795
|
+
chain ||= :hive
|
796
|
+
chain = chain.to_s.downcase.to_sym
|
287
797
|
base_per_mvest, base_per_debt = price_feed(chain)
|
288
798
|
properties = api(chain).get_dynamic_global_properties do |_properties, error|
|
289
799
|
_properties
|
290
800
|
end
|
291
801
|
|
292
802
|
current_supply = properties.current_supply.split(' ').first.to_f
|
293
|
-
current_debt_supply = properties.current_sbd_supply.split(' ').first.to_f
|
294
|
-
total_vesting_fund_steem = properties.total_vesting_fund_steem.split(' ').first.to_f
|
295
803
|
virtual_supply = properties.virtual_supply.split(' ').first.to_f
|
296
804
|
debt_steem = virtual_supply - current_supply
|
297
805
|
total_base = (current_supply / base_per_mvest) * base_per_debt
|
298
806
|
ratio = (debt_steem / virtual_supply) * 100
|
299
807
|
|
808
|
+
current_debt_supply, total_vesting_fund_base = case chain
|
809
|
+
when :steem
|
810
|
+
[
|
811
|
+
properties.current_sbd_supply.split(' ').first.to_f,
|
812
|
+
properties.total_vesting_fund_steem.split(' ').first.to_f
|
813
|
+
]
|
814
|
+
when :hive
|
815
|
+
[
|
816
|
+
properties.current_hbd_supply.split(' ').first.to_f,
|
817
|
+
properties.total_vesting_fund_hive.split(' ').first.to_f
|
818
|
+
]
|
819
|
+
end
|
820
|
+
|
300
821
|
supply = []
|
301
822
|
case chain
|
302
823
|
when :steem
|
@@ -304,7 +825,7 @@ module Cosgrove
|
|
304
825
|
reward_fund.reward_balance.split(' ').first.to_f
|
305
826
|
end
|
306
827
|
|
307
|
-
liquid_supply = current_supply - reward_balance -
|
828
|
+
liquid_supply = current_supply - reward_balance - total_vesting_fund_base
|
308
829
|
ratio_liquid = (liquid_supply / current_supply) * 100
|
309
830
|
|
310
831
|
current_supply = number_with_precision(current_supply, precision: 0, delimiter: ',', separator: '.')
|
@@ -321,7 +842,7 @@ module Cosgrove
|
|
321
842
|
reward_balance = properties.total_reward_fund_steem
|
322
843
|
reward_balance = reward_balance.split(' ').first.to_f
|
323
844
|
|
324
|
-
liquid_supply = current_supply - reward_balance -
|
845
|
+
liquid_supply = current_supply - reward_balance - total_vesting_fund_base
|
325
846
|
ratio_liquid = (liquid_supply / current_supply) * 100
|
326
847
|
|
327
848
|
current_supply = number_with_precision(current_supply, precision: 0, delimiter: ',', separator: '.')
|
@@ -338,7 +859,7 @@ module Cosgrove
|
|
338
859
|
reward_balance = properties.total_reward_fund_steem
|
339
860
|
reward_balance = reward_balance.split(' ').first.to_f
|
340
861
|
|
341
|
-
liquid_supply = current_supply - reward_balance -
|
862
|
+
liquid_supply = current_supply - reward_balance - total_vesting_fund_base
|
342
863
|
ratio_liquid = (liquid_supply / current_supply) * 100
|
343
864
|
|
344
865
|
current_supply = number_with_precision(current_supply, precision: 0, delimiter: ',', separator: '.')
|
@@ -351,23 +872,44 @@ module Cosgrove
|
|
351
872
|
supply << ["#{current_supply} CORE (Worth #{total_base} TBD)"]
|
352
873
|
supply << ["#{current_debt_supply} TBD (#{ratio} of supply)"]
|
353
874
|
supply << ["#{liquid_supply} Liquid CORE (#{ratio_liquid} of supply)"]
|
875
|
+
when :hive
|
876
|
+
reward_balance = api(chain).get_reward_fund('post') do |reward_fund|
|
877
|
+
reward_fund.reward_balance.split(' ').first.to_f
|
878
|
+
end
|
879
|
+
|
880
|
+
liquid_supply = current_supply - reward_balance - total_vesting_fund_base
|
881
|
+
ratio_liquid = (liquid_supply / current_supply) * 100
|
882
|
+
|
883
|
+
current_supply = number_with_precision(current_supply, precision: 0, delimiter: ',', separator: '.')
|
884
|
+
ratio = number_to_percentage(ratio, precision: 3)
|
885
|
+
total_base = number_to_currency(total_base, precision: 0)
|
886
|
+
current_debt_supply = number_to_currency(current_debt_supply, precision: 0)
|
887
|
+
liquid_supply = number_with_precision(liquid_supply, precision: 0, delimiter: ',', separator: '.')
|
888
|
+
ratio_liquid = number_to_percentage(ratio_liquid, precision: 3)
|
889
|
+
|
890
|
+
supply << ["#{current_supply} HIVE (Worth #{total_base} HBD)"]
|
891
|
+
supply << ["#{current_debt_supply} HBD (#{ratio} of supply)"]
|
892
|
+
supply << ["#{liquid_supply} Liquid HIVE (#{ratio_liquid} of supply)"]
|
354
893
|
end
|
355
894
|
|
356
895
|
"Supply: `" + supply.join('; ') + "`"
|
357
896
|
end
|
358
897
|
|
359
898
|
def mvests_sum(options = {})
|
360
|
-
chain = options[:chain] || :
|
899
|
+
chain = options[:chain] || :hive
|
900
|
+
chain = chain.to_s.downcase.to_sym
|
361
901
|
account_names = options[:account_names]
|
362
902
|
case chain
|
363
|
-
when :steem then SteemApi::Account.where(name: account_names).sum("TRY_PARSE(REPLACE(vesting_shares, ' VESTS', '') AS float)")
|
903
|
+
# when :steem then SteemApi::Account.where(name: account_names).sum("TRY_PARSE(REPLACE(vesting_shares, ' VESTS', '') AS float)")
|
364
904
|
when :golos then "Query not supported. No database for Golos."
|
365
905
|
when :test then "Query not supported. No database for Testnet."
|
906
|
+
when :hive then HiveSQL::Account.where(name: account_names).sum("TRY_PARSE(REPLACE(vesting_shares, ' VESTS', '') AS float)")
|
366
907
|
end
|
367
908
|
end
|
368
909
|
|
369
|
-
def debt_exchange_rate(chain = :
|
370
|
-
chain
|
910
|
+
def debt_exchange_rate(chain = :hive, limit = 19)
|
911
|
+
chain ||= :hive
|
912
|
+
chain = chain.to_s.downcase.to_sym
|
371
913
|
rates = api(chain).get_witnesses_by_vote('', limit) do |witnesses|
|
372
914
|
witnesses.map(&:sbd_exchange_rate)
|
373
915
|
end
|
@@ -375,6 +917,7 @@ module Cosgrove
|
|
375
917
|
symbol = case chain
|
376
918
|
when :steem then 'SBD'
|
377
919
|
when :golos then 'GBG'
|
920
|
+
when :hive then 'HBD'
|
378
921
|
end
|
379
922
|
|
380
923
|
ratio = rates.map do |r|
|
@@ -390,8 +933,9 @@ module Cosgrove
|
|
390
933
|
"#{price} #{symbol}"
|
391
934
|
end
|
392
935
|
|
393
|
-
def apr(chain = :
|
394
|
-
chain
|
936
|
+
def apr(chain = :hive, limit = 20)
|
937
|
+
chain ||= :hive
|
938
|
+
chain = chain.to_s.downcase.to_sym
|
395
939
|
rates = api(chain).get_witnesses_by_vote('', limit) do |witnesses|
|
396
940
|
witnesses.map(&:props).map { |p| p['sbd_interest_rate'] }
|
397
941
|
end
|
@@ -401,8 +945,9 @@ module Cosgrove
|
|
401
945
|
number_to_percentage(rate, precision: 3)
|
402
946
|
end
|
403
947
|
|
404
|
-
def effective_apr(chain = :
|
405
|
-
chain
|
948
|
+
def effective_apr(chain = :hive)
|
949
|
+
chain ||= :hive
|
950
|
+
chain = chain.to_s.downcase.to_sym
|
406
951
|
rate = api(chain).get_dynamic_global_properties do |properties|
|
407
952
|
properties.sbd_interest_rate
|
408
953
|
end
|
@@ -411,8 +956,9 @@ module Cosgrove
|
|
411
956
|
number_to_percentage(rate, precision: 3)
|
412
957
|
end
|
413
958
|
|
414
|
-
def effective_price(chain = :
|
415
|
-
chain
|
959
|
+
def effective_price(chain = :hive)
|
960
|
+
chain ||= :hive
|
961
|
+
chain = chain.to_s.downcase.to_sym
|
416
962
|
current_median_history = api(chain).get_feed_history do |feed_history|
|
417
963
|
feed_history.current_median_history
|
418
964
|
end
|
@@ -423,6 +969,7 @@ module Cosgrove
|
|
423
969
|
symbol = case chain
|
424
970
|
when :steem then 'SBD'
|
425
971
|
when :golos then 'GBG'
|
972
|
+
when :hive then 'HBD'
|
426
973
|
end
|
427
974
|
|
428
975
|
price = b / q
|