Class: CryptoTicker::MtGox
- Inherits:
-
Object
- Object
- CryptoTicker::MtGox
- Defined in:
- lib/crypto_ticker.rb
Overview
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.
Constant Summary collapse
- @@valid_pairs =
%w[ BTC/USD LTC/USD NMC/USD ]
Class Method Summary collapse
- .depth(base, quote = '') ⇒ Object
- .info(json) ⇒ Object
-
.last(json) ⇒ Object
Accepts JSON retrieved from the MtGox ticker URL, returns last trade amount (denominated in counter currency) as a BigDecimal.
-
.ticker(base, quote = '') ⇒ Object
return a ticker URL for a given crypto FX pair.
- .trades(base, quote = '') ⇒ Object
Class Method Details
.depth(base, quote = '') ⇒ Object
53 54 55 56 57 58 59 |
# 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) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# 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) ⇒ Object
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
64 65 66 67 68 69 |
# 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 = '') ⇒ Object
return a ticker URL for a given crypto FX pair
37 38 39 40 41 42 43 |
# 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 = '') ⇒ Object
45 46 47 48 49 50 51 |
# 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 |