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