Class: CryptoTicker::Vircurex
- Inherits:
-
Object
- Object
- CryptoTicker::Vircurex
- Defined in:
- lib/crypto_ticker.rb
Overview
Vircurex ticker API and retrieval method
Class Method Summary collapse
-
.getpair(json, base, quote) ⇒ Object
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).
-
.pair_info(json, base, quote) ⇒ Object
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).
-
.ticker(base = '', quote = '') ⇒ Object
accept [base, quote] args for consistency with other classes, but ignore them.
Class Method Details
.getpair(json, base, quote) ⇒ Object
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.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# 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) ⇒ Object
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.
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# 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 = '') ⇒ Object
accept [base, quote] args for consistency with other classes, but ignore them
179 180 181 182 |
# 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 |