lib/utils.rb in SimBot-0.1.7 vs lib/utils.rb in SimBot-0.1.8

- old
+ new

@@ -1,28 +1,109 @@ class Utils - def self.get_bchxrp_price - # fetch bch/xrp price from coin market cap - factor = rand(1...1.01) + # accept market paramter and return the coinmarket cap quote for said market + # @param [String] market + # @return [FalseClass and Float] + def self.quote(market) + case market + when 'bchxrp' + bchxrp_price + when 'bchbtc' + bchbtc_price + when 'btcxrp' + btcxrp_price + when 'eoseth' + eoseth_price + when 'btcltc' + btcltc_price + when 'ltcbtc' + ltcbtc_price + when 'bchxrp' + bchxrp_price + when 'ltcbch' + ltcbch_price + when 'ltcxrp' + ltcxrp_price + else + false + end + end + + # fetch ltc/xrp price from coin market cap + # @return [float] rate + def self.ltcxrp_price + response = RestClient.get('https://api.coinmarketcap.com/v2/ticker/2/?convert=XRP') + hash = JSON.parse(response.body) + hash['data']['quotes']['XRP']['price'].to_f.round(4) + end + + # fetch ltc/bch price from coin market cap + # @return [float] rate + def self.ltcbch_price + response = RestClient.get('https://api.coinmarketcap.com/v2/ticker/2/?convert=BCH') + hash = JSON.parse(response.body) + hash['data']['quotes']['BCH']['price'].to_f.round(4) + end + + # fetch bch/xrp price from coin market cap + # @return [float] rate + def self.bchxrp_price response = RestClient.get('https://api.coinmarketcap.com/v2/ticker/1831/?convert=XRP') - hash = JSON.parse (response.body) - return hash['data']['quotes']['XRP']['price'].to_f.round(4) * factor + hash = JSON.parse(response.body) + hash['data']['quotes']['XRP']['price'].to_f.round(4) end - def self.get_bchbtc_price - # fetch bch/xrp price from coin market cap - factor = rand(1...1.01) + + # fetch ltc/btc price from coin market cap + # @return [float] rate + def self.ltcbtc_price + response = RestClient.get('https://api.coinmarketcap.com/v2/ticker/2/?convert=BTC') + hash = JSON.parse(response.body) + hash['data']['quotes']['BTC']['price'].to_f.round(4) + end + + # fetch btc/ltc price from coin market cap + # @return [float] rate + def self.btcltc_price + response = RestClient.get('https://api.coinmarketcap.com/v2/ticker/1/?convert=LTC') + hash = JSON.parse(response.body) + hash['data']['quotes']['LTC']['price'].to_f.round(4) + end + + # fetch bch/xrp price from coin market cap + # @return [float] rate + def self.bchxrp_price + response = RestClient.get('https://api.coinmarketcap.com/v2/ticker/1831/?convert=XRP') + hash = JSON.parse(response.body) + hash['data']['quotes']['XRP']['price'].to_f.round(4) + end + + # fetch bch/btc price from coin market cap + # @return [float] rate + def self.bchbtc_price response = RestClient.get('https://api.coinmarketcap.com/v2/ticker/1831/?convert=BTC') hash = JSON.parse (response.body) - return hash['data']['quotes']['BTC']['price'].to_f.round(4) * factor + hash['data']['quotes']['BTC']['price'].to_f.round(4) end - def self.get_eoseth_price - # fetch bch/xrp price from coin market cap + + # fetch btc/xrp price from coin market cap + # @return [float] rate + def self.btcxrp_price + response = RestClient.get('https://api.coinmarketcap.com/v2/ticker/1/?convert=XRP') + hash = JSON.parse (response.body) + hash['data']['quotes']['XRP']['price'].to_f.round(4) + end + + # fetch eos/eth price from coin market cap + # @return [float] rate + def self.eoseth_price response = RestClient.get('https://api.coinmarketcap.com/v2/ticker/1765/?convert=ETH') hash = JSON.parse (response.body) return hash['data']['quotes']['ETH']['price'].to_f.round(4) end # Try and read the existing pid from the pid file and signal the # process. Returns true for a non blocking status. + # @param [Integer] pid + # @return [FalseClass and TrueClass] def self.kill_process(pid) opid = File.read("#{pid}.pid").strip.to_i Process.kill "HUP", opid File.delete("#{pid}.pid") File.delete("#{pid}.outfile")