Class: Bitstamper::Models::Order

Inherits:
Base
  • Object
show all
Defined in:
lib/bitstamper/models/order.rb

Constant Summary collapse

BUY =
0
SELL =
1
MAPPING =
{
  "id"              =>   :string,
  "currency_pair"   =>   :string,
  "type"            =>   :integer,
  "price"           =>   :float,
  "amount"          =>   :float,
  "event"           =>   :string
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#attributes

Constructor Details

#initialize(hash) ⇒ Order



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bitstamper/models/order.rb', line 19

def initialize(hash)
  hash["type"]      =     hash["order_type"] if hash.fetch("type", nil).to_s.empty? && hash.has_key?("order_type")
  
  hash.each do |key, value|
    type            =     ::Bitstamper::Models::Order::MAPPING.fetch(key, nil)
    value           =     value && type ? ::Bitstamper::Utilities::convert_value(value, type) : value
    self.send("#{key}=", value) if self.respond_to?(key)
  end
  
  datetime          =     hash.fetch("datetime", nil)&.to_s
  
  if !datetime.to_s.empty? && datetime.include?("-")
    self.datetime   =     ::Bitstamper::Utilities::convert_value(datetime, :datetime)
  elsif !datetime.to_s.empty? && ::Bitstamper::Utilities.numeric?(datetime)
    self.datetime   =     ::Bitstamper::Utilities::convert_value(datetime, :time)
  end
  
  self.order_type   =     case self.type
    when ::Bitstamper::Models::Order::BUY  then :buy
    when ::Bitstamper::Models::Order::SELL then :sell
  end
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



4
5
6
# File 'lib/bitstamper/models/order.rb', line 4

def amount
  @amount
end

#currency_pairObject

Returns the value of attribute currency_pair.



4
5
6
# File 'lib/bitstamper/models/order.rb', line 4

def currency_pair
  @currency_pair
end

#datetimeObject

Returns the value of attribute datetime.



4
5
6
# File 'lib/bitstamper/models/order.rb', line 4

def datetime
  @datetime
end

#errorObject

Returns the value of attribute error.



5
6
7
# File 'lib/bitstamper/models/order.rb', line 5

def error
  @error
end

#eventObject

Returns the value of attribute event.



5
6
7
# File 'lib/bitstamper/models/order.rb', line 5

def event
  @event
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/bitstamper/models/order.rb', line 4

def id
  @id
end

#messageObject

Returns the value of attribute message.



5
6
7
# File 'lib/bitstamper/models/order.rb', line 5

def message
  @message
end

#order_typeObject

Returns the value of attribute order_type.



4
5
6
# File 'lib/bitstamper/models/order.rb', line 4

def order_type
  @order_type
end

#priceObject

Returns the value of attribute price.



4
5
6
# File 'lib/bitstamper/models/order.rb', line 4

def price
  @price
end

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/bitstamper/models/order.rb', line 4

def type
  @type
end

Class Method Details

.parse(data) ⇒ Object



42
43
44
# File 'lib/bitstamper/models/order.rb', line 42

def self.parse(data)
  data&.collect { |item| ::Bitstamper::Models::Order.new(item) }
end