cosgrove 0.0.4.0pre1 → 0.0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,47 @@
1
+ module Cosgrove
2
+ class FindCommunitiesJob
3
+ def perform(event, args, limit = 1000, chain = :hive)
4
+ chain = chain.to_s.downcase.to_sym
5
+ terms = args.map{|term| "%#{term.downcase.strip}%"}
6
+
7
+ all_communities = case chain
8
+ # when :steem then SteemApi::Tx::Custom::Community.where('id >= 217640816').op('updateProps').order(id: :desc).limit(limit)
9
+ when :hive then HiveSQL::Tx::Custom::Community.where('id >= 217640816').op('updateProps').order(id: :desc).limit(limit)
10
+ end
11
+
12
+ all_communities = all_communities.select("*, (SELECT [Accounts].[recovery_account] FROM [Accounts] WHERE [Accounts].[name] = JSON_VALUE([TxCustoms].[json_metadata], '$[1].community')) AS community_owner")
13
+
14
+ communities = all_communities.all
15
+
16
+ terms.each do |term|
17
+ communities = communities.where("LOWER([TxCustoms].[json_metadata]) LIKE ? OR required_posting_auth LIKE ? OR (SELECT [Accounts].[recovery_account] FROM [Accounts] WHERE [Accounts].[name] = JSON_VALUE([TxCustoms].[json_metadata], '$[1].community')) = ?", term, term, term)
18
+ end
19
+
20
+ event.channel.start_typing if !!event
21
+
22
+ if communities.none?
23
+ msg = "Unable to find communities with: `#{args.join(' ')}`"
24
+
25
+ guess_communities = all_communities.all
26
+
27
+ terms.each do |term|
28
+ pattern = term.chars.each.map{ |c| c }.join('%')
29
+ pattern = pattern.gsub('%%', '%')
30
+ guess_communities = guess_communities.where("LOWER(JSON_VALUE([TxCustoms].[json_metadata], '$[1].props.title')) LIKE ?", pattern)
31
+ end
32
+
33
+ if guess_communities.any? && !!(guess = guess_communities.sample.payload['props']['title'] rescue nil)
34
+ msg += "\nDid you mean: #{guess}"
35
+ end
36
+
37
+ if !!event
38
+ event << msg
39
+ end
40
+
41
+ return []
42
+ end
43
+
44
+ communities
45
+ end
46
+ end
47
+ end
@@ -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 = :steem)
7
+ def base_per_mvest(chain = :hive)
7
8
  api(chain).get_dynamic_global_properties do |properties|
8
- total_vesting_fund_steem = properties.total_vesting_fund_steem.to_f
9
- total_vesting_shares_mvest = properties.total_vesting_shares.to_f / 1e6
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
- total_vesting_fund_steem / total_vesting_shares_mvest
18
+ total_vesting_fund_base / total_vesting_shares_mvest
12
19
  end
13
20
  end
14
21
 
15
- def price_feed(chain = :steem)
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&currencyPair=BTC_STEEM&depth=10").read]
45
- pol_btc_sbd = JSON[open("https://poloniex.com/public?command=returnOrderBook&currencyPair=BTC_SBD&depth=10").read]
46
52
  pol_usdt_btc = JSON[open("https://poloniex.com/public?command=returnOrderBook&currencyPair=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, pol_usdt_sbd, btx_usdt_golos, btx_usdt_gbg, btx_usdt_steem, btx_usdt_sbd]
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 = :steem, account_names = [])
82
- pol_usdt_steem, _pol_usdt_sbd, btx_usdt_golos, _btx_usdt_gbg, btx_usdt_steem, btx_usdt_sbd = market_data
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 = base_per_mvest * btx_usdt_steem
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(:steem).get_accounts([account.name]) do |accounts|
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
- steem = base_per_mvest * mvests
162
- sbd = base_per_debt * mvests
163
- btx_sbd = base_per_mvest * mvests * btx_usdt_steem
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
- steem = number_with_precision(steem, precision: 3, delimiter: ',', separator: '.')
169
- sbd = number_to_currency(sbd, precision: 3)
170
- btx_sbd = number_to_currency(btx_sbd, precision: 3)
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 = #{steem} STEEM = #{sbd} = #{btx_sbd} on Bittrex"]
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 = #{steem} STEEM = #{sbd} = #{btx_sbd} on Bittrex"]
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 = :steem)
213
- pol_usdt_steem, _pol_usdt_sbd, btx_usdt_golos, _btx_usdt_gbg, btx_usdt_steem, btx_usdt_sbd = market_data
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
- pol_usdt_steem, pol_usdt_sbd, btx_usdt_golos, btx_usdt_gbg, btx_usdt_steem, btx_usdt_sbd = market_data
250
-
251
- pol_usdt_steem = number_to_currency(pol_usdt_steem, precision: 4)
252
- pol_usdt_sbd = number_to_currency(pol_usdt_sbd, precision: 4)
253
- btx_usdt_steem = number_to_currency(btx_usdt_steem, precision: 4)
254
- btx_usdt_sbd = number_to_currency(btx_usdt_sbd, precision: 4)
255
- btx_usdt_golos = number_to_currency(btx_usdt_golos, precision: 4)
256
- btx_usdt_gbg = number_to_currency(btx_usdt_gbg, precision: 4)
257
-
258
- ticker = []
259
- ticker << "`Poloniex: USD/STEEM: #{pol_usdt_steem}; USD/SBD: #{pol_usdt_sbd}`"
260
- ticker << "`Bittrex: USD/STEEM: #{btx_usdt_steem}; USD/SBD: #{btx_usdt_sbd}`"
261
- ticker << "`Bittrex: USD/GOLOS: #{btx_usdt_golos}; USD/GBG: #{btx_usdt_gbg}`"
262
- ticker.join("\n")
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 promoted(chain = :steem, period = :today)
266
- return "Query not supported. No database for #{chain.to_s.capitalize}." unless chain == :steem
409
+ def ticker(event = nil, chain = :hive)
410
+ chain = chain.to_s.downcase.to_sym
411
+ message = nil
412
+ threads = []
267
413
 
268
- promoted = SteemApi::Tx::Transfer.where(to: 'null', amount_symbol: 'SBD').send(period)
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&currencyPair=USDT_BTC&depth=10").read]
533
+ pol_btc_steem = JSON[open("https://poloniex.com/public?command=returnOrderBook&currencyPair=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)
764
+
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,17 +791,32 @@ 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
803
+ virtual_supply = properties.virtual_supply.split(' ').first.to_f
804
+ debt_steem = virtual_supply - current_supply
295
805
  total_base = (current_supply / base_per_mvest) * base_per_debt
296
- ratio = (current_debt_supply / total_base) * 100
806
+ ratio = (debt_steem / virtual_supply) * 100
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
297
820
 
298
821
  supply = []
299
822
  case chain
@@ -302,7 +825,7 @@ module Cosgrove
302
825
  reward_fund.reward_balance.split(' ').first.to_f
303
826
  end
304
827
 
305
- liquid_supply = current_supply - reward_balance - total_vesting_fund_steem
828
+ liquid_supply = current_supply - reward_balance - total_vesting_fund_base
306
829
  ratio_liquid = (liquid_supply / current_supply) * 100
307
830
 
308
831
  current_supply = number_with_precision(current_supply, precision: 0, delimiter: ',', separator: '.')
@@ -319,7 +842,7 @@ module Cosgrove
319
842
  reward_balance = properties.total_reward_fund_steem
320
843
  reward_balance = reward_balance.split(' ').first.to_f
321
844
 
322
- liquid_supply = current_supply - reward_balance - total_vesting_fund_steem
845
+ liquid_supply = current_supply - reward_balance - total_vesting_fund_base
323
846
  ratio_liquid = (liquid_supply / current_supply) * 100
324
847
 
325
848
  current_supply = number_with_precision(current_supply, precision: 0, delimiter: ',', separator: '.')
@@ -336,7 +859,7 @@ module Cosgrove
336
859
  reward_balance = properties.total_reward_fund_steem
337
860
  reward_balance = reward_balance.split(' ').first.to_f
338
861
 
339
- liquid_supply = current_supply - reward_balance - total_vesting_fund_steem
862
+ liquid_supply = current_supply - reward_balance - total_vesting_fund_base
340
863
  ratio_liquid = (liquid_supply / current_supply) * 100
341
864
 
342
865
  current_supply = number_with_precision(current_supply, precision: 0, delimiter: ',', separator: '.')
@@ -349,23 +872,44 @@ module Cosgrove
349
872
  supply << ["#{current_supply} CORE (Worth #{total_base} TBD)"]
350
873
  supply << ["#{current_debt_supply} TBD (#{ratio} of supply)"]
351
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)"]
352
893
  end
353
894
 
354
895
  "Supply: `" + supply.join('; ') + "`"
355
896
  end
356
897
 
357
898
  def mvests_sum(options = {})
358
- chain = options[:chain] || :steem
899
+ chain = options[:chain] || :hive
900
+ chain = chain.to_s.downcase.to_sym
359
901
  account_names = options[:account_names]
360
902
  case chain
361
- 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)")
362
904
  when :golos then "Query not supported. No database for Golos."
363
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)")
364
907
  end
365
908
  end
366
909
 
367
- def debt_exchange_rate(chain = :steem, limit = 19)
368
- chain = chain.to_sym
910
+ def debt_exchange_rate(chain = :hive, limit = 19)
911
+ chain ||= :hive
912
+ chain = chain.to_s.downcase.to_sym
369
913
  rates = api(chain).get_witnesses_by_vote('', limit) do |witnesses|
370
914
  witnesses.map(&:sbd_exchange_rate)
371
915
  end
@@ -373,6 +917,7 @@ module Cosgrove
373
917
  symbol = case chain
374
918
  when :steem then 'SBD'
375
919
  when :golos then 'GBG'
920
+ when :hive then 'HBD'
376
921
  end
377
922
 
378
923
  ratio = rates.map do |r|
@@ -388,8 +933,9 @@ module Cosgrove
388
933
  "#{price} #{symbol}"
389
934
  end
390
935
 
391
- def apr(chain = :steem, limit = 19)
392
- chain = chain.to_sym
936
+ def apr(chain = :hive, limit = 20)
937
+ chain ||= :hive
938
+ chain = chain.to_s.downcase.to_sym
393
939
  rates = api(chain).get_witnesses_by_vote('', limit) do |witnesses|
394
940
  witnesses.map(&:props).map { |p| p['sbd_interest_rate'] }
395
941
  end
@@ -399,8 +945,9 @@ module Cosgrove
399
945
  number_to_percentage(rate, precision: 3)
400
946
  end
401
947
 
402
- def effective_apr(chain = :steem)
403
- chain = chain.to_sym
948
+ def effective_apr(chain = :hive)
949
+ chain ||= :hive
950
+ chain = chain.to_s.downcase.to_sym
404
951
  rate = api(chain).get_dynamic_global_properties do |properties|
405
952
  properties.sbd_interest_rate
406
953
  end
@@ -409,8 +956,9 @@ module Cosgrove
409
956
  number_to_percentage(rate, precision: 3)
410
957
  end
411
958
 
412
- def effective_price(chain = :steem)
413
- chain = chain.to_sym
959
+ def effective_price(chain = :hive)
960
+ chain ||= :hive
961
+ chain = chain.to_s.downcase.to_sym
414
962
  current_median_history = api(chain).get_feed_history do |feed_history|
415
963
  feed_history.current_median_history
416
964
  end
@@ -421,6 +969,7 @@ module Cosgrove
421
969
  symbol = case chain
422
970
  when :steem then 'SBD'
423
971
  when :golos then 'GBG'
972
+ when :hive then 'HBD'
424
973
  end
425
974
 
426
975
  price = b / q