Class: WavesRubyClient::OrderBook

Inherits:
Object
  • Object
show all
Defined in:
lib/waves_ruby_client/order_book.rb

Overview

Orderbook for a pair of assets

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(asset1, asset2) ⇒ OrderBook

Returns a new instance of OrderBook.



12
13
14
15
16
# File 'lib/waves_ruby_client/order_book.rb', line 12

def initialize(asset1, asset2)
  self.asset1 = asset1
  self.asset2 = asset2
  self.bids = self.asks = []
end

Instance Attribute Details

#asksObject

Returns the value of attribute asks.



10
11
12
# File 'lib/waves_ruby_client/order_book.rb', line 10

def asks
  @asks
end

#asset1Object

Returns the value of attribute asset1.



10
11
12
# File 'lib/waves_ruby_client/order_book.rb', line 10

def asset1
  @asset1
end

#asset2Object

Returns the value of attribute asset2.



10
11
12
# File 'lib/waves_ruby_client/order_book.rb', line 10

def asset2
  @asset2
end

#bidsObject

Returns the value of attribute bids.



10
11
12
# File 'lib/waves_ruby_client/order_book.rb', line 10

def bids
  @bids
end

Class Method Details

.btc_wavesObject



6
7
8
# File 'lib/waves_ruby_client/order_book.rb', line 6

def self.btc_waves
  new(WavesRubyClient::Asset.waves, WavesRubyClient::Asset.btc)
end

Instance Method Details

#refreshObject



18
19
20
21
22
23
24
# File 'lib/waves_ruby_client/order_book.rb', line 18

def refresh
  order_book = WavesRubyClient::Api.instance.call_matcher(
    "/orderbook/#{asset1.url_id}/#{asset2.url_id}#getOrderBook"
  )
  self.asks = order_book['asks'].map { |order| scale(order) }
  self.bids = order_book['bids'].map { |order| scale(order) }
end