Class: Bitshares::Market

Inherits:
Object
  • Object
show all
Defined in:
lib/bitshares/market.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#baseObject (readonly)

Returns the value of attribute base.



7
8
9
# File 'lib/bitshares/market.rb', line 7

def base
  @base
end

#quoteObject (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_collateralObject

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_bidObject



27
28
29
30
# File 'lib/bitshares/market.rb', line 27

def highest_bid
  return if bids.empty?
  price bids.first
end

#last_fillObject



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_askObject



22
23
24
25
# File 'lib/bitshares/market.rb', line 22

def lowest_ask
  return if asks.empty?
  price asks.first
end

#mid_priceObject



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