class CryptoTicker::Vircurex

Vircurex ticker API and retrieval method

Public Class Methods

getpair(json, base, quote) click to toggle source

Accepts JSON retrieved from the Vircurex ticker URL, as well as a currency pair (specified as 2 arguments, a base currency and a quote currency). Returns last trade amount in quote currency.

# File lib/crypto_ticker.rb, line 187
def getpair(json, base, quote)
  hash = JSON.parse(json)

  # upcase currency pair inputs
  base.upcase!
  quote.upcase!

  # default value (may change this to just throw an exception)
  last = 0.0

  # if currency pair exists, return value of last trade
  if hash.has_key?(base) && hash[base].has_key?( quote ) &&
     hash[base][quote].has_key?('last_trade')
      last = hash[base][quote]['last_trade'].to_d
  end

  last
end
pair_info(json, base, quote) click to toggle source

Accepts JSON retrieved from the Vircurex ticker URL, as well as a currency pair (specified as 2 arguments, a base currency and a quote currency). Returns last trade amount in quote currency.

# File lib/crypto_ticker.rb, line 209
def pair_info(json, base, quote)
  hash = JSON.parse(json)

  # upcase currency pair inputs
  base.upcase!
  quote.upcase!

  # default value (may change this to just throw an exception)
  info = {}

  # if currency pair exists, return value of last trade
  if hash.has_key?(base) && hash[base].has_key?( quote )
     info = hash[base][quote]
  end

  info
end
ticker(base='', quote='') click to toggle source

accept [base, quote] args for consistency with other classes, but ignore them

# File lib/crypto_ticker.rb, line 179
def ticker(base='', quote='')
  # this one gets everything...
  'https://vircurex.com/api/get_info_for_currency.json'
end