Class: Bitshares::Market
- Inherits:
-
Object
- Object
- Bitshares::Market
- Defined in:
- lib/bitshares/market.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#quote ⇒ Object
readonly
Returns the value of attribute quote.
Instance Method Summary collapse
-
#get_asset_collateral ⇒ Object
uses quote only, not base.
- #highest_bid ⇒ Object
-
#initialize(quote, base) ⇒ Market
constructor
A new instance of Market.
- #last_fill ⇒ Object
-
#list_shorts(limit = nil) ⇒ Object
uses quote only, not base.
- #lowest_ask ⇒ Object
- #method_missing(m, *args) ⇒ Object
- #mid_price ⇒ Object
Constructor Details
#initialize(quote, base) ⇒ Market
Returns a new instance of Market.
9 10 11 12 13 14 15 |
# File 'lib/bitshares/market.rb', line 9 def initialize(quote, base) [quote, base].each &:upcase! @quote_hash, @base_hash = asset(quote), asset(base) @quote, @base = @quote_hash['symbol'], @base_hash['symbol'] valid_market?(@quote_hash['id'], @base_hash['id']) @multiplier = multiplier end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object
45 46 47 |
# File 'lib/bitshares/market.rb', line 45 def method_missing(m, *args) CLIENT.request('blockchain_market_' + m.to_s, [quote, base] + args) end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
7 8 9 |
# File 'lib/bitshares/market.rb', line 7 def base @base end |
#quote ⇒ Object (readonly)
Returns the value of attribute quote.
7 8 9 |
# File 'lib/bitshares/market.rb', line 7 def quote @quote end |
Instance Method Details
#get_asset_collateral ⇒ Object
uses quote only, not base
41 42 43 |
# File 'lib/bitshares/market.rb', line 41 def get_asset_collateral # uses quote only, not base CLIENT.request('blockchain_market_get_asset_collateral', [quote]) end |
#highest_bid ⇒ Object
27 28 29 30 |
# File 'lib/bitshares/market.rb', line 27 def highest_bid return if bids.empty? price bids.first end |
#last_fill ⇒ Object
17 18 19 20 |
# File 'lib/bitshares/market.rb', line 17 def last_fill return -1 if order_hist.empty? order_hist.first['bid_index']['order_price']['ratio'].to_f * multiplier end |
#list_shorts(limit = nil) ⇒ Object
uses quote only, not base
37 38 39 |
# File 'lib/bitshares/market.rb', line 37 def list_shorts(limit = nil) # uses quote only, not base CLIENT.request('blockchain_market_list_shorts', [quote] + [limit]) end |
#lowest_ask ⇒ Object
22 23 24 25 |
# File 'lib/bitshares/market.rb', line 22 def lowest_ask return if asks.empty? price asks.first end |
#mid_price ⇒ Object
32 33 34 35 |
# File 'lib/bitshares/market.rb', line 32 def mid_price return nil if highest_bid.nil? || lowest_ask.nil? (highest_bid + lowest_ask) / 2 end |