cosgrove 0.0.3.5 → 0.0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,19 +1,33 @@
1
1
  module Cosgrove
2
2
  module Market
3
3
  include Support
4
+ include Utils
4
5
  include ActionView::Helpers::NumberHelper
5
-
6
- def price_feed(chain = :steem)
6
+
7
+ def base_per_mvest(chain = :hive)
8
+ api(chain).get_dynamic_global_properties do |properties|
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
17
+
18
+ total_vesting_fund_base / total_vesting_shares_mvest
19
+ end
20
+ end
21
+
22
+ def price_feed(chain = :hive)
7
23
  api(chain).get_feed_history do |feed_history|
8
- base_per_mvest = api(chain).steem_per_mvest
9
-
10
24
  current_median_history = feed_history.current_median_history
11
25
  base = current_median_history.base
12
26
  base = base.split(' ').first.to_f
13
27
  quote = current_median_history.quote
14
28
  quote = quote.split(' ').first.to_f
15
29
 
16
- base_per_debt = (base / quote) * base_per_mvest
30
+ base_per_debt = (base / quote) * base_per_mvest(chain)
17
31
 
18
32
  [base_per_mvest, base_per_debt]
19
33
  end
@@ -35,29 +49,17 @@ module Cosgrove
35
49
 
36
50
  def market_data
37
51
  pol_btc_steem = JSON[open("https://poloniex.com/public?command=returnOrderBook&currencyPair=BTC_STEEM&depth=10").read]
38
- pol_btc_sbd = JSON[open("https://poloniex.com/public?command=returnOrderBook&currencyPair=BTC_SBD&depth=10").read]
39
52
  pol_usdt_btc = JSON[open("https://poloniex.com/public?command=returnOrderBook&currencyPair=USDT_BTC&depth=10").read]
40
53
 
41
54
  pol_btc_steem = pol_btc_steem['asks'].first.first.to_f
42
- pol_btc_sbd = pol_btc_sbd['asks'].first.first.to_f
43
55
  pol_usdt_btc = pol_usdt_btc['asks'].first.first.to_f
44
56
 
45
- pol_usdt_sbd = pol_usdt_btc * pol_btc_sbd
46
57
  pol_usdt_steem = pol_usdt_btc * pol_btc_steem
47
- # pol_sbd_steem = pol_usdt_sbd * ( pol_usdt_btc * pol_btc_steem )
48
58
 
49
- btx_btc_golos = JSON[open("https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-golos").read]
50
- btx_btc_gbg = JSON[open("https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-gbg").read]
51
59
  btx_usdt_btc = JSON[open("https://bittrex.com/api/v1.1/public/getmarketsummary?market=usdt-btc").read]
52
60
 
53
- btx_btc_golos = btx_btc_golos['result'].first['Ask'].to_f
54
- btx_btc_gbg = btx_btc_gbg['result'].first['Ask'].to_f
55
61
  btx_usdt_btc = btx_usdt_btc['result'].first['Ask'].to_f
56
62
 
57
- btx_usdt_gbg = btx_usdt_btc * btx_btc_gbg
58
- btx_usdt_golos = btx_usdt_btc * btx_btc_golos
59
- # btx_gbg_golos = btx_usdt_gbg * ( btx_usdt_btc * btx_btc_golos )
60
-
61
63
  btx_btc_steem = JSON[open("https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-steem").read]
62
64
  btx_btc_sbd = JSON[open("https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-sbd").read]
63
65
 
@@ -66,22 +68,63 @@ module Cosgrove
66
68
 
67
69
  btx_usdt_sbd = btx_usdt_btc * btx_btc_sbd
68
70
  btx_usdt_steem = btx_usdt_btc * btx_btc_steem
69
- # btx_sbd = btx_usdt_sbd * ( btx_usdt_btc * btx_btc_steem )
70
71
 
71
- [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
+ }
72
109
  end
73
110
 
74
- def mvests(chain = :steem, account_names = [])
75
- 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]
76
116
  base_per_mvest, base_per_debt = price_feed(chain)
77
117
 
78
118
  if account_names.none?
79
- 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
80
123
  btx_base_per_dept_as_usdt = number_to_currency(btx_base_per_dept_as_usdt, precision: 3)
81
124
 
82
125
  base_per_mvest = number_with_precision(base_per_mvest, precision: 3, delimiter: ',', separator: '.')
83
126
 
84
- base_per_debt = if chain == :steem
127
+ base_per_debt = if chain == :steem || chain == :hive
85
128
  number_to_currency(base_per_debt, precision: 3)
86
129
  else
87
130
  _btc_gld, usdt_gld_per_milli = gold_price
@@ -96,6 +139,7 @@ module Cosgrove
96
139
  when :steem then "`1 MV = 1M VESTS = #{base_per_mvest} STEEM = #{base_per_debt} = #{btx_base_per_dept_as_usdt} on Bittrex`"
97
140
  when :golos then "`1 MG = 1M GESTS = #{base_per_mvest} GOLOS = #{base_per_debt} GBG = #{base_per_debt_as_usdt}`"
98
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`"
99
143
  end
100
144
  end
101
145
 
@@ -125,24 +169,108 @@ module Cosgrove
125
169
  end
126
170
 
127
171
  account_names = account_names.map(&:downcase).uniq
128
- accounts = SteemData::Account.where(:name.in => account_names)
129
- account = accounts.last
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
130
227
 
131
- if accounts.size == 0
132
- accounts = SteemApi::Account.where(name: account_names)
133
- account = accounts.limit(1).last
228
+ api(:golos).get_accounts(account_names) do |accounts, error|
229
+ account = accounts.first
230
+ gests = account.vesting_shares.split(' ').first.to_f
134
231
  end
135
232
 
136
- if accounts.count == account_names.size
137
- if accounts.kind_of? Mongoid::Criteria
138
- vests = accounts.sum('vesting_shares.amount')
139
- delegated_vests = accounts.sum('delegated_vesting_shares.amount')
140
- received_vests = accounts.sum('received_vesting_shares.amount')
141
- else
142
- vests = accounts.pluck(:vesting_shares).map(&:to_f).sum
143
- delegated_vests = accounts.pluck(:delegated_vesting_shares).map(&:to_f).sum
144
- received_vests = accounts.pluck(:received_vesting_shares).map(&:to_f).sum
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
145
263
  end
264
+ end
265
+
266
+ account_names = account_names.map(&:downcase).uniq
267
+ accounts = HiveSQL::Account.where(name: account_names)
268
+ account = accounts.limit(1).first
269
+
270
+ if accounts.count == account_names.size
271
+ vests = accounts.pluck(:vesting_shares).map(&:to_f).sum
272
+ delegated_vests = accounts.pluck(:delegated_vesting_shares).map(&:to_f).sum
273
+ received_vests = accounts.pluck(:received_vesting_shares).map(&:to_f).sum
146
274
  elsif !wildcards
147
275
  valid_names = accounts.distinct(:name)
148
276
  unknown_names = account_names - valid_names
@@ -152,7 +280,7 @@ module Cosgrove
152
280
  if accounts.count == 1 && vests == 0.0
153
281
  # Falling back to RPC because balance is out of date and we only want
154
282
  # a single account.
155
- api(:steem).get_accounts([account.name]) do |accounts|
283
+ api(chain).get_accounts([account.name]) do |accounts|
156
284
  account = accounts.first
157
285
  vests = account.vesting_shares.split(' ').first.to_f
158
286
  delegated_vests = account.delegated_vesting_shares.split(' ').first.to_f
@@ -162,59 +290,41 @@ module Cosgrove
162
290
 
163
291
  mvests = vests / 1000000
164
292
  delegated_vests = (received_vests - delegated_vests) / 1000000
165
- steem = base_per_mvest * mvests
166
- sbd = base_per_debt * mvests
167
- 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
168
296
 
169
297
  mvests = number_with_precision(mvests, precision: 3, delimiter: ',', separator: '.')
170
298
  delegated_sign = delegated_vests >= 0.0 ? '+' : '-'
171
299
  delegated_vests = number_with_precision(delegated_vests.abs, precision: 3, delimiter: ',', separator: '.')
172
- steem = number_with_precision(steem, precision: 3, delimiter: ',', separator: '.')
173
- sbd = number_to_currency(sbd, precision: 3)
174
- 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)
175
303
 
176
304
  if accounts.size == 1
177
- balance = ["#{mvests} MVESTS = #{steem} STEEM = #{sbd} = #{btx_sbd} on Bittrex"]
305
+ balance = ["#{mvests} MVESTS = #{hive} HIVE = #{hbd} = #{btx_hbd} on Bittrex"]
178
306
  unless delegated_vests == '0.000'
179
307
  balance << "(#{delegated_sign}#{delegated_vests} MVESTS delegated)"
180
308
  end
181
309
 
182
310
  "**#{account.name}:** `#{balance.join(' ')}`"
183
311
  else
184
- balance = ["#{mvests} MVESTS = #{steem} STEEM = #{sbd} = #{btx_sbd} on Bittrex"]
312
+ balance = ["#{mvests} MVESTS = #{hive} HIVE = #{hbd} = #{btx_hbd} on Bittrex"]
185
313
  unless delegated_vests == '0.000'
186
314
  balance << "(#{delegated_sign}#{delegated_vests} MVESTS delegated)"
187
315
  end
188
316
 
189
317
  "**#{pluralize(accounts.count, 'account')}:** `#{balance.join(' ')}`"
190
318
  end
191
- when :golos
192
- account = nil
193
- gests = nil
194
-
195
- api(:golos).get_accounts(account_names) do |accounts, error|
196
- account = accounts.first
197
- gests = account.vesting_shares.split(' ').first.to_f
198
- end
199
-
200
- mgests = gests / 1000000
201
- golos = base_per_mvest * mgests
202
- gbg = base_per_debt * mgests
203
- _btc_gld, usdt_gld_per_milli = gold_price
204
- usd = gbg * usdt_gld_per_milli
205
-
206
- mgests = number_with_precision(mgests, precision: 3, delimiter: ',', separator: '.')
207
- golos = number_with_precision(golos, precision: 3, delimiter: ',', separator: '.')
208
- gbg = number_with_precision(gbg, precision: 3, delimiter: ',', separator: '.')
209
- usd = number_to_currency(usd, precision: 3)
210
-
211
- "**#{account.name}:** `#{mgests} MGESTS = #{golos} GOLOS = #{gbg} GBG = #{usd}`"
212
- when :test then "Query not supported. No Mongo for Testnet."
319
+ when :test then "Query not supported. No database for Testnet."
213
320
  end
214
321
  end
215
322
 
216
- def rewardpool(chain = :steem)
217
- 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]
218
328
  base_per_mvest, base_per_debt = price_feed(chain)
219
329
 
220
330
  case chain
@@ -246,32 +356,426 @@ module Cosgrove
246
356
  "Total Reward Fund: `#{total} GOLOS (Worth: #{total_gbg} GBG internally; #{btx_total_usd} on Bittrex)`"
247
357
  when :test
248
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)`"
249
372
  end
250
373
  end
251
374
 
252
- def ticker
253
- pol_usdt_steem, pol_usdt_sbd, btx_usdt_golos, btx_usdt_gbg, btx_usdt_steem, btx_usdt_sbd = market_data
254
-
255
- pol_usdt_steem = number_to_currency(pol_usdt_steem, precision: 4)
256
- pol_usdt_sbd = number_to_currency(pol_usdt_sbd, precision: 4)
257
- btx_usdt_steem = number_to_currency(btx_usdt_steem, precision: 4)
258
- btx_usdt_sbd = number_to_currency(btx_usdt_sbd, precision: 4)
259
- btx_usdt_golos = number_to_currency(btx_usdt_golos, precision: 4)
260
- btx_usdt_gbg = number_to_currency(btx_usdt_gbg, precision: 4)
261
-
262
- ticker = []
263
- ticker << "`Poloniex: USD/STEEM: #{pol_usdt_steem}; USD/SBD: #{pol_usdt_sbd}`"
264
- ticker << "`Bittrex: USD/STEEM: #{btx_usdt_steem}; USD/SBD: #{btx_usdt_sbd}`"
265
- ticker << "`Bittrex: USD/GOLOS: #{btx_usdt_golos}; USD/GBG: #{btx_usdt_gbg}`"
266
- 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
267
407
  end
268
408
 
269
- def promoted(chain = :steem, period = :today)
270
- return "Query not supported. No Mongo 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 = []
271
413
 
272
- promoted = SteemData::AccountOperation.type('transfer').where(account: 'null', to: 'null', 'amount.asset' => '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
273
777
  count_promoted = promoted.count
274
- sum_promoted = promoted.sum('amount.amount')
778
+ sum_promoted = promoted.sum(:amount)
275
779
 
276
780
  base_per_mvest, base_per_debt = price_feed(chain)
277
781
  total = api(chain).get_reward_fund('post') do |reward_fund|
@@ -287,17 +791,32 @@ module Cosgrove
287
791
  "#{pluralize(count_promoted, 'post')} promoted #{period} totalling #{sum_promoted} (#{ratio} the size of reward pool)."
288
792
  end
289
793
 
290
- def supply(chain)
794
+ def supply(chain = :hive)
795
+ chain ||= :hive
796
+ chain = chain.to_s.downcase.to_sym
291
797
  base_per_mvest, base_per_debt = price_feed(chain)
292
798
  properties = api(chain).get_dynamic_global_properties do |_properties, error|
293
799
  _properties
294
800
  end
295
801
 
296
802
  current_supply = properties.current_supply.split(' ').first.to_f
297
- current_debt_supply = properties.current_sbd_supply.split(' ').first.to_f
298
- 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
299
805
  total_base = (current_supply / base_per_mvest) * base_per_debt
300
- 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
301
820
 
302
821
  supply = []
303
822
  case chain
@@ -306,7 +825,7 @@ module Cosgrove
306
825
  reward_fund.reward_balance.split(' ').first.to_f
307
826
  end
308
827
 
309
- liquid_supply = current_supply - reward_balance - total_vesting_fund_steem
828
+ liquid_supply = current_supply - reward_balance - total_vesting_fund_base
310
829
  ratio_liquid = (liquid_supply / current_supply) * 100
311
830
 
312
831
  current_supply = number_with_precision(current_supply, precision: 0, delimiter: ',', separator: '.')
@@ -323,7 +842,7 @@ module Cosgrove
323
842
  reward_balance = properties.total_reward_fund_steem
324
843
  reward_balance = reward_balance.split(' ').first.to_f
325
844
 
326
- liquid_supply = current_supply - reward_balance - total_vesting_fund_steem
845
+ liquid_supply = current_supply - reward_balance - total_vesting_fund_base
327
846
  ratio_liquid = (liquid_supply / current_supply) * 100
328
847
 
329
848
  current_supply = number_with_precision(current_supply, precision: 0, delimiter: ',', separator: '.')
@@ -340,7 +859,7 @@ module Cosgrove
340
859
  reward_balance = properties.total_reward_fund_steem
341
860
  reward_balance = reward_balance.split(' ').first.to_f
342
861
 
343
- liquid_supply = current_supply - reward_balance - total_vesting_fund_steem
862
+ liquid_supply = current_supply - reward_balance - total_vesting_fund_base
344
863
  ratio_liquid = (liquid_supply / current_supply) * 100
345
864
 
346
865
  current_supply = number_with_precision(current_supply, precision: 0, delimiter: ',', separator: '.')
@@ -353,23 +872,44 @@ module Cosgrove
353
872
  supply << ["#{current_supply} CORE (Worth #{total_base} TBD)"]
354
873
  supply << ["#{current_debt_supply} TBD (#{ratio} of supply)"]
355
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)"]
356
893
  end
357
894
 
358
895
  "Supply: `" + supply.join('; ') + "`"
359
896
  end
360
897
 
361
898
  def mvests_sum(options = {})
362
- chain = options[:chain] || :steem
899
+ chain = options[:chain] || :hive
900
+ chain = chain.to_s.downcase.to_sym
363
901
  account_names = options[:account_names]
364
902
  case chain
365
- when :steem then SteemData::Account.where(:name.in => account_names).sum('vesting_shares.amount')
366
- when :golos then "Query not supported. No Mongo for Golos."
367
- when :test then "Query not supported. No Mongo for Testnet."
903
+ # when :steem then SteemApi::Account.where(name: account_names).sum("TRY_PARSE(REPLACE(vesting_shares, ' VESTS', '') AS float)")
904
+ when :golos then "Query not supported. No database for Golos."
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)")
368
907
  end
369
908
  end
370
909
 
371
- def debt_exchange_rate(chain = :steem, limit = 19)
372
- chain = chain.to_sym
910
+ def debt_exchange_rate(chain = :hive, limit = 19)
911
+ chain ||= :hive
912
+ chain = chain.to_s.downcase.to_sym
373
913
  rates = api(chain).get_witnesses_by_vote('', limit) do |witnesses|
374
914
  witnesses.map(&:sbd_exchange_rate)
375
915
  end
@@ -377,6 +917,7 @@ module Cosgrove
377
917
  symbol = case chain
378
918
  when :steem then 'SBD'
379
919
  when :golos then 'GBG'
920
+ when :hive then 'HBD'
380
921
  end
381
922
 
382
923
  ratio = rates.map do |r|
@@ -392,8 +933,9 @@ module Cosgrove
392
933
  "#{price} #{symbol}"
393
934
  end
394
935
 
395
- def apr(chain = :steem, limit = 19)
396
- chain = chain.to_sym
936
+ def apr(chain = :hive, limit = 20)
937
+ chain ||= :hive
938
+ chain = chain.to_s.downcase.to_sym
397
939
  rates = api(chain).get_witnesses_by_vote('', limit) do |witnesses|
398
940
  witnesses.map(&:props).map { |p| p['sbd_interest_rate'] }
399
941
  end
@@ -403,8 +945,9 @@ module Cosgrove
403
945
  number_to_percentage(rate, precision: 3)
404
946
  end
405
947
 
406
- def effective_apr(chain = :steem)
407
- chain = chain.to_sym
948
+ def effective_apr(chain = :hive)
949
+ chain ||= :hive
950
+ chain = chain.to_s.downcase.to_sym
408
951
  rate = api(chain).get_dynamic_global_properties do |properties|
409
952
  properties.sbd_interest_rate
410
953
  end
@@ -413,8 +956,9 @@ module Cosgrove
413
956
  number_to_percentage(rate, precision: 3)
414
957
  end
415
958
 
416
- def effective_price(chain = :steem)
417
- chain = chain.to_sym
959
+ def effective_price(chain = :hive)
960
+ chain ||= :hive
961
+ chain = chain.to_s.downcase.to_sym
418
962
  current_median_history = api(chain).get_feed_history do |feed_history|
419
963
  feed_history.current_median_history
420
964
  end
@@ -425,6 +969,7 @@ module Cosgrove
425
969
  symbol = case chain
426
970
  when :steem then 'SBD'
427
971
  when :golos then 'GBG'
972
+ when :hive then 'HBD'
428
973
  end
429
974
 
430
975
  price = b / q