Class: BudaApi::Models::OrderBookEntry

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/buda_api/models.rb

Overview

Order book entry model

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#raw, #to_h, #to_json

Constructor Details

#initialize(data) ⇒ OrderBookEntry

Returns a new instance of OrderBookEntry.



101
102
103
104
105
106
107
108
109
110
# File 'lib/buda_api/models.rb', line 101

def initialize(data)
  super(data)
  if data.is_a?(Array) && data.length >= 2
    @price = data[0].to_f
    @amount = data[1].to_f
  else
    @price = data["price"]&.to_f || 0.0
    @amount = data["amount"]&.to_f || 0.0
  end
end

Instance Attribute Details

#amount ⇒ Object (readonly)

Returns the value of attribute amount.



112
113
114
# File 'lib/buda_api/models.rb', line 112

def amount
  @amount
end

#price ⇒ Object (readonly)

Returns the value of attribute price.



112
113
114
# File 'lib/buda_api/models.rb', line 112

def price
  @price
end

Instance Method Details

#total ⇒ Object



114
115
116
# File 'lib/buda_api/models.rb', line 114

def total
  @price * @amount
end