class CryptoTicker::MtGox
MtGox
BTC/USD ticker and retrieval method
note: The official MtGox
API documentation is very sparse, and some methods are published but undocumented. The ‘ticker’ method should work, others may lag or return large amounts of data.
Public Class Methods
depth(base, quote='')
click to toggle source
# File lib/crypto_ticker.rb, line 53 def depth(base, quote='') pair = CryptoTicker::makepair(base, quote) if @@valid_pairs.include?( pair ) "http://data.mtgox.com/api/2/" + pair.split('/').join('') + "/money/depth/fetch" end end
info(json)
click to toggle source
# File lib/crypto_ticker.rb, line 71 def info(json) hash = JSON.parse(json) info = {} if hash['result'] === 'success' hash['data'].each do |k,v| if v.class.to_s.eql?( 'Hash' ) info[k.to_sym] = v['value'].to_d end end end # return either nil or the hash w/data info.empty? ? nil : info end
last(json)
click to toggle source
Accepts JSON retrieved from the MtGox
ticker URL, returns last trade amount (denominated in counter currency) as a BigDecimal. eg: BTC/USD ticker will return amount in USD
# File lib/crypto_ticker.rb, line 64 def last(json) hash = JSON.parse(json) if hash['result'] === 'success' hash['data']['last']['value'].to_d end end
ticker(base, quote='')
click to toggle source
return a ticker URL for a given crypto FX pair
# File lib/crypto_ticker.rb, line 37 def ticker(base, quote='') pair = CryptoTicker::makepair(base, quote) if @@valid_pairs.include?( pair ) "http://data.mtgox.com/api/2/" + pair.split('/').join('') + "/money/ticker" end end
trades(base, quote='')
click to toggle source
# File lib/crypto_ticker.rb, line 45 def trades(base, quote='') pair = CryptoTicker::makepair(base, quote) if @@valid_pairs.include?( pair ) "http://data.mtgox.com/api/2/" + pair.split('/').join('') + "/money/trades/fetch" end end