Class: CryptoTicker::BTCe
- Inherits:
-
Object
- Object
- CryptoTicker::BTCe
- Defined in:
- lib/crypto_ticker.rb
Overview
BTC-e tickers for various crypto-currencies and retrieval methods
Constant Summary collapse
- @@valid_pairs =
%w[ BTC/USD BTC/RUR BTC/EUR LTC/BTC LTC/USD LTC/RUR NMC/BTC USD/RUR EUR/USD NVC/BTC TRC/BTC PPC/BTC RUC/BTC ]
- @@ret_types =
{ 'date' => :integer, 'price' => :bigdecimal, 'amount' => :bigdecimal, 'tid' => :integer, 'item' => :string, 'trade_type' => :string, 'price_currency' => :string, 'high' => :bigdecimal, 'low' => :bigdecimal, 'sell' => :bigdecimal, 'buy' => :bigdecimal, 'last' => :bigdecimal, 'vol_cur' => :bigdecimal, 'vol' => :bigdecimal, 'avg' => :bigdecimal, 'server_time' => :integer, }
- @@ret_fcns =
{ :integer => 'to_i', :bigdecimal => 'to_d', :string => 'to_s', }
Class Method Summary collapse
- .depth(base, quote = '') ⇒ Object
- .info(json) ⇒ Object
-
.last(json) ⇒ Object
Accepts JSON retrieved from the appropriate BTC-e ticker URL, returns last trade amount (denominated in counter currency) as a float.
- .ticker(base, quote = '') ⇒ Object
- .trades(base, quote = '') ⇒ Object
Class Method Details
.depth(base, quote = '') ⇒ Object
138 139 140 141 142 143 |
# File 'lib/crypto_ticker.rb', line 138 def depth(base, quote='') pair = CryptoTicker::makepair(base, quote) if @@valid_pairs.include?( pair ) "https://btc-e.com/api/2/#{pair.to_sym}/depth" end end |
.info(json) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/crypto_ticker.rb', line 155 def info(json) hash = JSON.parse(json) info = {} # TODO: recursively process Arrays, Hashes, Strings, Fixnums... if hash.has_key?('ticker') hash['ticker'].keys.each do |key| val = hash['ticker'][key] info[key.to_sym] = val.send(@@ret_fcns[@@ret_types[key]]) end end info end |
.last(json) ⇒ Object
Accepts JSON retrieved from the appropriate BTC-e ticker URL, returns last trade amount (denominated in counter currency) as a float. eg: BTC/USD ticker will return amount in USD
NMC/BTC ticker will return amount in BTC
149 150 151 152 |
# File 'lib/crypto_ticker.rb', line 149 def last(json) hash = JSON.parse(json) hash['ticker']['last'].to_d end |
.ticker(base, quote = '') ⇒ Object
124 125 126 127 128 129 |
# File 'lib/crypto_ticker.rb', line 124 def ticker(base, quote='') pair = CryptoTicker::makepair(base, quote) if @@valid_pairs.include?( pair ) "https://btc-e.com/api/2/#{pair.to_sym}/ticker" end end |
.trades(base, quote = '') ⇒ Object
131 132 133 134 135 136 |
# File 'lib/crypto_ticker.rb', line 131 def trades(base, quote='') pair = CryptoTicker::makepair(base, quote) if @@valid_pairs.include?( pair ) "https://btc-e.com/api/2/#{pair.to_sym}/trades" end end |